Refactor code for improved readability and null safety in various files Also updated PR to allow login via map.

This commit is contained in:
zjs81
2026-01-11 11:51:40 -07:00
parent be3b920b3f
commit 8c3ffa5472
5 changed files with 54 additions and 22 deletions
+13 -11
View File
@@ -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,
@@ -831,6 +840,7 @@ class _ChatScreenState extends State<ChatScreen> {
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(
+28
View File
@@ -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'),
),
], ],
), ),
); );
+3 -1
View File
@@ -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,
); );
} }
} }