feat: derive communikey members from messages, admin is community pubkey

This commit is contained in:
Claude
2026-01-12 12:55:34 +00:00
parent 39c101808d
commit 45b17b9ccf
2 changed files with 48 additions and 20 deletions

View File

@@ -411,33 +411,60 @@ export function ChatViewer({
| LiveActivityMetadata
| undefined;
// Derive participants from messages for live activities (unique pubkeys who have chatted)
// Derive participants from messages for live activities and communikeys (unique pubkeys who have chatted)
const derivedParticipants = useMemo(() => {
if (conversation?.type !== "live-chat" || !messages) {
return conversation?.participants || [];
}
// For communikeys, derive members from messages with community pubkey as admin
if (conversation?.protocol === "communikeys" && messages) {
const communityPubkey = conversation.metadata?.communityPubkey as
| string
| undefined;
const participants: { pubkey: string; role: "host" | "member" }[] = [];
const hostPubkey = liveActivity?.hostPubkey;
const participants: { pubkey: string; role: "host" | "member" }[] = [];
// Host always first
if (hostPubkey) {
participants.push({ pubkey: hostPubkey, role: "host" });
}
// Add other participants from messages (excluding host)
const seen = new Set(hostPubkey ? [hostPubkey] : []);
for (const msg of messages) {
if (msg.type !== "system" && !seen.has(msg.author)) {
seen.add(msg.author);
participants.push({ pubkey: msg.author, role: "member" });
// Community pubkey is the admin (host)
if (communityPubkey) {
participants.push({ pubkey: communityPubkey, role: "host" });
}
// Add other participants from messages (excluding admin)
const seen = new Set(communityPubkey ? [communityPubkey] : []);
for (const msg of messages) {
if (msg.type !== "system" && !seen.has(msg.author)) {
seen.add(msg.author);
participants.push({ pubkey: msg.author, role: "member" });
}
}
return participants;
}
return participants;
// For live activities, derive from messages with host pubkey
if (conversation?.type === "live-chat" && messages) {
const hostPubkey = liveActivity?.hostPubkey;
const participants: { pubkey: string; role: "host" | "member" }[] = [];
// Host always first
if (hostPubkey) {
participants.push({ pubkey: hostPubkey, role: "host" });
}
// Add other participants from messages (excluding host)
const seen = new Set(hostPubkey ? [hostPubkey] : []);
for (const msg of messages) {
if (msg.type !== "system" && !seen.has(msg.author)) {
seen.add(msg.author);
participants.push({ pubkey: msg.author, role: "member" });
}
}
return participants;
}
return conversation?.participants || [];
}, [
conversation?.protocol,
conversation?.type,
conversation?.participants,
conversation?.metadata?.communityPubkey,
messages,
liveActivity?.hostPubkey,
]);

View File

@@ -210,7 +210,8 @@ export class CommunikeysAdapter extends ChatProtocolAdapter {
type: "group",
protocol: "communikeys",
title: displayName,
participants: [], // Could fetch from badge holders later
// Community pubkey is the admin, other members derived from messages in ChatViewer
participants: [{ pubkey: communityPubkey, role: "host" as const }],
metadata: {
communityPubkey,
communityRelays,