mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-04-20 22:13:48 +00: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:
parent
fca810737d
commit
367f89fb1b
3 changed files with 15 additions and 9 deletions
|
|
@ -23,6 +23,7 @@ class Message {
|
|||
final int? pathLength;
|
||||
final Uint8List pathBytes;
|
||||
final Map<String, int> reactions;
|
||||
final Uint8List fourByteRoomContactKey;
|
||||
|
||||
Message({
|
||||
required this.senderKey,
|
||||
|
|
@ -40,8 +41,10 @@ class Message {
|
|||
this.tripTimeMs,
|
||||
this.pathLength,
|
||||
Uint8List? pathBytes,
|
||||
Uint8List? fourByteRoomContactKey,
|
||||
Map<String, int>? reactions,
|
||||
}) : pathBytes = pathBytes ?? Uint8List(0),
|
||||
fourByteRoomContactKey = fourByteRoomContactKey ?? Uint8List(0),
|
||||
reactions = reactions ?? {};
|
||||
|
||||
String get senderKeyHex => pubKeyToHex(senderKey);
|
||||
|
|
@ -58,6 +61,7 @@ class Message {
|
|||
Uint8List? pathBytes,
|
||||
bool? isCli,
|
||||
Map<String, int>? reactions,
|
||||
Uint8List? fourByteRoomContactKey,
|
||||
}) {
|
||||
return Message(
|
||||
senderKey: senderKey,
|
||||
|
|
@ -76,6 +80,7 @@ class Message {
|
|||
pathLength: pathLength ?? this.pathLength,
|
||||
pathBytes: pathBytes ?? this.pathBytes,
|
||||
reactions: reactions ?? this.reactions,
|
||||
fourByteRoomContactKey: fourByteRoomContactKey ?? this.fourByteRoomContactKey,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -209,13 +209,13 @@ class _RoomChatScreenState extends State<RoomChatScreen> {
|
|||
final message = messages[index];
|
||||
final contact = _resolveContactFrom4Bytes(
|
||||
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(
|
||||
message: message,
|
||||
senderName: contact.name,
|
||||
onTap: () => _openMessagePath(message),
|
||||
senderName: "${contact.name} [$fourByteHex]",
|
||||
onTap: () => _openMessagePath(message, contact),
|
||||
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 fourByteHex = message.fourByteRoomContactKey.map((b) => b.toRadixString(16).padLeft(2, '0')).join().toUpperCase();
|
||||
final senderName =
|
||||
message.isOutgoing ? (connector.selfName ?? 'Me') : widget.contact.name;
|
||||
message.isOutgoing ? (connector.selfName ?? 'Me') : "${contact.name} [$fourByteHex]";
|
||||
final pathMessage = ChannelMessage(
|
||||
senderKey: null,
|
||||
senderName: senderName,
|
||||
|
|
@ -899,8 +900,6 @@ class _MessageBubble extends StatelessWidget {
|
|||
? colorScheme.onErrorContainer
|
||||
: (isOutgoing ? colorScheme.onPrimary : colorScheme.onSurface);
|
||||
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));
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 4),
|
||||
|
|
@ -954,7 +953,7 @@ class _MessageBubble extends StatelessWidget {
|
|||
if(!isOutgoing)
|
||||
|
||||
Text(
|
||||
"[$hexString] $messageText",
|
||||
messageText,
|
||||
style: TextStyle(
|
||||
color: textColor,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ class MessageStore {
|
|||
'pathLength': msg.pathLength,
|
||||
'pathBytes': msg.pathBytes.isNotEmpty ? base64Encode(msg.pathBytes) : null,
|
||||
'reactions': msg.reactions,
|
||||
'fourByteRoomContactKey': base64Encode(msg.fourByteRoomContactKey),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -86,6 +87,7 @@ 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)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue