diff --git a/lib/components/list_items/chat_list_item.dart b/lib/components/list_items/chat_list_item.dart index 1965d99..9f28c5e 100644 --- a/lib/components/list_items/chat_list_item.dart +++ b/lib/components/list_items/chat_list_item.dart @@ -6,6 +6,7 @@ import 'package:fluffychat/utils/room_name_calculator.dart'; import 'package:fluffychat/views/chat.dart'; import 'package:flutter/material.dart'; import 'package:toast/toast.dart'; +import 'package:pedantic/pedantic.dart'; import '../avatar.dart'; import '../matrix.dart'; @@ -67,6 +68,10 @@ class ChatListItem extends StatelessWidget { } if (room.membership == Membership.join) { + if (Matrix.of(context).shareContent != null) { + unawaited(room.sendEvent(Matrix.of(context).shareContent)); + Matrix.of(context).shareContent = null; + } await Navigator.pushAndRemoveUntil( context, AppRoute.defaultRoute(context, Chat(room.id)), diff --git a/lib/components/list_items/message.dart b/lib/components/list_items/message.dart index 9ff10bd..b079ddf 100644 --- a/lib/components/list_items/message.dart +++ b/lib/components/list_items/message.dart @@ -72,6 +72,15 @@ class Message extends StatelessWidget { ); } + if (!event.redacted) { + popupMenuList.add( + const PopupMenuItem( + value: "forward", + child: Text('Forward'), + ), + ); + } + if (ownMessage && event.status == -1) { popupMenuList.add( const PopupMenuItem( @@ -108,6 +117,10 @@ class Message extends StatelessWidget { case "copy": await Clipboard.setData(ClipboardData(text: event.body)); break; + case "forward": + Matrix.of(context).shareContent = event.content; + Navigator.of(context).popUntil((r) => r.isFirst); + break; } }, itemBuilder: (BuildContext context) => popupMenuList, diff --git a/lib/components/matrix.dart b/lib/components/matrix.dart index 6908775..af8200a 100644 --- a/lib/components/matrix.dart +++ b/lib/components/matrix.dart @@ -42,6 +42,7 @@ class MatrixState extends State { FirebaseMessaging _firebaseMessaging = FirebaseMessaging(); FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); + Map shareContent; String activeRoomId; diff --git a/lib/views/chat_list.dart b/lib/views/chat_list.dart index 0645e68..26f85ef 100644 --- a/lib/views/chat_list.dart +++ b/lib/views/chat_list.dart @@ -12,6 +12,8 @@ import 'package:fluffychat/views/settings.dart'; import 'package:flutter/material.dart'; import 'package:flutter_speed_dial/flutter_speed_dial.dart'; +enum SelectMode { normal, multi_select, share } + class ChatListView extends StatelessWidget { @override Widget build(BuildContext context) { @@ -39,6 +41,7 @@ class _ChatListState extends State { bool searchMode = false; StreamSubscription sub; final TextEditingController searchController = TextEditingController(); + SelectMode selectMode = SelectMode.normal; Future waitForFirstSync(BuildContext context) async { Client client = Matrix.of(context).client; @@ -68,6 +71,11 @@ class _ChatListState extends State { @override Widget build(BuildContext context) { + if (Matrix.of(context).shareContent != null) { + selectMode = SelectMode.share; + } else if (selectMode == SelectMode.share) { + setState(() => selectMode = SelectMode.normal); + } return Scaffold( appBar: AppBar( title: searchMode @@ -81,7 +89,7 @@ class _ChatListState extends State { ), ) : Text( - "FluffyChat", + selectMode == SelectMode.share ? "Share" : "FluffyChat", ), leading: searchMode ? IconButton( @@ -97,41 +105,50 @@ class _ChatListState extends State { icon: Icon(Icons.search), onPressed: () => setState(() => searchMode = true), ), - PopupMenuButton( - onSelected: (String choice) { - switch (choice) { - case "settings": - Navigator.of(context).pushAndRemoveUntil( - AppRoute.defaultRoute( - context, - SettingsView(), - ), - (r) => r.isFirst, - ); - break; - case "archive": - Navigator.of(context).pushAndRemoveUntil( - AppRoute.defaultRoute( - context, - Archive(), - ), - (r) => r.isFirst, - ); - break; - } - }, - itemBuilder: (BuildContext context) => - >[ - const PopupMenuItem( - value: "archive", - child: Text('Archive'), - ), - const PopupMenuItem( - value: "settings", - child: Text('Settings'), - ), - ], - ), + if (selectMode == SelectMode.share) + IconButton( + icon: Icon(Icons.close), + onPressed: () { + Matrix.of(context).shareContent = null; + setState(() => selectMode = SelectMode.normal); + }, + ), + if (selectMode == SelectMode.normal) + PopupMenuButton( + onSelected: (String choice) { + switch (choice) { + case "settings": + Navigator.of(context).pushAndRemoveUntil( + AppRoute.defaultRoute( + context, + SettingsView(), + ), + (r) => r.isFirst, + ); + break; + case "archive": + Navigator.of(context).pushAndRemoveUntil( + AppRoute.defaultRoute( + context, + Archive(), + ), + (r) => r.isFirst, + ); + break; + } + }, + itemBuilder: (BuildContext context) => + >[ + const PopupMenuItem( + value: "archive", + child: Text('Archive'), + ), + const PopupMenuItem( + value: "settings", + child: Text('Settings'), + ), + ], + ), ], ), floatingActionButton: SpeedDial(