mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-07-08 01:33:24 +10:00
Added value to Message fourByteRoomContactKey which holds the first 4 bytes of the contacts pub key that posted the message to the room.
This commit is contained in:
@@ -23,6 +23,7 @@ class Message {
|
|||||||
final int? pathLength;
|
final int? pathLength;
|
||||||
final Uint8List pathBytes;
|
final Uint8List pathBytes;
|
||||||
final Map<String, int> reactions;
|
final Map<String, int> reactions;
|
||||||
|
final Uint8List fourByteRoomContactKey;
|
||||||
|
|
||||||
Message({
|
Message({
|
||||||
required this.senderKey,
|
required this.senderKey,
|
||||||
@@ -40,8 +41,10 @@ class Message {
|
|||||||
this.tripTimeMs,
|
this.tripTimeMs,
|
||||||
this.pathLength,
|
this.pathLength,
|
||||||
Uint8List? pathBytes,
|
Uint8List? pathBytes,
|
||||||
|
Uint8List? fourByteRoomContactKey,
|
||||||
Map<String, int>? reactions,
|
Map<String, int>? reactions,
|
||||||
}) : pathBytes = pathBytes ?? Uint8List(0),
|
}) : pathBytes = pathBytes ?? Uint8List(0),
|
||||||
|
fourByteRoomContactKey = fourByteRoomContactKey ?? Uint8List(0),
|
||||||
reactions = reactions ?? {};
|
reactions = reactions ?? {};
|
||||||
|
|
||||||
String get senderKeyHex => pubKeyToHex(senderKey);
|
String get senderKeyHex => pubKeyToHex(senderKey);
|
||||||
@@ -58,6 +61,7 @@ class Message {
|
|||||||
Uint8List? pathBytes,
|
Uint8List? pathBytes,
|
||||||
bool? isCli,
|
bool? isCli,
|
||||||
Map<String, int>? reactions,
|
Map<String, int>? reactions,
|
||||||
|
Uint8List? fourByteRoomContactKey,
|
||||||
}) {
|
}) {
|
||||||
return Message(
|
return Message(
|
||||||
senderKey: senderKey,
|
senderKey: senderKey,
|
||||||
@@ -76,6 +80,7 @@ class Message {
|
|||||||
pathLength: pathLength ?? this.pathLength,
|
pathLength: pathLength ?? this.pathLength,
|
||||||
pathBytes: pathBytes ?? this.pathBytes,
|
pathBytes: pathBytes ?? this.pathBytes,
|
||||||
reactions: reactions ?? this.reactions,
|
reactions: reactions ?? this.reactions,
|
||||||
|
fourByteRoomContactKey: fourByteRoomContactKey ?? this.fourByteRoomContactKey,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -209,13 +209,13 @@ class _RoomChatScreenState extends State<RoomChatScreen> {
|
|||||||
final message = messages[index];
|
final message = messages[index];
|
||||||
final contact = _resolveContactFrom4Bytes(
|
final contact = _resolveContactFrom4Bytes(
|
||||||
connector,
|
connector,
|
||||||
Uint8List.fromList(message.text.substring(0, 4.clamp(0, message.text.length)).codeUnits),
|
message.fourByteRoomContactKey.isEmpty ? Uint8List.fromList([0, 0, 0, 0]) : message.fourByteRoomContactKey,
|
||||||
);
|
);
|
||||||
|
final fourByteHex = message.fourByteRoomContactKey.map((b) => b.toRadixString(16).padLeft(2, '0')).join().toUpperCase();
|
||||||
return _MessageBubble(
|
return _MessageBubble(
|
||||||
message: message,
|
message: message,
|
||||||
senderName: contact.name,
|
senderName: "${contact.name} [$fourByteHex]",
|
||||||
onTap: () => _openMessagePath(message),
|
onTap: () => _openMessagePath(message, contact),
|
||||||
onLongPress: () => _showMessageActions(message),
|
onLongPress: () => _showMessageActions(message),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -747,10 +747,11 @@ class _RoomChatScreenState extends State<RoomChatScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void _openMessagePath(Message message) {
|
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 senderName =
|
final senderName =
|
||||||
message.isOutgoing ? (connector.selfName ?? 'Me') : widget.contact.name;
|
message.isOutgoing ? (connector.selfName ?? 'Me') : "${contact.name} [$fourByteHex]";
|
||||||
final pathMessage = ChannelMessage(
|
final pathMessage = ChannelMessage(
|
||||||
senderKey: null,
|
senderKey: null,
|
||||||
senderName: senderName,
|
senderName: senderName,
|
||||||
@@ -899,8 +900,6 @@ class _MessageBubble extends StatelessWidget {
|
|||||||
? colorScheme.onErrorContainer
|
? colorScheme.onErrorContainer
|
||||||
: (isOutgoing ? colorScheme.onPrimary : colorScheme.onSurface);
|
: (isOutgoing ? colorScheme.onPrimary : colorScheme.onSurface);
|
||||||
final metaColor = textColor.withValues(alpha: 0.7);
|
final metaColor = textColor.withValues(alpha: 0.7);
|
||||||
final bytes4 = Uint8List.fromList(message.text.substring(0, 4.clamp(0, message.text.length)).codeUnits);
|
|
||||||
final hexString = bytes4.map((b) => b.toRadixString(16).padLeft(2, '0')).join().toUpperCase();
|
|
||||||
final messageText = message.text.substring(4.clamp(0, message.text.length));
|
final messageText = message.text.substring(4.clamp(0, message.text.length));
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 4),
|
padding: const EdgeInsets.symmetric(vertical: 4),
|
||||||
@@ -954,7 +953,7 @@ class _MessageBubble extends StatelessWidget {
|
|||||||
if(!isOutgoing)
|
if(!isOutgoing)
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
"[$hexString] $messageText",
|
messageText,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: textColor,
|
color: textColor,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ class MessageStore {
|
|||||||
'pathLength': msg.pathLength,
|
'pathLength': msg.pathLength,
|
||||||
'pathBytes': msg.pathBytes.isNotEmpty ? base64Encode(msg.pathBytes) : null,
|
'pathBytes': msg.pathBytes.isNotEmpty ? base64Encode(msg.pathBytes) : null,
|
||||||
'reactions': msg.reactions,
|
'reactions': msg.reactions,
|
||||||
|
'fourByteRoomContactKey': base64Encode(msg.fourByteRoomContactKey),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,6 +87,7 @@ 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)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user