Skip to content

Commit

Permalink
Select text option for chat messages (#1726)
Browse files Browse the repository at this point in the history
  • Loading branch information
beastoin authored Jan 25, 2025
2 parents cd5164a + 83f2aad commit ab3eaa9
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 12 deletions.
36 changes: 24 additions & 12 deletions app/lib/pages/chat/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:friend_private/backend/preferences.dart';
import 'package:friend_private/backend/schema/app.dart';
import 'package:friend_private/backend/schema/conversation.dart';
import 'package:friend_private/backend/schema/message.dart';
import 'package:friend_private/pages/chat/select_text_screen.dart';
import 'package:friend_private/pages/chat/widgets/ai_message.dart';
import 'package:friend_private/pages/chat/widgets/animated_mini_banner.dart';
import 'package:friend_private/pages/chat/widgets/user_message.dart';
Expand All @@ -17,6 +18,7 @@ import 'package:friend_private/providers/home_provider.dart';
import 'package:friend_private/providers/conversation_provider.dart';
import 'package:friend_private/providers/message_provider.dart';
import 'package:friend_private/utils/analytics/mixpanel.dart';
import 'package:friend_private/utils/other/temp.dart';
import 'package:friend_private/widgets/dialog.dart';
import 'package:friend_private/widgets/extensions/string.dart';
import 'package:gradient_borders/gradient_borders.dart';
Expand Down Expand Up @@ -241,20 +243,29 @@ class ChatPageState extends State<ChatPage> with AutomaticKeepAliveClientMixin {
builder: (context) => MessageActionMenu(
message: message.text.decodeString,
onCopy: () async {
MixpanelManager()
.track('Chat Message Copied', properties: {'message': message.text});
await Clipboard.setData(ClipboardData(text: message.text.decodeString));
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text(
'Message copied to clipboard.',
style: TextStyle(
color: Color.fromARGB(255, 255, 255, 255),
fontSize: 12.0,
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text(
'Message copied to clipboard.',
style: TextStyle(
color: Color.fromARGB(255, 255, 255, 255),
fontSize: 12.0,
),
),
duration: Duration(milliseconds: 2000),
),
duration: Duration(milliseconds: 2000),
),
);
Navigator.pop(context);
);
Navigator.pop(context);
}
},
onSelectText: () {
MixpanelManager().track('Chat Message Text Selected',
properties: {'message': message.text});
routeToPage(context, SelectTextScreen(message: message));
},
onShare: () {
MixpanelManager()
Expand Down Expand Up @@ -291,6 +302,8 @@ class ChatPageState extends State<ChatPage> with AutomaticKeepAliveClientMixin {
Navigator.of(context).pop();
},
() {
MixpanelManager().track('Chat Message Reported',
properties: {'message': message.text});
Navigator.of(context).pop();
Navigator.of(context).pop();
context.read<MessageProvider>().removeLocalMessage(message.id);
Expand All @@ -313,7 +326,6 @@ class ChatPageState extends State<ChatPage> with AutomaticKeepAliveClientMixin {
);
},
);
// Navigator.pop(context);
},
),
);
Expand Down
33 changes: 33 additions & 0 deletions app/lib/pages/chat/select_text_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'package:flutter/material.dart';
import 'package:friend_private/backend/schema/message.dart';

import 'widgets/markdown_message_widget.dart';

class SelectTextScreen extends StatelessWidget {
final ServerMessage message;
const SelectTextScreen({super.key, required this.message});

@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Theme.of(context).colorScheme.primary,
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.primary,
automaticallyImplyLeading: true,
title: const Text('Select Text'),
centerTitle: false,
leading: IconButton(
icon: const Icon(Icons.arrow_back_ios_new),
onPressed: () {
Navigator.pop(context);
},
),
elevation: 0,
),
body: Padding(
padding: const EdgeInsets.all(10.0),
child: SelectionArea(child: getMarkdownWidget(context, message.text)),
),
);
}
}
7 changes: 7 additions & 0 deletions app/lib/pages/chat/widgets/message_action_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import 'markdown_message_widget.dart';

class MessageActionMenu extends StatelessWidget {
final Function()? onCopy;
final Function()? onSelectText;
final Function()? onShare;
final Function()? onReport;
final String message;

const MessageActionMenu({
super.key,
this.onCopy,
this.onSelectText,
this.onShare,
this.onReport,
required this.message,
Expand Down Expand Up @@ -46,6 +48,11 @@ class MessageActionMenu extends StatelessWidget {
icon: Icons.copy,
onTap: onCopy,
),
_buildActionButton(
title: 'Select Text',
icon: Icons.description_outlined,
onTap: onSelectText,
),
_buildActionButton(
title: 'Share',
icon: Icons.share,
Expand Down

0 comments on commit ab3eaa9

Please sign in to comment.