feat: add support for commenting and reacting on external content
This commit is contained in:
@@ -98,11 +98,11 @@ class ClientService extends EventTarget {
|
||||
}
|
||||
}
|
||||
|
||||
let relays: string[]
|
||||
const relaySet = new Set<string>()
|
||||
if (specifiedRelayUrls?.length) {
|
||||
relays = specifiedRelayUrls
|
||||
specifiedRelayUrls.forEach((url) => relaySet.add(url))
|
||||
} else {
|
||||
const _additionalRelayUrls: string[] = additionalRelayUrls ?? []
|
||||
additionalRelayUrls?.forEach((url) => relaySet.add(url))
|
||||
if (!specifiedRelayUrls?.length && ![kinds.Contacts, kinds.Mutelist].includes(event.kind)) {
|
||||
const mentions: string[] = []
|
||||
event.tags.forEach(([tagName, tagValue]) => {
|
||||
@@ -118,10 +118,14 @@ class ClientService extends EventTarget {
|
||||
if (mentions.length > 0) {
|
||||
const relayLists = await this.fetchRelayLists(mentions)
|
||||
relayLists.forEach((relayList) => {
|
||||
_additionalRelayUrls.push(...relayList.read.slice(0, 4))
|
||||
relayList.read.slice(0, 4).forEach((url) => relaySet.add(url))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const relayList = await this.fetchRelayList(event.pubkey)
|
||||
relayList.write.forEach((url) => relaySet.add(url))
|
||||
|
||||
if (
|
||||
[
|
||||
kinds.RelayList,
|
||||
@@ -131,20 +135,23 @@ class ClientService extends EventTarget {
|
||||
ExtendedKind.RELAY_REVIEW
|
||||
].includes(event.kind)
|
||||
) {
|
||||
_additionalRelayUrls.push(...BIG_RELAY_URLS)
|
||||
BIG_RELAY_URLS.forEach((url) => relaySet.add(url))
|
||||
}
|
||||
|
||||
const relayList = await this.fetchRelayList(event.pubkey)
|
||||
relays = (relayList?.write.slice(0, 10) ?? []).concat(
|
||||
Array.from(new Set(_additionalRelayUrls)) ?? []
|
||||
)
|
||||
if (event.kind === ExtendedKind.COMMENT) {
|
||||
const rootITag = event.tags.find(tagNameEquals('I'))
|
||||
if (rootITag) {
|
||||
// For external content comments, always publish to big relays
|
||||
BIG_RELAY_URLS.forEach((url) => relaySet.add(url))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!relays.length) {
|
||||
relays.push(...BIG_RELAY_URLS)
|
||||
if (!relaySet.size) {
|
||||
BIG_RELAY_URLS.forEach((url) => relaySet.add(url))
|
||||
}
|
||||
|
||||
return relays
|
||||
return Array.from(relaySet)
|
||||
}
|
||||
|
||||
async publishEvent(relayUrls: string[], event: NEvent) {
|
||||
|
||||
Reference in New Issue
Block a user