mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-06-19 00:45:33 +10:00
Refactor code for improved readability and null safety in various files Also updated PR to allow login via map.
This commit is contained in:
@@ -1996,14 +1996,14 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
final settings = _appSettingsService!.settings;
|
||||
if (settings.notificationsEnabled && settings.notifyOnNewMessage) {
|
||||
// Find the contact name
|
||||
if(contact?.type == advTypeChat) {
|
||||
if (contact?.type == advTypeChat) {
|
||||
_notificationService.showMessageNotification(
|
||||
contactName: contact?.name ?? 'Unknown',
|
||||
message: message.text,
|
||||
contactId: message.senderKeyHex,
|
||||
badgeCount: getTotalUnreadCount(),
|
||||
);
|
||||
}else if(contact?.type == advTypeRoom) {
|
||||
} else if (contact?.type == advTypeRoom) {
|
||||
_notificationService.showMessageNotification(
|
||||
contactName: contact?.name ?? 'Unknown Room',
|
||||
message: message.text.substring(4),
|
||||
|
||||
@@ -208,7 +208,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
Contact contact = widget.contact;
|
||||
final message = messages[index];
|
||||
String fourByteHex = '';
|
||||
if(widget.contact.type == advTypeRoom) {
|
||||
if (widget.contact.type == advTypeRoom) {
|
||||
contact = _resolveContactFrom4Bytes(
|
||||
connector,
|
||||
message.fourByteRoomContactKey.isEmpty ? Uint8List.fromList([0, 0, 0, 0]) : message.fourByteRoomContactKey,
|
||||
@@ -763,9 +763,18 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
|
||||
void _openMessagePath(Message message, Contact contact) {
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final fourByteHex = message.fourByteRoomContactKey.map((b) => b.toRadixString(16).padLeft(2, '0')).join().toUpperCase();
|
||||
final senderName =
|
||||
message.isOutgoing ? (connector.selfName ?? 'Me') : widget.contact.type == advTypeRoom ? "${contact.name} [$fourByteHex]" : widget.contact.name;
|
||||
final fourByteHex = message.fourByteRoomContactKey
|
||||
.map((b) => b.toRadixString(16).padLeft(2, '0'))
|
||||
.join()
|
||||
.toUpperCase();
|
||||
final String senderName;
|
||||
if (message.isOutgoing) {
|
||||
senderName = connector.selfName ?? 'Me';
|
||||
} else if (widget.contact.type == advTypeRoom) {
|
||||
senderName = "${contact.name} [$fourByteHex]";
|
||||
} else {
|
||||
senderName = widget.contact.name;
|
||||
}
|
||||
final pathMessage = ChannelMessage(
|
||||
senderKey: null,
|
||||
senderName: senderName,
|
||||
@@ -826,11 +835,12 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
_retryMessage(message);
|
||||
},
|
||||
),
|
||||
if(widget.contact.type == advTypeRoom)
|
||||
if (widget.contact.type == advTypeRoom)
|
||||
ListTile(
|
||||
leading: const Icon(Icons.chat),
|
||||
title: const Text('Open Chat'),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
_openChat(context, contact);
|
||||
},
|
||||
),
|
||||
@@ -977,20 +987,12 @@ class _MessageBubble extends StatelessWidget {
|
||||
fallbackTextColor: textColor.withValues(alpha: 0.7),
|
||||
)
|
||||
else
|
||||
if(!isOutgoing)
|
||||
Text(
|
||||
messageText,
|
||||
style: TextStyle(
|
||||
color: textColor,
|
||||
),
|
||||
),
|
||||
if(isOutgoing)
|
||||
Text(
|
||||
message.text,
|
||||
style: TextStyle(
|
||||
color: textColor,
|
||||
),
|
||||
Text(
|
||||
messageText,
|
||||
style: TextStyle(
|
||||
color: textColor,
|
||||
),
|
||||
),
|
||||
if (isOutgoing && message.retryCount > 0) ...[
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
|
||||
@@ -681,7 +681,7 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
_showRepeaterLogin(context, contact);
|
||||
},
|
||||
)
|
||||
else if(isRoom)
|
||||
else if (isRoom)
|
||||
ListTile(
|
||||
leading: const Icon(Icons.room, color: Colors.blue),
|
||||
title: const Text('Room Login'),
|
||||
|
||||
@@ -18,6 +18,7 @@ import 'channels_screen.dart';
|
||||
import 'chat_screen.dart';
|
||||
import 'contacts_screen.dart';
|
||||
import '../widgets/repeater_login_dialog.dart';
|
||||
import '../widgets/room_login_dialog.dart';
|
||||
import 'repeater_hub_screen.dart';
|
||||
import 'settings_screen.dart';
|
||||
|
||||
@@ -572,6 +573,25 @@ class _MapScreenState extends State<MapScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
void _showRoomLogin(BuildContext context, Contact room) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => RoomLoginDialog(
|
||||
room: room,
|
||||
onLogin: (password) {
|
||||
// Navigate to chat screen after successful login
|
||||
context.read<MeshCoreConnector>().markContactRead(room.publicKeyHex);
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ChatScreen(contact: room),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showNodeInfo(BuildContext context, Contact contact) {
|
||||
showDialog(
|
||||
context: context,
|
||||
@@ -624,6 +644,14 @@ class _MapScreenState extends State<MapScreen> {
|
||||
},
|
||||
child: const Text('Manage Repeater'),
|
||||
),
|
||||
if (contact.type == advTypeRoom)
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
_showRoomLogin(context, contact);
|
||||
},
|
||||
child: const Text('Join Room'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -87,7 +87,9 @@ class MessageStore {
|
||||
reactions: (json['reactions'] as Map<String, dynamic>?)?.map(
|
||||
(key, value) => MapEntry(key, value as int),
|
||||
) ?? {},
|
||||
fourByteRoomContactKey: Uint8List.fromList(base64Decode(json['fourByteRoomContactKey'] as String)),
|
||||
fourByteRoomContactKey: json['fourByteRoomContactKey'] != null
|
||||
? Uint8List.fromList(base64Decode(json['fourByteRoomContactKey'] as String))
|
||||
: null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user