mirror of
https://github.com/jkingsman/Remote-Terminal-for-MeshCore.git
synced 2026-08-06 16:53:38 +02:00
Begone, prefix matching; use the whole key you have
This commit is contained in:
@@ -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}`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user