chore(dm): remove the unused useGroupConversations hook
It was exported but referenced nowhere (only in a comment); the 1:1 inbox never surfaced group chats. Comment updated accordingly.
This commit is contained in:
parent
2edf7a797e
commit
fb5ebb5cd4
1 changed files with 1 additions and 138 deletions
|
|
@ -436,7 +436,7 @@ export function useConversations() {
|
|||
const pTags = rumor.tags.filter(t => t[0] === 'p').map(t => t[1]);
|
||||
|
||||
// 1:1 list only. A rumor addressed to more than one recipient is a
|
||||
// GROUP message (surfaced by useGroupConversations). Without this
|
||||
// GROUP message, which this inbox does not surface. Without this
|
||||
// guard each group would masquerade as a phantom 1:1 with whichever
|
||||
// participant happened to speak, and would appear twice in the UI.
|
||||
if (pTags.length > 1) continue;
|
||||
|
|
@ -506,143 +506,6 @@ export function formatPubkeyShort(pubkey: string): string {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to fetch group conversations (multi-participant chats)
|
||||
* Group conversations have more than 1 p-tag in the rumor
|
||||
*/
|
||||
export function useGroupConversations() {
|
||||
const { nostr } = useNostr();
|
||||
const { user } = useCurrentUser();
|
||||
const { logins } = useNostrLogin();
|
||||
const { config } = useAppContext();
|
||||
const nip44Available = checkNip44(user, logins);
|
||||
|
||||
const relayUrls = config.relayMetadata.relays
|
||||
.filter(r => r.read)
|
||||
.map(r => r.url)
|
||||
.sort()
|
||||
.join(',');
|
||||
|
||||
return useQuery({
|
||||
queryKey: ['group-conversations', user?.pubkey, relayUrls],
|
||||
queryFn: async (c) => {
|
||||
if (!user?.signer?.nip44) return [];
|
||||
|
||||
const signal = AbortSignal.any([c.signal, AbortSignal.timeout(15000)]);
|
||||
|
||||
const readRelays = config.relayMetadata.relays
|
||||
.filter(r => r.read)
|
||||
.map(r => r.url);
|
||||
|
||||
// Query for gift wraps addressed to us
|
||||
const allEvents: NostrEvent[] = [];
|
||||
|
||||
for (const relayUrl of readRelays) {
|
||||
try {
|
||||
const relay = nostr.relay(relayUrl);
|
||||
const events = await relay.query(
|
||||
[{
|
||||
kinds: [GIFT_WRAP_KIND],
|
||||
'#p': [user.pubkey],
|
||||
limit: 200,
|
||||
}],
|
||||
{ signal }
|
||||
);
|
||||
allEvents.push(...events);
|
||||
} catch (error) {
|
||||
console.warn(`[DM] Failed to query ${relayUrl}:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
// Deduplicate
|
||||
const uniqueEvents = Array.from(
|
||||
new Map(allEvents.map(e => [e.id, e])).values()
|
||||
);
|
||||
|
||||
// Decrypt and find group conversations (>1 participant)
|
||||
const groupMap = new Map<string, { participants: string[]; messages: DirectMessage[]; subject?: string }>();
|
||||
|
||||
for (const giftWrap of uniqueEvents) {
|
||||
try {
|
||||
// Decrypt gift wrap
|
||||
const sealJson = await user.signer.nip44.decrypt(giftWrap.pubkey, giftWrap.content);
|
||||
const seal = JSON.parse(sealJson) as NostrEvent;
|
||||
|
||||
if (seal.kind !== SEAL_KIND) continue;
|
||||
|
||||
// Decrypt seal
|
||||
const rumorJson = await user.signer.nip44.decrypt(seal.pubkey, seal.content);
|
||||
const rumor = JSON.parse(rumorJson) as NostrEvent;
|
||||
|
||||
if (rumor.pubkey !== seal.pubkey) continue;
|
||||
if (rumor.kind !== DM_KIND) continue;
|
||||
|
||||
// Get all participants from p tags
|
||||
const pTags = rumor.tags.filter(t => t[0] === 'p').map(t => t[1]);
|
||||
|
||||
// Only include if this is a group (more than 1 p tag)
|
||||
if (pTags.length <= 1) continue;
|
||||
|
||||
// Include sender in participants
|
||||
const allParticipants = [...new Set([rumor.pubkey, ...pTags])];
|
||||
const groupId = getGroupId(allParticipants);
|
||||
|
||||
// Get subject if present
|
||||
const subject = rumor.tags.find(t => t[0] === 'subject')?.[1];
|
||||
|
||||
const message: DirectMessage = {
|
||||
id: rumor.id,
|
||||
pubkey: rumor.pubkey,
|
||||
content: rumor.content,
|
||||
createdAt: rumor.created_at,
|
||||
conversationWith: groupId,
|
||||
participants: allParticipants,
|
||||
subject,
|
||||
};
|
||||
|
||||
const existing = groupMap.get(groupId) || {
|
||||
participants: allParticipants,
|
||||
messages: [],
|
||||
subject
|
||||
};
|
||||
existing.messages.push(message);
|
||||
// Update subject if newer message has one
|
||||
if (subject && message.createdAt > (existing.messages[0]?.createdAt || 0)) {
|
||||
existing.subject = subject;
|
||||
}
|
||||
groupMap.set(groupId, existing);
|
||||
|
||||
} catch (error) {
|
||||
console.debug('[DM] Failed to decrypt group message:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Build group conversation list
|
||||
const conversations: Conversation[] = [];
|
||||
|
||||
for (const [groupId, data] of groupMap) {
|
||||
const sorted = data.messages.sort((a, b) => b.createdAt - a.createdAt);
|
||||
|
||||
conversations.push({
|
||||
pubkey: groupId, // Use group ID as identifier
|
||||
participants: data.participants,
|
||||
lastMessage: sorted[0],
|
||||
unreadCount: 0,
|
||||
isGroup: true,
|
||||
subject: data.subject,
|
||||
});
|
||||
}
|
||||
|
||||
// Sort by last message time
|
||||
return conversations.sort((a, b) =>
|
||||
(b.lastMessage?.createdAt || 0) - (a.lastMessage?.createdAt || 0)
|
||||
);
|
||||
},
|
||||
enabled: nip44Available,
|
||||
...amberSafeQueryOptions(isInteractiveSigner(user, logins)),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to fetch messages in a specific group conversation
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in a new issue