Support for pinned messages #49
2 changed files with 32 additions and 26 deletions
Better error reporting
commit
19c9479539
|
|
@ -11,7 +11,11 @@ abstract class SetStateRequest with _$SetStateRequest {
|
||||||
required String type,
|
required String type,
|
||||||
required String stateKey,
|
required String stateKey,
|
||||||
required Content content,
|
required Content content,
|
||||||
@JsonKey(name: "delay_ms") @MSDuration() @Default(null) Duration? delay,
|
|
||||||
|
@JsonKey(name: "delay_ms", includeIfNull: false)
|
||||||
|
@MSDuration()
|
||||||
|
@Default(null)
|
||||||
|
Duration? delay,
|
||||||
}) = _SetStateRequest;
|
}) = _SetStateRequest;
|
||||||
|
|
||||||
factory SetStateRequest.fromJson(Map<String, Object?> json) =>
|
factory SetStateRequest.fromJson(Map<String, Object?> json) =>
|
||||||
|
|
|
||||||
|
|
@ -175,36 +175,17 @@ class RoomChat extends HookConsumerWidget {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
PopupMenuItem buildPinOption(Event event) {
|
|
||||||
final isPinned = ref
|
|
||||||
.watch(PinnedEventsController.provider(roomId))
|
|
||||||
.maybeWhen(
|
|
||||||
data: (pinnedEvents) =>
|
|
||||||
pinnedEvents.any((ev) => ev.eventId == event.eventId),
|
|
||||||
orElse: () => false,
|
|
||||||
);
|
|
||||||
|
|
||||||
return PopupMenuItem(
|
|
||||||
onTap: () async {
|
|
||||||
final notifier = ref.read(
|
|
||||||
PinnedEventsController.provider(roomId).notifier,
|
|
||||||
);
|
|
||||||
if (isPinned) {
|
|
||||||
await notifier.removePin(event);
|
|
||||||
} else {
|
|
||||||
await notifier.addPin(event);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child: ListTile(
|
|
||||||
leading: Icon(isPinned ? Icons.push_pin_outlined : Icons.push_pin),
|
|
||||||
title: Text(isPinned ? "Unpin Event" : "Pin Event"),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
IList<PopupMenuEntry> getEventOptions(Event event) {
|
IList<PopupMenuEntry> getEventOptions(Event event) {
|
||||||
final danger = theme.colorScheme.error;
|
final danger = theme.colorScheme.error;
|
||||||
final isSentByMe = event.sender == userId;
|
final isSentByMe = event.sender == userId;
|
||||||
|
|
||||||
|
final isPinned = ref
|
||||||
|
.watch(PinnedEventsController.provider(roomId))
|
||||||
|
.whenOrNull(
|
||||||
|
data: (pinnedEvents) =>
|
||||||
|
pinnedEvents.any((ev) => ev.eventId == event.eventId),
|
||||||
|
);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
if (ref.watch(
|
if (ref.watch(
|
||||||
PowerLevelController.provider(
|
PowerLevelController.provider(
|
||||||
|
|
@ -282,7 +263,28 @@ class RoomChat extends HookConsumerWidget {
|
||||||
PowerLevelConfig(eventType: .pinnedEvents, roomId: roomId),
|
PowerLevelConfig(eventType: .pinnedEvents, roomId: roomId),
|
||||||
),
|
),
|
||||||
))
|
))
|
||||||
buildPinOption(event),
|
PopupMenuItem(
|
||||||
|
onTap: isPinned == null
|
||||||
|
? null
|
||||||
|
: () async {
|
||||||
|
try {
|
||||||
|
final notifier = ref.read(
|
||||||
|
PinnedEventsController.provider(roomId).notifier,
|
||||||
|
);
|
||||||
|
if (isPinned) {
|
||||||
|
await notifier.removePin(event);
|
||||||
|
} else {
|
||||||
|
await notifier.addPin(event);
|
||||||
|
}
|
||||||
|
} catch (error, stackTrace) {
|
||||||
|
showError(error, stackTrace);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: ListTile(
|
||||||
|
leading: Icon(Icons.push_pin),
|
||||||
|
title: Text(isPinned == true ? "Unpin Event" : "Pin Event"),
|
||||||
|
),
|
||||||
|
),
|
||||||
PopupMenuItem(
|
PopupMenuItem(
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
final room = ref.watch(
|
final room = ref.watch(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue