mirror of
https://github.com/jkingsman/Remote-Terminal-for-MeshCore.git
synced 2026-07-06 01:42:11 +02:00
Oh god, so much code for such a minor flow. Ambiguous sender manually fetched prefix DMs are now visible.
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user