feat: Implement clear chat, delete conversation, mute, and report options within the chat screen.
This commit is contained in:
@@ -29,6 +29,7 @@ class _ChatScreenState extends ConsumerState<ChatScreen>
|
||||
final ScrollController _scrollController = ScrollController();
|
||||
final FocusNode _messageFocusNode = FocusNode();
|
||||
bool _isComposing = false;
|
||||
bool _isMuted = false;
|
||||
int _previousMessageCount = 0;
|
||||
|
||||
final SocketService _socket = SocketService();
|
||||
@@ -145,6 +146,107 @@ class _ChatScreenState extends ConsumerState<ChatScreen>
|
||||
});
|
||||
}
|
||||
|
||||
void _handleMenuAction(String action, String? agentProfileId) {
|
||||
switch (action) {
|
||||
case 'clear_chat':
|
||||
_showConfirmDialog(
|
||||
title: 'Clear Chat',
|
||||
message: 'Are you sure you want to clear all messages? This cannot be undone.',
|
||||
onConfirm: () {
|
||||
ref.read(messagingProvider.notifier).clearChat(widget.conversationId);
|
||||
},
|
||||
);
|
||||
break;
|
||||
case 'mute':
|
||||
setState(() => _isMuted = !_isMuted);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(_isMuted ? 'Notifications muted' : 'Notifications unmuted'),
|
||||
duration: const Duration(seconds: 2),
|
||||
),
|
||||
);
|
||||
break;
|
||||
case 'report':
|
||||
_showReportDialog();
|
||||
break;
|
||||
case 'delete':
|
||||
_showConfirmDialog(
|
||||
title: 'Delete Conversation',
|
||||
message: 'Are you sure you want to delete this conversation? This cannot be undone.',
|
||||
onConfirm: () {
|
||||
ref.read(messagingProvider.notifier).deleteConversation(widget.conversationId);
|
||||
context.go('/messages');
|
||||
},
|
||||
isDanger: true,
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void _showConfirmDialog({
|
||||
required String title,
|
||||
required String message,
|
||||
required VoidCallback onConfirm,
|
||||
bool isDanger = false,
|
||||
}) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: Text(title),
|
||||
content: Text(message),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(ctx);
|
||||
onConfirm();
|
||||
},
|
||||
child: Text(
|
||||
'Confirm',
|
||||
style: TextStyle(color: isDanger ? Colors.red : null),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showReportDialog() {
|
||||
final controller = TextEditingController();
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: const Text('Report User'),
|
||||
content: TextField(
|
||||
controller: controller,
|
||||
maxLines: 3,
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'Describe the issue...',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(ctx);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Report submitted. Thank you.')),
|
||||
);
|
||||
},
|
||||
child: const Text('Submit'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _handleBack() {
|
||||
ref.read(messagingProvider.notifier).setActiveConversation(null);
|
||||
context.go('/messages');
|
||||
@@ -255,6 +357,7 @@ class _ChatScreenState extends ConsumerState<ChatScreen>
|
||||
name: otherPartyName,
|
||||
isOnline: isOnline,
|
||||
avatar: otherPartyAvatar,
|
||||
agentProfileId: conversation?.agentProfileId,
|
||||
),
|
||||
Expanded(
|
||||
child: messagingState.isLoadingMessages && messages.isEmpty
|
||||
@@ -289,6 +392,7 @@ class _ChatScreenState extends ConsumerState<ChatScreen>
|
||||
required String name,
|
||||
required bool isOnline,
|
||||
String? avatar,
|
||||
String? agentProfileId,
|
||||
}) {
|
||||
final initials = _getInitials(name);
|
||||
|
||||
@@ -385,30 +489,44 @@ class _ChatScreenState extends ConsumerState<ChatScreen>
|
||||
],
|
||||
),
|
||||
),
|
||||
// Three dots (vertical)
|
||||
GestureDetector(
|
||||
onTap: () {},
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 10),
|
||||
child: Icon(
|
||||
Icons.more_vert,
|
||||
size: 20,
|
||||
color: AppColors.primaryDark,
|
||||
),
|
||||
// Three dots menu (matches web: Clear Chat, Mute, Report, Delete)
|
||||
PopupMenuButton<String>(
|
||||
icon: const Icon(
|
||||
Icons.more_vert,
|
||||
size: 20,
|
||||
color: AppColors.primaryDark,
|
||||
),
|
||||
padding: EdgeInsets.zero,
|
||||
onSelected: (value) => _handleMenuAction(value, agentProfileId),
|
||||
itemBuilder: (_) => [
|
||||
const PopupMenuItem(
|
||||
value: 'clear_chat',
|
||||
child: Text('Clear Chat'),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'mute',
|
||||
child: Text(_isMuted ? 'Unmute Notifications' : 'Mute Notifications'),
|
||||
),
|
||||
const PopupMenuItem(
|
||||
value: 'report',
|
||||
child: Text('Report User'),
|
||||
),
|
||||
const PopupMenuItem(
|
||||
value: 'delete',
|
||||
child: Text(
|
||||
'Delete Conversation',
|
||||
style: TextStyle(color: Colors.red),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
// Star icon
|
||||
GestureDetector(
|
||||
onTap: () {},
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(right: 4),
|
||||
child: Icon(
|
||||
Icons.star_rounded,
|
||||
size: 24,
|
||||
color: AppColors.accentOrange,
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 4),
|
||||
child: Icon(
|
||||
Icons.star_rounded,
|
||||
size: 24,
|
||||
color: AppColors.accentOrange,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user