parent
47645ea327
commit
7f7bdbf525
3 changed files with 1477 additions and 577 deletions
|
|
@ -26,6 +26,7 @@ extension BuildEventOptions on Event {
|
|||
required String roomId,
|
||||
required String userId,
|
||||
required void Function(int, RelationType) onRelation,
|
||||
void Function(String threadRoot)? onStartThread,
|
||||
}) {
|
||||
final theme = Theme.of(context);
|
||||
final danger = theme.colorScheme.error;
|
||||
|
|
@ -34,11 +35,15 @@ extension BuildEventOptions on Event {
|
|||
final notifier = RoomChatController.provider((
|
||||
roomId: roomId,
|
||||
contextualEvent: null,
|
||||
threadRoot: null,
|
||||
)).notifier;
|
||||
|
||||
final isPinned = ref
|
||||
.read(PinnedIdsController.provider(roomId))
|
||||
.contains(eventId);
|
||||
final canSend = ref.read(
|
||||
PowerLevelController.provider(.new(eventType: .message, roomId: roomId)),
|
||||
);
|
||||
|
||||
void showReasonSheet({
|
||||
required String title,
|
||||
|
|
@ -170,11 +175,7 @@ extension BuildEventOptions on Event {
|
|||
),
|
||||
),
|
||||
|
||||
if (ref.read(
|
||||
PowerLevelController.provider(
|
||||
.new(eventType: .message, roomId: roomId),
|
||||
),
|
||||
))
|
||||
if (canSend)
|
||||
PopupMenuItem(
|
||||
onTap: () => onRelation(rowId, .reply),
|
||||
child: const ListTile(
|
||||
|
|
@ -183,6 +184,18 @@ extension BuildEventOptions on Event {
|
|||
),
|
||||
),
|
||||
|
||||
if (onStartThread != null &&
|
||||
threadCount == 0 &&
|
||||
canSend &&
|
||||
relatesTo == null)
|
||||
PopupMenuItem(
|
||||
onTap: () => onStartThread(eventId),
|
||||
child: const ListTile(
|
||||
leading: Icon(Icons.forum),
|
||||
title: Text("Start Thread"),
|
||||
),
|
||||
),
|
||||
|
||||
if (sender == userId &&
|
||||
switch (content) {
|
||||
LocationMessageContent() ||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ extension OpenLinkInfo on WidgetRef {
|
|||
: await read(
|
||||
EventController.provider(
|
||||
.new(roomId: summary.roomId, eventId: linkInfo.eventId!),
|
||||
).selectAsync((data) => data?.rowId),
|
||||
).future,
|
||||
).onError((_, _) => null);
|
||||
|
||||
if (await focusRoom(summary.roomId, eventRowId) || !context.mounted) return;
|
||||
|
|
|
|||
50
lib/helpers/extensions/thread_events.dart
Normal file
50
lib/helpers/extensions/thread_events.dart
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import "package:collection/collection.dart";
|
||||
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||
import "package:nexus/helpers/extensions/event_id_is_fake.dart";
|
||||
import "package:nexus/models/event.dart";
|
||||
import "package:nexus/models/room.dart";
|
||||
|
||||
typedef ThreadInfo = ({int count, Event? latest});
|
||||
typedef Thread = ({Event root, ThreadInfo info});
|
||||
|
||||
extension ThreadEvents on Room {
|
||||
/// The threads in the loaded events, most recently active first.
|
||||
IList<Thread> get threads {
|
||||
DateTime lastActive(Thread thread) =>
|
||||
thread.info.latest?.timestamp ?? thread.root.timestamp;
|
||||
|
||||
return events.values
|
||||
.where((event) => event.threadCount > 0)
|
||||
.map((root) => (root: root, info: thread(root)))
|
||||
.sorted((a, b) => lastActive(b).compareTo(lastActive(a)))
|
||||
.toIList();
|
||||
}
|
||||
|
||||
/// The events in the thread from [threadRoot], oldest first, without the
|
||||
/// root itself.
|
||||
IList<Event> threadEvents(String threadRoot) =>
|
||||
(relations[threadRoot] ?? const .empty())
|
||||
.map((rowId) => events[rowId])
|
||||
.nonNulls
|
||||
.where(
|
||||
(event) =>
|
||||
event.threadRoot == threadRoot &&
|
||||
(!event.eventId.isFake || clientSticky.contains(event.rowId)),
|
||||
)
|
||||
.sorted((a, b) => a.timestamp.compareTo(b.timestamp))
|
||||
.toIList();
|
||||
|
||||
/// How many replies the thread from [root] has, and its latest event, from
|
||||
/// gomuks' aggregate on it
|
||||
ThreadInfo thread(Event root) =>
|
||||
(count: root.threadCount, latest: events[root.threadLatestRowId]);
|
||||
|
||||
/// The latest event in the thread from [threadRoot], if it's loaded.
|
||||
Event? latestThreadEvent(String threadRoot) => switch (eventIds[threadRoot]) {
|
||||
final rowId? => switch (events[rowId]) {
|
||||
final root? => thread(root).latest,
|
||||
null => null,
|
||||
},
|
||||
null => null,
|
||||
};
|
||||
}
|
||||
Loading…
Reference in a new issue