Begone, prefix matching; use the whole key you have

This commit is contained in:
Jack Kingsman
2026-01-19 00:01:25 -08:00
parent 9e86d263f7
commit 3cb5711b5c
13 changed files with 76 additions and 123 deletions
+2 -11
View File
@@ -9,8 +9,6 @@
* across devices - see useUnreadCounts hook.
*/
import { getPubkeyPrefix } from './pubkey';
const LAST_MESSAGE_KEY = 'remoteterm-lastMessageTime';
const SORT_ORDER_KEY = 'remoteterm-sortOrder';
@@ -49,17 +47,10 @@ export function setLastMessageTime(key: string, timestamp: number): Conversation
* This is NOT the same as Message.conversation_key (the database field).
* This creates prefixed keys for state tracking:
* - Channels: "channel-{channelKey}"
* - Contacts: "contact-{12-char-pubkey-prefix}"
*
* The 12-char prefix for contacts ensures consistent matching regardless
* of whether we have a full 64-char pubkey or just a prefix.
* - Contacts: "contact-{publicKey}"
*/
export function getStateKey(type: 'channel' | 'contact', id: string): string {
if (type === 'channel') {
return `channel-${id}`;
}
// For contacts, use 12-char prefix for consistent matching
return `contact-${getPubkeyPrefix(id)}`;
return `${type}-${id}`;
}
/**
+1 -10
View File
@@ -7,27 +7,18 @@
*/
import type { Favorite } from '../types';
import { pubkeysMatch } from './pubkey';
const FAVORITES_KEY = 'remoteterm-favorites';
/**
* Check if a conversation is favorited (from provided favorites array)
*
* For contacts, uses prefix matching to handle full pubkeys vs 12-char prefixes.
*/
export function isFavorite(
favorites: Favorite[],
type: 'channel' | 'contact',
id: string
): boolean {
return favorites.some((f) => {
if (f.type !== type) return false;
// For contacts, use prefix matching (handles full keys vs prefixes)
if (type === 'contact') return pubkeysMatch(f.id, id);
// For channels, exact match
return f.id === id;
});
return favorites.some((f) => f.type === type && f.id === id);
}
/**