Add copy function

This commit is contained in:
Christian Pauly 2020-01-08 20:01:52 +01:00
parent 921d0984ee
commit 0fd90af759
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/utils/chat_time.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../avatar.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) {
popupMenuList.add(
const PopupMenuItem<String>(
@ -75,6 +95,9 @@ class Message extends StatelessWidget {
case "delete":
await event.remove();
break;
case "copy":
await Clipboard.setData(ClipboardData(text: event.getBody()));
break;
}
},
itemBuilder: (BuildContext context) => popupMenuList,

View File

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