Compare commits

..
2 changed files with 84 additions and 88 deletions

View file

@ -21,98 +21,93 @@ class ReactionRow extends ConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {
final clientState = ref.watch(ClientStateController.provider); final clientState = ref.watch(ClientStateController.provider);
return Padding( return switch (ref.watch(
padding: .only(top: 4), ReactionsController.provider(
child: switch (ref.watch( .new(roomId: event.roomId, eventRowId: event.rowId),
ReactionsController.provider( ),
.new(roomId: event.roomId, eventRowId: event.rowId), )) {
), AsyncData(value: final IMap<String, IList<String>>? reactors) ||
)) { AsyncLoading(value: final reactors) => Wrap(
AsyncData(value: final IMap<String, IList<String>>? reactors) || spacing: 4,
AsyncLoading(value: final reactors) => Wrap( runSpacing: 4,
spacing: 4, children: event.reactions
runSpacing: 4, .where((_, value) => value != 0)
children: event.reactions .mapTo(
.where((_, value) => value != 0) (reaction, count) => HookBuilder(
.mapTo( builder: (context) {
(reaction, count) => HookBuilder( final enabled = useState(true);
builder: (context) {
final enabled = useState(true);
final selected = final selected =
reactors?[reaction]?.contains(clientState!.userId) ?? reactors?[reaction]?.contains(clientState!.userId) ??
false; false;
return Tooltip( return Tooltip(
message: reactors?[reaction]?.join(", ") ?? "", message: reactors?[reaction]?.join(", ") ?? "",
child: ChoiceChip( child: ChoiceChip(
showCheckmark: false, showCheckmark: false,
selected: selected, selected: selected,
label: Row( label: Row(
mainAxisSize: .min, mainAxisSize: .min,
spacing: 8, spacing: 8,
children: [ children: [
Flexible( Flexible(
child: reaction.startsWith("mxc://") child: reaction.startsWith("mxc://")
? Image( ? Image(
height: 20, height: 20,
image: CachedNetworkImage( image: CachedNetworkImage(
headers: ref.headers, headers: ref.headers,
Uri.parse(reaction) Uri.parse(reaction)
.mxcToHttps( .mxcToHttps(
clientState!.homeserverUrl!, clientState!.homeserverUrl!,
) )
.toString(), .toString(),
ref.watch( ref.watch(CrossCacheController.provider),
CrossCacheController.provider, ),
), )
), : Text(reaction, overflow: .ellipsis),
) ),
: Text(reaction, overflow: .ellipsis), Text(count.toString(), overflow: .ellipsis),
), ],
Text(count.toString(), overflow: .ellipsis),
],
),
onSelected: enabled.value
? (value) async {
enabled.value = false;
try {
final controller = ref.watch(
RoomChatController.provider(
event.roomId,
).notifier,
);
if (selected) {
await controller
.removeReaction(
reaction,
event,
clientState!.userId!,
)
.onError(showError);
} else {
await controller
.sendReaction(reaction, event)
.onError(showError);
}
} finally {
enabled.value = true;
}
}
: null,
), ),
); onSelected: enabled.value
}, ? (value) async {
), enabled.value = false;
) try {
.toList(), final controller = ref.watch(
), RoomChatController.provider(
event.roomId,
).notifier,
);
AsyncError(:final error, :final stackTrace) => ErrorDialog( if (selected) {
error, await controller
stackTrace, .removeReaction(
), reaction,
}, event,
); clientState!.userId!,
)
.onError(showError);
} else {
await controller
.sendReaction(reaction, event)
.onError(showError);
}
} finally {
enabled.value = true;
}
}
: null,
),
);
},
),
)
.toList(),
),
AsyncError(:final error, :final stackTrace) => ErrorDialog(
error,
stackTrace,
),
};
} }
} }

View file

@ -271,6 +271,7 @@ class MessageRenderer extends ConsumerWidget {
case final UrlElement link?) case final UrlElement link?)
UrlPreview(link.url), UrlPreview(link.url),
SizedBox(height: 4),
ReactionRow(event), ReactionRow(event),
], ],
], ],