Oh god, so much code for such a minor flow. Ambiguous sender manually fetched prefix DMs are now visible.

This commit is contained in:
Jack Kingsman
2026-03-11 20:38:41 -07:00
parent e0df30b5f0
commit 20d0bd92bb
32 changed files with 876 additions and 65 deletions
+16
View File
@@ -41,6 +41,22 @@ export function setLastMessageTime(key: string, timestamp: number): Conversation
return { ...lastMessageTimesCache };
}
/**
* Move conversation timing state to a new key, preserving the most recent timestamp.
*/
export function renameConversationTimeKey(oldKey: string, newKey: string): ConversationTimes {
if (oldKey === newKey) return { ...lastMessageTimesCache };
const oldTimestamp = lastMessageTimesCache[oldKey];
const newTimestamp = lastMessageTimesCache[newKey];
if (oldTimestamp !== undefined) {
lastMessageTimesCache[newKey] =
newTimestamp === undefined ? oldTimestamp : Math.max(newTimestamp, oldTimestamp);
delete lastMessageTimesCache[oldKey];
}
return { ...lastMessageTimesCache };
}
/**
* Generate a state tracking key for message times.
*
+16 -2
View File
@@ -21,6 +21,20 @@ function getPubkeyPrefix(key: string): string {
/**
* Get a display name for a contact, falling back to pubkey prefix.
*/
export function getContactDisplayName(name: string | null | undefined, pubkey: string): string {
return name || getPubkeyPrefix(pubkey);
export function getContactDisplayName(
name: string | null | undefined,
pubkey: string,
lastAdvert?: number | null
): string {
if (name) return name;
if (isUnknownFullKeyContact(pubkey, lastAdvert)) return '[unknown sender]';
return getPubkeyPrefix(pubkey);
}
export function isPrefixOnlyContact(pubkey: string): boolean {
return pubkey.length < 64;
}
export function isUnknownFullKeyContact(pubkey: string, lastAdvert?: number | null): boolean {
return pubkey.length === 64 && !lastAdvert;
}
+7 -2
View File
@@ -86,14 +86,19 @@ export function resolveChannelFromHashToken(token: string, channels: Channel[]):
export function resolveContactFromHashToken(token: string, contacts: Contact[]): Contact | null {
const normalizedToken = token.trim();
if (!normalizedToken) return null;
const lowerToken = normalizedToken.toLowerCase();
// Preferred path: stable identity by full public key.
const byKey = contacts.find((c) => c.public_key.toLowerCase() === normalizedToken.toLowerCase());
const byKey = contacts.find((c) => c.public_key.toLowerCase() === lowerToken);
if (byKey) return byKey;
// Backward compatibility for legacy name/prefix-based hashes.
return (
contacts.find((c) => getContactDisplayName(c.name, c.public_key) === normalizedToken) || null
contacts.find(
(c) =>
getContactDisplayName(c.name, c.public_key, c.last_advert) === normalizedToken ||
c.public_key.toLowerCase().startsWith(lowerToken)
) || null
);
}