Skip to content

Commit

Permalink
TW-1442: Implement Jump to Message on pinned view
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian KOUNE authored and hoangdat committed Feb 7, 2024
1 parent be0396c commit 453d0a5
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 25 deletions.
4 changes: 4 additions & 0 deletions assets/images/ic_goto.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions lib/pages/chat/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1342,8 +1342,8 @@ class ChatController extends State<Chat>
) {
final listAction = [
ChatContextMenuActions.select,
ChatContextMenuActions.copyMessage,
ChatContextMenuActions.pinChat,
ChatContextMenuActions.copyMessage,
ChatContextMenuActions.forward,
if (PlatformInfos.isWeb && event.hasAttachment)
ChatContextMenuActions.downloadFile,
Expand All @@ -1358,9 +1358,10 @@ class ChatController extends State<Chat>
unpin: isUnpinEvent(event),
isSelected: isSelected(event),
),
iconAction: action.getIcon(
iconAction: action.getIconData(
unpin: isUnpinEvent(event),
),
imagePath: action.getImagePath(),
onCallbackAction: () => _handleClickOnContextMenuItem(
action,
event,
Expand Down Expand Up @@ -1390,6 +1391,8 @@ class ChatController extends State<Chat>
case ChatContextMenuActions.downloadFile:
downloadFileAction(context, event);
break;
default:
break;
}
}

Expand Down
19 changes: 17 additions & 2 deletions lib/pages/chat/chat_context_menu_actions.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:fluffychat/resource/image_paths.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';

Expand All @@ -6,7 +7,8 @@ enum ChatContextMenuActions {
copyMessage,
pinChat,
forward,
downloadFile;
downloadFile,
jumpToMessage;

String getTitle(
BuildContext context, {
Expand All @@ -26,10 +28,12 @@ enum ChatContextMenuActions {
return L10n.of(context)!.forward;
case ChatContextMenuActions.downloadFile:
return L10n.of(context)!.download;
case ChatContextMenuActions.jumpToMessage:
return L10n.of(context)!.jumpToMessage;
}
}

IconData getIcon({
IconData? getIconData({
bool isSelected = false,
bool unpin = false,
}) {
Expand All @@ -44,6 +48,17 @@ enum ChatContextMenuActions {
return Icons.shortcut;
case ChatContextMenuActions.downloadFile:
return Icons.download;
default:
return null;
}
}

String? getImagePath() {
switch (this) {
case ChatContextMenuActions.jumpToMessage:
return ImagePaths.icGoTo;
default:
return null;
}
}
}
15 changes: 13 additions & 2 deletions lib/pages/chat/chat_pinned_events/pinned_messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,10 @@ class PinnedMessagesController extends State<PinnedMessages>
Event event,
) {
final listAction = [
ChatContextMenuActions.pinChat,
ChatContextMenuActions.select,
ChatContextMenuActions.jumpToMessage,
ChatContextMenuActions.copyMessage,
ChatContextMenuActions.pinChat,
ChatContextMenuActions.forward,
if (PlatformInfos.isWeb && event.hasAttachment)
ChatContextMenuActions.downloadFile,
Expand All @@ -262,7 +263,8 @@ class PinnedMessagesController extends State<PinnedMessages>
unpin: event.isPinned,
isSelected: isSelected(event),
),
iconAction: action.getIcon(unpin: event.isPinned),
iconAction: action.getIconData(unpin: event.isPinned),
imagePath: action.getImagePath(),
onCallbackAction: () => _handleClickOnContextMenuItem(
action,
event,
Expand Down Expand Up @@ -305,11 +307,20 @@ class PinnedMessagesController extends State<PinnedMessages>
case ChatContextMenuActions.downloadFile:
await event.saveFile(context);
break;
case ChatContextMenuActions.jumpToMessage:
jumpToMessage(context, event);
break;
default:
break;
}
}

void jumpToMessage(BuildContext context, Event event) {
context.go(
'/rooms/${event.roomId}?event=${event.eventId}',
);
}

void forwardEventAction(Event event) async {
Matrix.of(context).shareContent =
event.getDisplayEvent(widget.timeline!).content;
Expand Down
1 change: 1 addition & 0 deletions lib/resource/image_paths.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class ImagePaths {
static String get logoTwakeWelcome => _getImagePath('logo_twake_welcome.svg');
static String get icEmptySearch => _getImagePath('ic_empty_search.svg');
static String get icFileError => _getImagePath('ic_file_error.svg');
static String get icGoTo => _getImagePath('ic_goto.svg');

static String _getImagePath(String imageName) {
return AssetsPaths.images + imageName;
Expand Down
47 changes: 28 additions & 19 deletions lib/widgets/mixins/popup_menu_widget_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,30 +81,39 @@ mixin PopupMenuWidgetMixin {
TextStyle? styleName,
EdgeInsets? padding,
}) {
Widget buildIcon() {
// We try to get the SVG first and then the IconData
if (imagePath != null) {
return SvgPicture.asset(
imagePath,
width: iconSize ?? PopupMenuWidgetStyle.defaultItemIconSize,
height: iconSize ?? PopupMenuWidgetStyle.defaultItemIconSize,
fit: BoxFit.fill,
colorFilter: ColorFilter.mode(
colorIcon ?? PopupMenuWidgetStyle.defaultItemColorIcon(context)!,
BlendMode.srcIn,
),
);
}

if (iconAction != null) {
return Icon(
iconAction,
size: iconSize ?? PopupMenuWidgetStyle.defaultItemIconSize,
color:
colorIcon ?? PopupMenuWidgetStyle.defaultItemColorIcon(context),
);
}

return const SizedBox.shrink();
}

return Padding(
padding: padding ?? PopupMenuWidgetStyle.defaultItemPadding,
child: SizedBox(
child: Row(
children: [
if (iconAction != null)
Icon(
iconAction,
size: iconSize ?? PopupMenuWidgetStyle.defaultItemIconSize,
color: colorIcon ??
PopupMenuWidgetStyle.defaultItemColorIcon(context),
),
if (imagePath != null)
SvgPicture.asset(
imagePath,
width: iconSize ?? PopupMenuWidgetStyle.defaultItemIconSize,
height: iconSize ?? PopupMenuWidgetStyle.defaultItemIconSize,
fit: BoxFit.fill,
colorFilter: ColorFilter.mode(
colorIcon ??
PopupMenuWidgetStyle.defaultItemColorIcon(context)!,
BlendMode.srcIn,
),
),
buildIcon(),
const SizedBox(width: PopupMenuWidgetStyle.defaultItemElementsGap),
Expanded(
child: Text(
Expand Down

0 comments on commit 453d0a5

Please sign in to comment.