mirror of
https://github.com/purrgrammer/grimoire.git
synced 2026-06-06 02:31:13 +02:00
feat: derive communikey members from messages, admin is community pubkey
This commit is contained in:
@@ -411,33 +411,60 @@ export function ChatViewer({
|
|||||||
| LiveActivityMetadata
|
| LiveActivityMetadata
|
||||||
| undefined;
|
| 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(() => {
|
const derivedParticipants = useMemo(() => {
|
||||||
if (conversation?.type !== "live-chat" || !messages) {
|
// For communikeys, derive members from messages with community pubkey as admin
|
||||||
return conversation?.participants || [];
|
if (conversation?.protocol === "communikeys" && messages) {
|
||||||
}
|
const communityPubkey = conversation.metadata?.communityPubkey as
|
||||||
|
| string
|
||||||
|
| undefined;
|
||||||
|
const participants: { pubkey: string; role: "host" | "member" }[] = [];
|
||||||
|
|
||||||
const hostPubkey = liveActivity?.hostPubkey;
|
// Community pubkey is the admin (host)
|
||||||
const participants: { pubkey: string; role: "host" | "member" }[] = [];
|
if (communityPubkey) {
|
||||||
|
participants.push({ pubkey: communityPubkey, role: "host" });
|
||||||
// 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" });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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?.type,
|
||||||
conversation?.participants,
|
conversation?.participants,
|
||||||
|
conversation?.metadata?.communityPubkey,
|
||||||
messages,
|
messages,
|
||||||
liveActivity?.hostPubkey,
|
liveActivity?.hostPubkey,
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -210,7 +210,8 @@ export class CommunikeysAdapter extends ChatProtocolAdapter {
|
|||||||
type: "group",
|
type: "group",
|
||||||
protocol: "communikeys",
|
protocol: "communikeys",
|
||||||
title: displayName,
|
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: {
|
metadata: {
|
||||||
communityPubkey,
|
communityPubkey,
|
||||||
communityRelays,
|
communityRelays,
|
||||||
|
|||||||
Reference in New Issue
Block a user