mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-08-03 22:43:00 +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;
|
final settings = _appSettingsService!.settings;
|
||||||
if (settings.notificationsEnabled && settings.notifyOnNewMessage) {
|
if (settings.notificationsEnabled && settings.notifyOnNewMessage) {
|
||||||
// Find the contact name
|
// Find the contact name
|
||||||
if(contact?.type == advTypeChat) {
|
if (contact?.type == advTypeChat) {
|
||||||
_notificationService.showMessageNotification(
|
_notificationService.showMessageNotification(
|
||||||
contactName: contact?.name ?? 'Unknown',
|
contactName: contact?.name ?? 'Unknown',
|
||||||
message: message.text,
|
message: message.text,
|
||||||
contactId: message.senderKeyHex,
|
contactId: message.senderKeyHex,
|
||||||
badgeCount: getTotalUnreadCount(),
|
badgeCount: getTotalUnreadCount(),
|
||||||
);
|
);
|
||||||
}else if(contact?.type == advTypeRoom) {
|
} else if (contact?.type == advTypeRoom) {
|
||||||
_notificationService.showMessageNotification(
|
_notificationService.showMessageNotification(
|
||||||
contactName: contact?.name ?? 'Unknown Room',
|
contactName: contact?.name ?? 'Unknown Room',
|
||||||
message: message.text.substring(4),
|
message: message.text.substring(4),
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
|||||||
Contact contact = widget.contact;
|
Contact contact = widget.contact;
|
||||||
final message = messages[index];
|
final message = messages[index];
|
||||||
String fourByteHex = '';
|
String fourByteHex = '';
|
||||||
if(widget.contact.type == advTypeRoom) {
|
if (widget.contact.type == advTypeRoom) {
|
||||||
contact = _resolveContactFrom4Bytes(
|
contact = _resolveContactFrom4Bytes(
|
||||||
connector,
|
connector,
|
||||||
message.fourByteRoomContactKey.isEmpty ? Uint8List.fromList([0, 0, 0, 0]) : message.fourByteRoomContactKey,
|
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) {
|
void _openMessagePath(Message message, Contact contact) {
|
||||||
final connector = context.read<MeshCoreConnector>();
|
final connector = context.read<MeshCoreConnector>();
|
||||||
final fourByteHex = message.fourByteRoomContactKey.map((b) => b.toRadixString(16).padLeft(2, '0')).join().toUpperCase();
|
final fourByteHex = message.fourByteRoomContactKey
|
||||||
final senderName =
|
.map((b) => b.toRadixString(16).padLeft(2, '0'))
|
||||||
message.isOutgoing ? (connector.selfName ?? 'Me') : widget.contact.type == advTypeRoom ? "${contact.name} [$fourByteHex]" : widget.contact.name;
|
.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(
|
final pathMessage = ChannelMessage(
|
||||||
senderKey: null,
|
senderKey: null,
|
||||||
senderName: senderName,
|
senderName: senderName,
|
||||||
@@ -826,11 +835,12 @@ class _ChatScreenState extends State<ChatScreen> {
|
|||||||
_retryMessage(message);
|
_retryMessage(message);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
if(widget.contact.type == advTypeRoom)
|
if (widget.contact.type == advTypeRoom)
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: const Icon(Icons.chat),
|
leading: const Icon(Icons.chat),
|
||||||
title: const Text('Open Chat'),
|
title: const Text('Open Chat'),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
|
Navigator.pop(sheetContext);
|
||||||
_openChat(context, contact);
|
_openChat(context, contact);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@@ -977,20 +987,12 @@ class _MessageBubble extends StatelessWidget {
|
|||||||
fallbackTextColor: textColor.withValues(alpha: 0.7),
|
fallbackTextColor: textColor.withValues(alpha: 0.7),
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
if(!isOutgoing)
|
Text(
|
||||||
Text(
|
messageText,
|
||||||
messageText,
|
style: TextStyle(
|
||||||
style: TextStyle(
|
color: textColor,
|
||||||
color: textColor,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if(isOutgoing)
|
|
||||||
Text(
|
|
||||||
message.text,
|
|
||||||
style: TextStyle(
|
|
||||||
color: textColor,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
|
),
|
||||||
if (isOutgoing && message.retryCount > 0) ...[
|
if (isOutgoing && message.retryCount > 0) ...[
|
||||||
const SizedBox(height: 4),
|
const SizedBox(height: 4),
|
||||||
Text(
|
Text(
|
||||||
|
|||||||
@@ -681,7 +681,7 @@ class _ContactsScreenState extends State<ContactsScreen>
|
|||||||
_showRepeaterLogin(context, contact);
|
_showRepeaterLogin(context, contact);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
else if(isRoom)
|
else if (isRoom)
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: const Icon(Icons.room, color: Colors.blue),
|
leading: const Icon(Icons.room, color: Colors.blue),
|
||||||
title: const Text('Room Login'),
|
title: const Text('Room Login'),
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import 'channels_screen.dart';
|
|||||||
import 'chat_screen.dart';
|
import 'chat_screen.dart';
|
||||||
import 'contacts_screen.dart';
|
import 'contacts_screen.dart';
|
||||||
import '../widgets/repeater_login_dialog.dart';
|
import '../widgets/repeater_login_dialog.dart';
|
||||||
|
import '../widgets/room_login_dialog.dart';
|
||||||
import 'repeater_hub_screen.dart';
|
import 'repeater_hub_screen.dart';
|
||||||
import 'settings_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) {
|
void _showNodeInfo(BuildContext context, Contact contact) {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
@@ -624,6 +644,14 @@ class _MapScreenState extends State<MapScreen> {
|
|||||||
},
|
},
|
||||||
child: const Text('Manage Repeater'),
|
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(
|
reactions: (json['reactions'] as Map<String, dynamic>?)?.map(
|
||||||
(key, value) => MapEntry(key, value as int),
|
(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