Add support for jumping to event links (#103)
Fixes #78. Reviewed-on: #103
This commit is contained in:
parent
597112f5d3
commit
1c4bf99be2
16 changed files with 169 additions and 113 deletions
|
|
@ -1,9 +1,10 @@
|
|||
import "package:material_ui/material_ui.dart";
|
||||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||
import "package:nexus/controllers/event.dart";
|
||||
import "package:nexus/controllers/room_summary.dart";
|
||||
import "package:nexus/controllers/user.dart";
|
||||
import "package:nexus/helpers/extensions/focus_room.dart";
|
||||
import "package:nexus/helpers/extensions/link_to_mention.dart";
|
||||
import "package:nexus/helpers/extensions/get_link_info.dart";
|
||||
import "package:nexus/helpers/extensions/show_user_popover.dart";
|
||||
import "package:nexus/models/content/membership.dart";
|
||||
import "package:nexus/models/room_summary.dart";
|
||||
|
|
@ -13,7 +14,8 @@ class const MentionChip(final String content, final String? roomId, {super.key})
|
|||
extends ConsumerWidget {
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final mention = content.mention;
|
||||
final linkInfo = content.linkInfo;
|
||||
final mention = linkInfo?.identifier;
|
||||
final data = switch (mention?.characters.firstOrNull) {
|
||||
"@" =>
|
||||
ref
|
||||
|
|
@ -40,7 +42,22 @@ class const MentionChip(final String content, final String? roomId, {super.key})
|
|||
if (data case MembershipContent membership) {
|
||||
context.showUserPopover(membership, mention, roomId: roomId);
|
||||
} else if (data case RoomSummary summary) {
|
||||
if (!await ref.focusRoom(summary.roomId) && context.mounted) {
|
||||
// TODO: This is an extra call that isn't truly needed, get rid of it
|
||||
final eventRowId = linkInfo?.eventId == null
|
||||
? null
|
||||
: await ref
|
||||
.read(
|
||||
EventController.provider(
|
||||
.new(
|
||||
roomId: summary.roomId,
|
||||
eventId: linkInfo!.eventId!,
|
||||
),
|
||||
).selectAsync((data) => data?.rowId),
|
||||
)
|
||||
.onError((_, _) => null);
|
||||
|
||||
if (!await ref.focusRoom(summary.roomId, eventRowId) &&
|
||||
context.mounted) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => Consumer(
|
||||
|
|
@ -53,7 +70,7 @@ class const MentionChip(final String content, final String? roomId, {super.key})
|
|||
)
|
||||
.whenOrNull(data: (data) => data) ??
|
||||
summary,
|
||||
via: content.via,
|
||||
via: linkInfo?.via,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
@ -63,9 +80,7 @@ class const MentionChip(final String content, final String? roomId, {super.key})
|
|||
child: Text(
|
||||
switch (data) {
|
||||
RoomSummary summary =>
|
||||
(summary.name == null ? null : "#${summary.name}") ??
|
||||
summary.canonicalAlias ??
|
||||
summary.roomId,
|
||||
"${(summary.name == null ? null : "#${summary.name}") ?? summary.canonicalAlias ?? summary.roomId}${linkInfo?.eventId == null ? "" : " > ${linkInfo?.eventId}"}",
|
||||
MembershipContent membership =>
|
||||
membership.displayName == null
|
||||
? mention
|
||||
|
|
|
|||
Loading…
Reference in a new issue