make NotificationsController work off of rowIds
This commit is contained in:
parent
281bab0202
commit
ead463262c
12 changed files with 116 additions and 71 deletions
|
|
@ -36,7 +36,7 @@ class const ChatPage({super.key}) extends HookConsumerWidget {
|
|||
key: ValueKey((roomId, initialHighlight)),
|
||||
roomId: roomId,
|
||||
isDesktop: isDesktop,
|
||||
initialHighlightedEvent: initialHighlight,
|
||||
initialHighlight: initialHighlight,
|
||||
showMembersByDefault: showMembersByDefault,
|
||||
);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import "package:nexus/widgets/renderers/event.dart";
|
|||
import "package:super_sliver_list/super_sliver_list.dart";
|
||||
|
||||
class const NotificationsPage({
|
||||
final String? highlightedEventId,
|
||||
final int? highlightedEvent,
|
||||
final bool defaultToAllNotifications = false,
|
||||
super.key,
|
||||
}) extends HookConsumerWidget {
|
||||
|
|
@ -34,7 +34,7 @@ class const NotificationsPage({
|
|||
};
|
||||
final unreadTypeIndex = useState(defaultToAllNotifications ? 1 : 0);
|
||||
|
||||
final highlightedId = useState(highlightedEventId);
|
||||
final highlightedId = useState(highlightedEvent);
|
||||
final listController = useRef(ListController());
|
||||
final scrollController = useScrollController();
|
||||
|
||||
|
|
@ -56,7 +56,7 @@ class const NotificationsPage({
|
|||
final notifications = await ref.watch(provider.future);
|
||||
|
||||
final index = notifications.indexWhere(
|
||||
(element) => element.eventId == highlightedId.value!,
|
||||
(tuple) => tuple.$1 == highlightedId.value!,
|
||||
);
|
||||
|
||||
if (index == -1) return;
|
||||
|
|
@ -120,23 +120,23 @@ class const NotificationsPage({
|
|||
),
|
||||
reverse: true,
|
||||
itemBuilder: (context, index) {
|
||||
final event = value[index];
|
||||
final (rowId, roomId) = value[index];
|
||||
final isHighlighted =
|
||||
event.eventId == highlightedId.value;
|
||||
rowId == highlightedId.value;
|
||||
|
||||
return Padding(
|
||||
padding: .only(top: 8),
|
||||
child: HighlightWrapper(
|
||||
InkWell(
|
||||
onTap: () async {
|
||||
await ref.focusRoom(event.roomId);
|
||||
await ref.focusRoom(roomId);
|
||||
ref
|
||||
.watch(
|
||||
ContextualEventController.provider(
|
||||
event.roomId,
|
||||
roomId,
|
||||
).notifier,
|
||||
)
|
||||
.set(event);
|
||||
.set(rowId);
|
||||
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).pop();
|
||||
|
|
@ -144,8 +144,9 @@ class const NotificationsPage({
|
|||
},
|
||||
child: IgnorePointer(
|
||||
child: EventRenderer(
|
||||
event.rowId,
|
||||
roomId: event.roomId,
|
||||
rowId,
|
||||
roomId: NotificationsController
|
||||
.virtualRoomId,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
|||
import "package:material_ui/material_ui.dart";
|
||||
import "package:hooks_riverpod/hooks_riverpod.dart";
|
||||
import "package:nexus/controllers/pinned_events.dart";
|
||||
import "package:nexus/helpers/hooks/chat_scroll.dart";
|
||||
import "package:nexus/models/event.dart";
|
||||
import "package:nexus/widgets/error_dialog.dart";
|
||||
import "package:nexus/widgets/loading.dart";
|
||||
|
|
@ -10,7 +11,7 @@ import "package:nexus/widgets/renderers/event.dart";
|
|||
final class const PinnedEventsDrawer(
|
||||
final String roomId, {
|
||||
required final IList<PopupMenuEntry> Function(Event event) getEventOptions,
|
||||
required final Future<void> Function(Event event) jumpToEvent,
|
||||
required final JumpToEvent jumpToEvent,
|
||||
super.key,
|
||||
}) extends HookConsumerWidget {
|
||||
@override
|
||||
|
|
@ -62,7 +63,7 @@ final class const PinnedEventsDrawer(
|
|||
borderRadius: .circular(12),
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
jumpToEvent(event);
|
||||
jumpToEvent(event.rowId);
|
||||
},
|
||||
child: Padding(
|
||||
padding: .symmetric(vertical: 4),
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import "package:hooks_riverpod/hooks_riverpod.dart";
|
|||
import "package:nexus/controllers/event.dart";
|
||||
import "package:nexus/controllers/rooms.dart";
|
||||
import "package:nexus/helpers/extensions/show_context_menu.dart";
|
||||
import "package:nexus/helpers/hooks/chat_scroll.dart";
|
||||
import "package:nexus/models/content/avatar.dart";
|
||||
import "package:nexus/models/content/canonical_alias.dart";
|
||||
import "package:nexus/models/content/content.dart";
|
||||
|
|
@ -35,7 +36,7 @@ class const EventRenderer(
|
|||
final int? previousEventRowId,
|
||||
final bool textOnly = false,
|
||||
final int? maxLines,
|
||||
final Future<void> Function(Event event)? jumpToEvent,
|
||||
final JumpToEvent? jumpToEvent,
|
||||
final IList<PopupMenuEntry> Function(Event event)? getEventOptions,
|
||||
super.key,
|
||||
}) extends HookConsumerWidget {
|
||||
|
|
@ -106,7 +107,8 @@ class const EventRenderer(
|
|||
.new(roomId: roomId, eventId: event.replyTo!),
|
||||
).future,
|
||||
);
|
||||
if (replyEvent != null) await jumpToEvent!(replyEvent);
|
||||
if (replyEvent != null)
|
||||
await jumpToEvent!(replyEvent.rowId);
|
||||
},
|
||||
isGrouped: isGrouped,
|
||||
maxLines: maxLines,
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import "package:super_sliver_list/super_sliver_list.dart";
|
|||
class const ChatTimeline({
|
||||
required final String roomId,
|
||||
required final ChatScroll scroll,
|
||||
required final Future<void> Function(Event event) jumpToEvent,
|
||||
required final JumpToEvent jumpToEvent,
|
||||
required final IList<PopupMenuEntry> Function(Event) getEventOptions,
|
||||
required final int? highlightedEvent,
|
||||
required final double composerHeight,
|
||||
|
|
|
|||
|
|
@ -24,14 +24,14 @@ final class const RoomChat({
|
|||
required final String? roomId,
|
||||
required final bool isDesktop,
|
||||
required final bool showMembersByDefault,
|
||||
final Event? initialHighlightedEvent,
|
||||
final int? initialHighlight,
|
||||
super.key,
|
||||
}) extends HookConsumerWidget {
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final relatedEvent = useState<Event?>(null);
|
||||
final relationType = useState(RelationType.reply);
|
||||
final contextualEvent = useState<Event?>(initialHighlightedEvent);
|
||||
final contextualEvent = useState<int?>(initialHighlight);
|
||||
final highlightedEvent = useState<int?>(null);
|
||||
|
||||
final composerSize = useState<double>(64);
|
||||
|
|
@ -63,12 +63,7 @@ final class const RoomChat({
|
|||
|
||||
final controllerProvider = RoomChatController.provider((
|
||||
roomId: roomId,
|
||||
contextualEvent: contextualEvent.value == null
|
||||
? null
|
||||
: (
|
||||
rowId: contextualEvent.value!.rowId,
|
||||
eventId: contextualEvent.value!.eventId,
|
||||
),
|
||||
contextualEvent: contextualEvent.value,
|
||||
));
|
||||
final notifier = ref.watch(controllerProvider.notifier);
|
||||
|
||||
|
|
@ -102,25 +97,25 @@ final class const RoomChat({
|
|||
},
|
||||
);
|
||||
|
||||
Future<void> jumpToEvent(Event event) async {
|
||||
highlightedEvent.value = event.rowId;
|
||||
Future<void> jumpToEvent(int rowId) async {
|
||||
highlightedEvent.value = rowId;
|
||||
|
||||
await scroll.jumpToEvent(event);
|
||||
await scroll.jumpToEvent(rowId);
|
||||
await Future.delayed(.new(milliseconds: 700), () {
|
||||
if (highlightedEvent.value == event.rowId) {
|
||||
if (highlightedEvent.value == rowId) {
|
||||
highlightedEvent.value = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
useEffect(() {
|
||||
if (initialHighlightedEvent == null) return null;
|
||||
if (initialHighlight == null) return null;
|
||||
|
||||
void check() {
|
||||
if (!context.mounted) return;
|
||||
|
||||
if (scroll.scrollController.hasClients) {
|
||||
jumpToEvent(initialHighlightedEvent!);
|
||||
jumpToEvent(initialHighlight!);
|
||||
} else {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) => check());
|
||||
}
|
||||
|
|
@ -129,7 +124,7 @@ final class const RoomChat({
|
|||
check();
|
||||
|
||||
return null;
|
||||
}, [initialHighlightedEvent]);
|
||||
}, [initialHighlight]);
|
||||
|
||||
IList<PopupMenuEntry> getEventOptions(Event event) =>
|
||||
event.buildEventOptions(
|
||||
|
|
|
|||
Loading…
Reference in a new issue