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
|
|
@ -2,7 +2,7 @@ import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
|||
import "package:material_ui/material_ui.dart";
|
||||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||
import "package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart";
|
||||
import "package:nexus/helpers/extensions/link_to_mention.dart";
|
||||
import "package:nexus/helpers/extensions/get_link_info.dart";
|
||||
import "package:nexus/helpers/launch_helper.dart";
|
||||
import "package:nexus/helpers/mxc_image.dart";
|
||||
import "package:nexus/widgets/expandable_image.dart";
|
||||
|
|
@ -70,7 +70,7 @@ class const Html(
|
|||
),
|
||||
|
||||
"a" =>
|
||||
element.attributes["href"]?.mention == null
|
||||
element.attributes["href"]?.linkInfo == null
|
||||
? null
|
||||
: InlineCustomWidget(
|
||||
child: MentionChip(element.attributes["href"]!, roomId),
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||
import "package:material_ui/material_ui.dart";
|
||||
import "package:flutter_hooks/flutter_hooks.dart";
|
||||
import "package:hooks_riverpod/hooks_riverpod.dart";
|
||||
import "package:nexus/controllers/room_summary.dart";
|
||||
import "package:nexus/helpers/extensions/link_to_mention.dart";
|
||||
import "package:nexus/helpers/extensions/get_link_info.dart";
|
||||
import "package:nexus/widgets/room_summary_dialog.dart";
|
||||
|
||||
class const JoinDialog(final WidgetRef ref, {super.key}) extends HookWidget {
|
||||
|
|
@ -13,20 +14,26 @@ class const JoinDialog(final WidgetRef ref, {super.key}) extends HookWidget {
|
|||
Future<void> onJoin() async {
|
||||
Navigator.of(context).pop();
|
||||
|
||||
final roomIdOrAlias = roomAlias.text.mention ?? roomAlias.text;
|
||||
final via = roomAlias.text.via;
|
||||
final linkInfo = roomAlias.text.linkInfo;
|
||||
final roomIdOrAlias = linkInfo?.identifier ?? roomAlias.text;
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => switch (ref.watch(
|
||||
RoomSummaryController.provider(
|
||||
.new(roomIdOrAlias: roomIdOrAlias, via: via),
|
||||
.new(
|
||||
roomIdOrAlias: roomIdOrAlias,
|
||||
via: linkInfo?.via ?? const IList.empty(),
|
||||
),
|
||||
),
|
||||
)) {
|
||||
AsyncData(:final value) => RoomSummaryDialog(value, via: via),
|
||||
AsyncData(:final value) => RoomSummaryDialog(
|
||||
value,
|
||||
via: linkInfo?.via,
|
||||
),
|
||||
AsyncError _ || AsyncLoading _ => RoomSummaryDialog(
|
||||
.new(roomId: roomAlias.text),
|
||||
via: via,
|
||||
via: linkInfo?.via,
|
||||
),
|
||||
},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import "package:m3e_buttons/m3e_buttons.dart";
|
|||
import "package:material_ui/material_ui.dart";
|
||||
import "package:flutter_hooks/flutter_hooks.dart";
|
||||
import "package:hooks_riverpod/hooks_riverpod.dart";
|
||||
import "package:nexus/controllers/contextual_event.dart";
|
||||
import "package:nexus/controllers/notifications.dart";
|
||||
import "package:nexus/helpers/extensions/focus_room.dart";
|
||||
import "package:nexus/models/event.dart";
|
||||
|
|
@ -129,18 +128,8 @@ class const NotificationsPage({
|
|||
child: HighlightWrapper(
|
||||
InkWell(
|
||||
onTap: () async {
|
||||
await ref.focusRoom(roomId);
|
||||
ref
|
||||
.watch(
|
||||
ContextualEventController.provider(
|
||||
roomId,
|
||||
).notifier,
|
||||
)
|
||||
.set(rowId);
|
||||
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
Navigator.of(context).pop();
|
||||
await ref.focusRoom(roomId, rowId);
|
||||
},
|
||||
child: IgnorePointer(
|
||||
child: EventRenderer(
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ import "package:nexus/helpers/hooks/chat_scroll.dart";
|
|||
import "package:nexus/models/event.dart";
|
||||
import "package:nexus/models/relation_type.dart";
|
||||
import "package:nexus/widgets/composer/composer.dart";
|
||||
import "package:nexus/widgets/error_dialog.dart";
|
||||
import "package:nexus/widgets/loading.dart";
|
||||
import "package:nexus/widgets/pinned_events_drawer.dart";
|
||||
import "package:nexus/widgets/member_list.dart";
|
||||
import "package:nexus/widgets/room_appbar.dart";
|
||||
|
|
@ -168,14 +170,20 @@ final class const RoomChat({
|
|||
Positioned.fill(
|
||||
child: Padding(
|
||||
padding: .symmetric(horizontal: 4),
|
||||
child: ChatTimeline(
|
||||
scroll: scroll,
|
||||
roomId: roomId,
|
||||
jumpToEvent: jumpToEvent,
|
||||
getEventOptions: getEventOptions,
|
||||
highlightedEvent: highlightedEvent.value,
|
||||
composerHeight: composerSize.value,
|
||||
),
|
||||
child: switch (controllerData) {
|
||||
AsyncLoading(value: _?) ||
|
||||
AsyncData(value: _) => ChatTimeline(
|
||||
scroll: scroll,
|
||||
roomId: roomId,
|
||||
jumpToEvent: jumpToEvent,
|
||||
getEventOptions: getEventOptions,
|
||||
highlightedEvent: highlightedEvent.value,
|
||||
composerHeight: composerSize.value,
|
||||
),
|
||||
AsyncLoading _ => Loading(),
|
||||
AsyncError(:final error, :final stackTrace) =>
|
||||
ErrorDialog(error, stackTrace),
|
||||
},
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
|
|
|
|||
Loading…
Reference in a new issue