From 34a1aef71a7ebc379449f0b90c1e6bae4ffbf7d9 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Thu, 17 Feb 2022 14:02:17 +0100 Subject: [PATCH] chore: Follow up fix pinned event ids --- lib/pages/chat/chat.dart | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index fb3f306de..3ae88f642 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -886,18 +886,16 @@ class ChatController extends State { if (room == null) return; final pinnedEventIds = room.pinnedEventIds; final selectedEventIds = selectedEvents.map((e) => e.eventId).toSet(); - final pin = selectedEventIds.any((e) => !pinnedEventIds.contains(e)); + final unpin = selectedEventIds.length == 1 && + pinnedEventIds.contains(selectedEventIds.single); + if (unpin) { + pinnedEventIds.removeWhere(selectedEventIds.contains); + } else { + pinnedEventIds.addAll(selectedEventIds); + } showFutureLoadingDialog( context: context, - future: () => room.setPinnedEvents( - pin - ? { - ...pinnedEventIds, - ...selectedEvents.map((e) => e.eventId), - }.toList() - : pinnedEventIds - ..removeWhere(selectedEventIds.contains), - ), + future: () => room.setPinnedEvents(pinnedEventIds), ); }