Merge branch 'add-copy-function' into 'master'

Add copy function

See merge request ChristianPauly/fluffychat-flutter!16
This commit is contained in:
Christian Pauly 2020-01-08 19:05:17 +00:00
commit c173091ca4
2 changed files with 28 additions and 2 deletions

View file

@ -4,6 +4,7 @@ import 'package:fluffychat/components/dialogs/redact_message_dialog.dart';
import 'package:fluffychat/components/message_content.dart'; import 'package:fluffychat/components/message_content.dart';
import 'package:fluffychat/utils/chat_time.dart'; import 'package:fluffychat/utils/chat_time.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../avatar.dart'; import '../avatar.dart';
import '../matrix.dart'; import '../matrix.dart';
@ -43,6 +44,25 @@ class Message extends StatelessWidget {
), ),
); );
} }
if (!event.redacted &&
[
MessageTypes.Text,
MessageTypes.Reply,
MessageTypes.Location,
MessageTypes.Notice,
MessageTypes.Emote,
MessageTypes.None,
].contains(event.messageType) &&
event.getBody().isNotEmpty) {
popupMenuList.add(
const PopupMenuItem<String>(
value: "copy",
child: Text('Copy'),
),
);
}
if (ownMessage && event.status == -1) { if (ownMessage && event.status == -1) {
popupMenuList.add( popupMenuList.add(
const PopupMenuItem<String>( const PopupMenuItem<String>(
@ -75,6 +95,9 @@ class Message extends StatelessWidget {
case "delete": case "delete":
await event.remove(); await event.remove();
break; break;
case "copy":
await Clipboard.setData(ClipboardData(text: event.getBody()));
break;
} }
}, },
itemBuilder: (BuildContext context) => popupMenuList, itemBuilder: (BuildContext context) => popupMenuList,

View file

@ -114,9 +114,12 @@ class MessageContent extends StatelessWidget {
? "You: " ? "You: "
: "${event.sender.calcDisplayname()}: " : "${event.sender.calcDisplayname()}: "
: ""; : "";
final String body = event.redacted
? "Redacted by ${event.redactedBecause.sender.calcDisplayname()}"
: senderPrefix + event.getBody();
if (textOnly) { if (textOnly) {
return Text( return Text(
senderPrefix + event.getBody(), body,
maxLines: maxLines, maxLines: maxLines,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
style: TextStyle( style: TextStyle(
@ -127,7 +130,7 @@ class MessageContent extends StatelessWidget {
); );
} }
return LinkText( return LinkText(
text: senderPrefix + event.getBody(), text: body,
textStyle: TextStyle( textStyle: TextStyle(
color: textColor, color: textColor,
decoration: event.redacted ? TextDecoration.lineThrough : null, decoration: event.redacted ? TextDecoration.lineThrough : null,