fix: Show original poster name in room messages, not room server name

Room servers forward messages with the original author's 4-byte public
key prefix (roomPostAuthorPrefix). Was ignoring this — all room messages
showed the room server's name as sender.

Now resolves the actual poster's name from roomPostAuthorPrefix by
matching against the contacts list. Falls back to room server name if
the author isn't a known contact.

Also fixes findContactByPrefix to accept 4-byte prefixes (was rejecting
anything shorter than 6 bytes).

Fixes #22
This commit is contained in:
Janez T
2026-03-19 09:20:22 +01:00
parent f286b0afd1
commit e683ab933f
3 changed files with 27 additions and 11 deletions

View File

@@ -1134,16 +1134,31 @@ class AppProvider with ChangeNotifier {
return;
}
// Enrich message with sender name from contacts first
// Enrich message with sender name from contacts.
// For room-forwarded messages, resolve the original poster's name
// from roomPostAuthorPrefix instead of the room server's key.
Message enrichedMessage = message;
Contact? senderContact;
if (message.senderPublicKeyPrefix != null && message.senderName == null) {
final contact = contactsProvider.findContactByKey(
message.senderPublicKeyPrefix!,
);
if (contact != null) {
senderContact = contact;
enrichedMessage = message.copyWith(senderName: contact.advName);
if (message.senderName == null) {
// Try room post author first (the actual person who posted)
if (message.roomPostAuthorPrefix != null) {
final author = contactsProvider.findContactByPrefix(
message.roomPostAuthorPrefix!,
);
if (author != null) {
senderContact = author;
enrichedMessage = message.copyWith(senderName: author.advName);
}
}
// Fall back to sender key (direct messages, or room with unknown author)
if (senderContact == null && message.senderPublicKeyPrefix != null) {
final contact = contactsProvider.findContactByKey(
message.senderPublicKeyPrefix!,
);
if (contact != null) {
senderContact = contact;
enrichedMessage = message.copyWith(senderName: contact.advName);
}
}
}
senderContact ??= message.senderPublicKeyPrefix != null