mirror of
				https://gitlab.com/famedly/fluffychat.git
				synced 2025-11-03 22:07:23 +01:00 
			
		
		
		
	feat: Send reactions to multiple events
This commit is contained in:
		
							parent
							
								
									068e312726
								
							
						
					
					
						commit
						f4425771f8
					
				@ -631,14 +631,14 @@ class ChatController extends State<Chat> {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void sendEmojiAction(String emoji) async {
 | 
			
		||||
    await showFutureLoadingDialog(
 | 
			
		||||
      context: context,
 | 
			
		||||
      future: () => room.sendReaction(
 | 
			
		||||
        selectedEvents.single.eventId,
 | 
			
		||||
        emoji,
 | 
			
		||||
      ),
 | 
			
		||||
    );
 | 
			
		||||
    final events = List<Event>.from(selectedEvents);
 | 
			
		||||
    setState(() => selectedEvents.clear());
 | 
			
		||||
    for (final event in events) {
 | 
			
		||||
      await room.sendReaction(
 | 
			
		||||
        event.eventId,
 | 
			
		||||
        emoji,
 | 
			
		||||
      );
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void clearSelectedEvents() => setState(() {
 | 
			
		||||
 | 
			
		||||
@ -41,44 +41,53 @@ class MessageReactions extends StatelessWidget {
 | 
			
		||||
        reactionMap[key].reacted |= e.senderId == e.room.client.userID;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    final reactionList = reactionMap.values.toList();
 | 
			
		||||
    reactionList.sort((a, b) => b.count - a.count > 0 ? 1 : -1);
 | 
			
		||||
    return Wrap(
 | 
			
		||||
        spacing: 4.0,
 | 
			
		||||
        runSpacing: 4.0,
 | 
			
		||||
        children: reactionList
 | 
			
		||||
            .map(
 | 
			
		||||
              (r) => _Reaction(
 | 
			
		||||
                reactionKey: r.key,
 | 
			
		||||
                count: r.count,
 | 
			
		||||
                reacted: r.reacted,
 | 
			
		||||
                onTap: () {
 | 
			
		||||
                  if (r.reacted) {
 | 
			
		||||
                    final evt = allReactionEvents.firstWhere(
 | 
			
		||||
                        (e) =>
 | 
			
		||||
                            e.senderId == e.room.client.userID &&
 | 
			
		||||
                            e.content['m.relates_to']['key'] == r.key,
 | 
			
		||||
                        orElse: () => null);
 | 
			
		||||
                    if (evt != null) {
 | 
			
		||||
                      showFutureLoadingDialog(
 | 
			
		||||
                        context: context,
 | 
			
		||||
                        future: () => evt.redactEvent(),
 | 
			
		||||
                      );
 | 
			
		||||
                    }
 | 
			
		||||
                  } else {
 | 
			
		||||
    return Wrap(spacing: 4.0, runSpacing: 4.0, children: [
 | 
			
		||||
      if (allReactionEvents.any((e) => e.status.isSending))
 | 
			
		||||
        const SizedBox(
 | 
			
		||||
          width: 28,
 | 
			
		||||
          height: 28,
 | 
			
		||||
          child: Padding(
 | 
			
		||||
            padding: EdgeInsets.all(4.0),
 | 
			
		||||
            child: CircularProgressIndicator.adaptive(strokeWidth: 1),
 | 
			
		||||
          ),
 | 
			
		||||
        ),
 | 
			
		||||
      ...reactionList
 | 
			
		||||
          .map(
 | 
			
		||||
            (r) => _Reaction(
 | 
			
		||||
              reactionKey: r.key,
 | 
			
		||||
              count: r.count,
 | 
			
		||||
              reacted: r.reacted,
 | 
			
		||||
              onTap: () {
 | 
			
		||||
                if (r.reacted) {
 | 
			
		||||
                  final evt = allReactionEvents.firstWhere(
 | 
			
		||||
                      (e) =>
 | 
			
		||||
                          e.senderId == e.room.client.userID &&
 | 
			
		||||
                          e.content['m.relates_to']['key'] == r.key,
 | 
			
		||||
                      orElse: () => null);
 | 
			
		||||
                  if (evt != null) {
 | 
			
		||||
                    showFutureLoadingDialog(
 | 
			
		||||
                        context: context,
 | 
			
		||||
                        future: () =>
 | 
			
		||||
                            event.room.sendReaction(event.eventId, r.key));
 | 
			
		||||
                      context: context,
 | 
			
		||||
                      future: () => evt.redactEvent(),
 | 
			
		||||
                    );
 | 
			
		||||
                  }
 | 
			
		||||
                },
 | 
			
		||||
                onLongPress: () async => await _AdaptableReactorsDialog(
 | 
			
		||||
                  client: client,
 | 
			
		||||
                  reactionEntry: r,
 | 
			
		||||
                ).show(context),
 | 
			
		||||
              ),
 | 
			
		||||
            )
 | 
			
		||||
            .toList());
 | 
			
		||||
                } else {
 | 
			
		||||
                  showFutureLoadingDialog(
 | 
			
		||||
                      context: context,
 | 
			
		||||
                      future: () =>
 | 
			
		||||
                          event.room.sendReaction(event.eventId, r.key));
 | 
			
		||||
                }
 | 
			
		||||
              },
 | 
			
		||||
              onLongPress: () async => await _AdaptableReactorsDialog(
 | 
			
		||||
                client: client,
 | 
			
		||||
                reactionEntry: r,
 | 
			
		||||
              ).show(context),
 | 
			
		||||
            ),
 | 
			
		||||
          )
 | 
			
		||||
          .toList(),
 | 
			
		||||
    ]);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -12,20 +12,17 @@ class ReactionsPicker extends StatelessWidget {
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    if (controller.showEmojiPicker) return Container();
 | 
			
		||||
    final display = controller.editEvent == null &&
 | 
			
		||||
        controller.replyEvent == null &&
 | 
			
		||||
        controller.room.canSendDefaultMessages &&
 | 
			
		||||
        controller.selectedEvents.isNotEmpty;
 | 
			
		||||
    return AnimatedContainer(
 | 
			
		||||
      duration: const Duration(milliseconds: 300),
 | 
			
		||||
      height: (controller.editEvent == null &&
 | 
			
		||||
              controller.replyEvent == null &&
 | 
			
		||||
              controller.room.canSendDefaultMessages &&
 | 
			
		||||
              controller.selectedEvents.length == 1)
 | 
			
		||||
          ? 56
 | 
			
		||||
          : 0,
 | 
			
		||||
      height: (display) ? 56 : 0,
 | 
			
		||||
      child: Material(
 | 
			
		||||
        color: Theme.of(context).secondaryHeaderColor,
 | 
			
		||||
        child: Builder(builder: (context) {
 | 
			
		||||
          if (!(controller.editEvent == null &&
 | 
			
		||||
              controller.replyEvent == null &&
 | 
			
		||||
              controller.selectedEvents.length == 1)) {
 | 
			
		||||
          if (!display) {
 | 
			
		||||
            return Container();
 | 
			
		||||
          }
 | 
			
		||||
          final emojis = List<String>.from(AppEmojis.emojis);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user