mirror of
https://github.com/dz0ny/meshcore-sar.git
synced 2026-08-13 17:30:28 +00:00
feat: Enhance message display with rich sender names and replace SnackBars with ToastLogger for notifications
This commit is contained in:
@@ -116,7 +116,7 @@ class Message {
|
|||||||
return '${diff.inDays}d ago';
|
return '${diff.inDays}d ago';
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get display name for sender
|
/// Get display name for sender (basic fallback without contact info)
|
||||||
String get displaySender {
|
String get displaySender {
|
||||||
if (senderName != null && senderName!.isNotEmpty) {
|
if (senderName != null && senderName!.isNotEmpty) {
|
||||||
return senderName!;
|
return senderName!;
|
||||||
@@ -130,6 +130,21 @@ class Message {
|
|||||||
return 'Unknown';
|
return 'Unknown';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get rich display name for sender using contact information
|
||||||
|
/// Returns emoji + display name if available, otherwise falls back to displaySender
|
||||||
|
String getRichDisplayName(dynamic contact) {
|
||||||
|
if (contact == null) return displaySender;
|
||||||
|
|
||||||
|
// If contact has roleEmoji, use it with displayName
|
||||||
|
final roleEmoji = contact.roleEmoji;
|
||||||
|
if (roleEmoji != null && roleEmoji.isNotEmpty) {
|
||||||
|
return '$roleEmoji ${contact.displayName}';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise just use advName or displayName
|
||||||
|
return contact.displayName ?? contact.advName ?? displaySender;
|
||||||
|
}
|
||||||
|
|
||||||
/// Convert to SAR marker if applicable
|
/// Convert to SAR marker if applicable
|
||||||
SarMarker? toSarMarker() {
|
SarMarker? toSarMarker() {
|
||||||
if (!isSarMarker || sarMarkerType == null || sarGpsCoordinates == null) {
|
if (!isSarMarker || sarMarkerType == null || sarGpsCoordinates == null) {
|
||||||
|
|||||||
@@ -537,6 +537,26 @@ class _MessageBubble extends StatelessWidget {
|
|||||||
final selfPublicKey = connectionProvider.deviceInfo.publicKey;
|
final selfPublicKey = connectionProvider.deviceInfo.publicKey;
|
||||||
final isOwnMessage = message.isFromSelf(selfPublicKey);
|
final isOwnMessage = message.isFromSelf(selfPublicKey);
|
||||||
|
|
||||||
|
// Look up contact information for rich display name
|
||||||
|
final contactsProvider = context.read<ContactsProvider>();
|
||||||
|
dynamic senderContact;
|
||||||
|
if (message.senderPublicKeyPrefix != null && !isOwnMessage) {
|
||||||
|
// Find contact by public key prefix (first 6 bytes)
|
||||||
|
final senderKeyHex = message.senderPublicKeyPrefix!
|
||||||
|
.sublist(0, message.senderPublicKeyPrefix!.length < 6 ? message.senderPublicKeyPrefix!.length : 6)
|
||||||
|
.map((b) => b.toRadixString(16).padLeft(2, '0'))
|
||||||
|
.join('');
|
||||||
|
|
||||||
|
senderContact = contactsProvider.contacts.where((c) {
|
||||||
|
return c.publicKeyHex.startsWith(senderKeyHex);
|
||||||
|
}).firstOrNull;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get rich display name (with emoji if available)
|
||||||
|
final displayName = isOwnMessage
|
||||||
|
? 'You'
|
||||||
|
: message.getRichDisplayName(senderContact);
|
||||||
|
|
||||||
// Debug: Log message details
|
// Debug: Log message details
|
||||||
if (message.text.startsWith('S:')) {
|
if (message.text.startsWith('S:')) {
|
||||||
debugPrint('🎨 [MessageBubble] Rendering SAR message:');
|
debugPrint('🎨 [MessageBubble] Rendering SAR message:');
|
||||||
@@ -622,7 +642,7 @@ class _MessageBubble extends StatelessWidget {
|
|||||||
const Icon(Icons.person, size: 16),
|
const Icon(Icons.person, size: 16),
|
||||||
const SizedBox(width: 4),
|
const SizedBox(width: 4),
|
||||||
Text(
|
Text(
|
||||||
isOwnMessage ? 'You' : message.displaySender,
|
displayName,
|
||||||
style: Theme.of(context).textTheme.labelMedium?.copyWith(
|
style: Theme.of(context).textTheme.labelMedium?.copyWith(
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
color: isOwnMessage ? Theme.of(context).colorScheme.primary : null,
|
color: isOwnMessage ? Theme.of(context).colorScheme.primary : null,
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import '../../providers/connection_provider.dart';
|
|||||||
import '../../providers/map_provider.dart';
|
import '../../providers/map_provider.dart';
|
||||||
import 'direct_message_sheet.dart';
|
import 'direct_message_sheet.dart';
|
||||||
import 'room_login_sheet.dart';
|
import 'room_login_sheet.dart';
|
||||||
|
import '../../utils/toast_logger.dart';
|
||||||
|
|
||||||
class ContactTile extends StatelessWidget {
|
class ContactTile extends StatelessWidget {
|
||||||
final Contact contact;
|
final Contact contact;
|
||||||
@@ -301,15 +302,11 @@ class ContactTile extends StatelessWidget {
|
|||||||
final hasPath = contact.hasPath;
|
final hasPath = contact.hasPath;
|
||||||
|
|
||||||
// Show initial notification reflecting the method being used
|
// Show initial notification reflecting the method being used
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ToastLogger.info(
|
||||||
SnackBar(
|
context,
|
||||||
content: Text(
|
hasPath
|
||||||
hasPath
|
? 'Pinging ${contact.displayName} (direct via path)...'
|
||||||
? 'Pinging ${contact.displayName} (direct via path)...'
|
: 'Pinging ${contact.displayName} (flooding - no path)...',
|
||||||
: 'Pinging ${contact.displayName} (flooding - no path)...',
|
|
||||||
),
|
|
||||||
duration: const Duration(seconds: 6),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Use smart ping with automatic fallback
|
// Use smart ping with automatic fallback
|
||||||
@@ -319,14 +316,9 @@ class ContactTile extends StatelessWidget {
|
|||||||
onRetryWithFlooding: () {
|
onRetryWithFlooding: () {
|
||||||
// Called when retrying with flooding after direct timeout
|
// Called when retrying with flooding after direct timeout
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ToastLogger.warning(
|
||||||
SnackBar(
|
context,
|
||||||
content: Text(
|
'Direct ping timeout - retrying ${contact.displayName} with flooding...',
|
||||||
'Direct ping timeout - retrying ${contact.displayName} with flooding...',
|
|
||||||
),
|
|
||||||
duration: const Duration(seconds: 3),
|
|
||||||
backgroundColor: Colors.orange,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -334,17 +326,17 @@ class ContactTile extends StatelessWidget {
|
|||||||
|
|
||||||
// Show final result
|
// Show final result
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
if (result.success) {
|
||||||
SnackBar(
|
ToastLogger.success(
|
||||||
content: Text(
|
context,
|
||||||
result.success
|
'Ping successful to ${contact.displayName}${result.retriedWithFlooding ? ' (via flooding fallback)' : ''}',
|
||||||
? 'Ping successful to ${contact.displayName}${result.retriedWithFlooding ? ' (via flooding fallback)' : ''}'
|
);
|
||||||
: 'Ping failed to ${contact.displayName} - no response received',
|
} else {
|
||||||
),
|
ToastLogger.error(
|
||||||
duration: const Duration(seconds: 2),
|
context,
|
||||||
backgroundColor: result.success ? Colors.green : Colors.red,
|
'Ping failed to ${contact.displayName} - no response received',
|
||||||
),
|
);
|
||||||
);
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@@ -600,12 +592,7 @@ class ContactTile extends StatelessWidget {
|
|||||||
onPressed: () {
|
onPressed: () {
|
||||||
final connectionProvider = context.read<ConnectionProvider>();
|
final connectionProvider = context.read<ConnectionProvider>();
|
||||||
connectionProvider.requestTelemetry(contact.publicKey, zeroHop: true);
|
connectionProvider.requestTelemetry(contact.publicKey, zeroHop: true);
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ToastLogger.info(context, 'Requesting telemetry from ${contact.displayName}...');
|
||||||
SnackBar(
|
|
||||||
content: Text('Requesting telemetry from ${contact.displayName}...'),
|
|
||||||
duration: const Duration(seconds: 2),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
icon: const Icon(Icons.refresh, size: 18),
|
icon: const Icon(Icons.refresh, size: 18),
|
||||||
label: const Text('Refresh'),
|
label: const Text('Refresh'),
|
||||||
@@ -665,12 +652,7 @@ class ContactTile extends StatelessWidget {
|
|||||||
child: OutlinedButton.icon(
|
child: OutlinedButton.icon(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
connectionProvider.resetPath(contact.publicKey);
|
connectionProvider.resetPath(contact.publicKey);
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ToastLogger.info(context, 'Path reset for ${contact.displayName}. Next message will find a new route.');
|
||||||
SnackBar(
|
|
||||||
content: Text('Path reset for ${contact.displayName}. Next message will find a new route.'),
|
|
||||||
duration: const Duration(seconds: 3),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
icon: const Icon(Icons.route),
|
icon: const Icon(Icons.route),
|
||||||
label: const Text('Reset Path (Re-route)'),
|
label: const Text('Reset Path (Re-route)'),
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import 'package:flutter/services.dart';
|
|||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import '../../models/contact.dart';
|
import '../../models/contact.dart';
|
||||||
import '../../providers/connection_provider.dart';
|
import '../../providers/connection_provider.dart';
|
||||||
|
import '../../utils/toast_logger.dart';
|
||||||
|
|
||||||
class DirectMessageSheet extends StatefulWidget {
|
class DirectMessageSheet extends StatefulWidget {
|
||||||
final Contact contact;
|
final Contact contact;
|
||||||
@@ -46,12 +47,7 @@ class _DirectMessageSheetState extends State<DirectMessageSheet> {
|
|||||||
|
|
||||||
if (!connectionProvider.deviceInfo.isConnected) {
|
if (!connectionProvider.deviceInfo.isConnected) {
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ToastLogger.error(context, 'Not connected to device');
|
||||||
const SnackBar(
|
|
||||||
content: Text('Not connected to device'),
|
|
||||||
backgroundColor: Colors.red,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,21 +65,10 @@ class _DirectMessageSheetState extends State<DirectMessageSheet> {
|
|||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
Navigator.pop(context); // Close the dialog
|
Navigator.pop(context); // Close the dialog
|
||||||
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ToastLogger.success(context, 'Direct message sent to ${widget.contact.displayName}');
|
||||||
SnackBar(
|
|
||||||
content: Text('Direct message sent to ${widget.contact.displayName}'),
|
|
||||||
backgroundColor: Colors.green,
|
|
||||||
duration: const Duration(seconds: 2),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ToastLogger.error(context, 'Failed to send: $e');
|
||||||
SnackBar(
|
|
||||||
content: Text('Failed to send: $e'),
|
|
||||||
backgroundColor: Colors.red,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user