add rooms to mention chips
Needs handling for event links, plus clickability
This commit is contained in:
parent
9c488e8981
commit
a9993013f5
8 changed files with 87 additions and 23 deletions
|
|
@ -1,8 +1,11 @@
|
|||
import "package:flutter/material.dart";
|
||||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||
import "package:nexus/controllers/room_summary.dart";
|
||||
import "package:nexus/controllers/user.dart";
|
||||
import "package:nexus/helpers/extensions/link_to_mention.dart";
|
||||
import "package:nexus/helpers/extensions/show_user_popover.dart";
|
||||
import "package:nexus/models/content/membership.dart";
|
||||
import "package:nexus/models/room_summary.dart";
|
||||
|
||||
class MentionChip extends ConsumerWidget {
|
||||
final String? roomId;
|
||||
|
|
@ -12,29 +15,48 @@ class MentionChip extends ConsumerWidget {
|
|||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final mention = content.mention;
|
||||
final membership = mention?.startsWith("@") == true
|
||||
? ref
|
||||
.watch(
|
||||
UserController.provider(.new(roomId: roomId, userId: mention!)),
|
||||
)
|
||||
.whenOrNull(data: (data) => data)
|
||||
: null;
|
||||
final data = switch (mention?.characters.firstOrNull) {
|
||||
"@" =>
|
||||
ref
|
||||
.watch(
|
||||
UserController.provider(.new(roomId: roomId, userId: mention!)),
|
||||
)
|
||||
.whenOrNull(data: (data) => data),
|
||||
|
||||
"#" || "!" =>
|
||||
ref
|
||||
.watch(
|
||||
RoomSummaryController.provider(.new(roomIdOrAlias: mention!)),
|
||||
)
|
||||
.whenOrNull(data: (data) => data),
|
||||
|
||||
_ => null,
|
||||
};
|
||||
|
||||
return mention == null
|
||||
? SizedBox.shrink()
|
||||
: InkWell(
|
||||
onTap: () {
|
||||
if (membership != null) {
|
||||
if (data case MembershipContent membership) {
|
||||
context.showUserPopover(membership, mention, roomId: roomId);
|
||||
} else if (data case RoomSummary summary) {
|
||||
// TODO: Handle summary
|
||||
}
|
||||
},
|
||||
child: IgnorePointer(
|
||||
child: Chip(
|
||||
label: Text(
|
||||
(membership?.displayName == null
|
||||
? null
|
||||
: "@${membership!.displayName}") ??
|
||||
mention,
|
||||
switch (data) {
|
||||
RoomSummary summary =>
|
||||
(summary.name == null ? null : "#${summary.name}") ??
|
||||
summary.canonicalAlias ??
|
||||
summary.roomId,
|
||||
MembershipContent membership =>
|
||||
membership.displayName == null
|
||||
? mention
|
||||
: "@${membership.displayName}",
|
||||
_ => mention,
|
||||
},
|
||||
style: .new(
|
||||
fontWeight: .bold,
|
||||
color: Theme.of(context).colorScheme.onPrimary,
|
||||
|
|
|
|||
|
|
@ -311,7 +311,7 @@ class RoomChat extends HookConsumerWidget {
|
|||
await Clipboard.setData(
|
||||
ClipboardData(
|
||||
text:
|
||||
"matrix:roomid/${room.metadata?.id.substring(1)}/e/${event.eventId}$vias)",
|
||||
"matrix:roomid/${room.metadata?.id.substring(1)}/e/${event.eventId}$vias",
|
||||
),
|
||||
);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -35,8 +35,7 @@ class RoomMenu extends ConsumerWidget {
|
|||
|
||||
await Clipboard.setData(
|
||||
.new(
|
||||
text:
|
||||
"matrix:roomid/${room!.metadata?.id.substring(1)}$vias)",
|
||||
text: "matrix:roomid/${room!.metadata?.id.substring(1)}$vias",
|
||||
),
|
||||
);
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue