Skip to content

Commit

Permalink
TW-727: close selection mode after action in messages list
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian KOUNE authored and hoangdat committed Oct 11, 2023
1 parent 81817d6 commit ca27d50
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
12 changes: 8 additions & 4 deletions lib/pages/chat/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,7 @@ class ChatController extends State<Chat>
}
}

void pinEvent() {
void pinEventAction() {
final room = this.room;
if (room == null) return;
final pinnedEventIds = room.pinnedEventIds;
Expand All @@ -1233,7 +1233,6 @@ class ChatController extends State<Chat>
} else {
pinnedEventIds.addAll(selectedEventIds);
}
clearSelectedEvents();
showFutureLoadingDialog(
context: context,
future: () => room.setPinnedEvents(pinnedEventIds),
Expand Down Expand Up @@ -1286,7 +1285,7 @@ class ChatController extends State<Chat>
bool get isArchived =>
{Membership.leave, Membership.ban}.contains(room?.membership);

void showEventInfo([Event? event]) =>
void showEventInfoAction([Event? event]) =>
(event ?? selectedEvents.single).showInfoDialog(context);

void onPhoneButtonTap() async {
Expand Down Expand Up @@ -1472,7 +1471,7 @@ class ChatController extends State<Chat>
break;
case ChatContextMenuActions.pinMessage:
onSelectMessage(event);
pinEvent();
pinEventAction();
break;
case ChatContextMenuActions.forward:
onSelectMessage(event);
Expand Down Expand Up @@ -1544,6 +1543,11 @@ class ChatController extends State<Chat>
}
}

void actionWithClearSelections(Function action) {
action();
clearSelectedEvents();
}

@override
Widget build(BuildContext context) {
return ChatView(this, key: widget.key);
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/chat/chat_event_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class ChatEventList extends StatelessWidget {
event,
onSwipe: (direction) =>
controller.replyAction(replyTo: event),
onInfoTab: controller.showEventInfo,
onInfoTab: controller.showEventInfoAction,
onAvatarTab: (Event event) => showAdaptiveBottomSheet(
context: context,
builder: (c) => UserBottomSheet(
Expand Down
18 changes: 12 additions & 6 deletions lib/pages/chat/chat_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,35 @@ class ChatView extends StatelessWidget {
TwakeIconButton(
icon: Icons.copy_outlined,
tooltip: L10n.of(context)!.copy,
onTap: controller.copyEventsAction,
onTap: () => controller
.actionWithClearSelections(controller.copyEventsAction),
),
if (controller.canRedactSelectedEvents)
TwakeIconButton(
icon: Icons.delete_outlined,
tooltip: L10n.of(context)!.redactMessage,
onTap: controller.redactEventsAction,
onTap: () => controller
.actionWithClearSelections(controller.redactEventsAction),
),
TwakeIconButton(
icon: Icons.push_pin_outlined,
onTap: controller.pinEvent,
tooltip: L10n.of(context)!.pinMessage,
onTap: () =>
controller.actionWithClearSelections(controller.pinEventAction),
),
if (controller.selectedEvents.length == 1)
PopupMenuButton<_EventContextAction>(
onSelected: (action) {
switch (action) {
case _EventContextAction.info:
controller.showEventInfo();
controller.clearSelectedEvents();
controller.actionWithClearSelections(
controller.showEventInfoAction,
);
break;
case _EventContextAction.report:
controller.reportEventAction();
controller.actionWithClearSelections(
controller.reportEventAction,
);
break;
}
},
Expand Down

0 comments on commit ca27d50

Please sign in to comment.