mirror of
https://github.com/coracle-social/coracle.git
synced 2024-09-29 16:31:04 +00:00
Add relay hints to channels
This commit is contained in:
parent
4349864065
commit
cefe7ae890
@ -24,6 +24,8 @@ export default ({keys, sync, getCmd, getUserWriteRelays}) => {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const getHints = e => pluck("url", Tags.from(e).relays())
|
||||||
|
|
||||||
sync.addHandler(40, e => {
|
sync.addHandler(40, e => {
|
||||||
const channel = channels.get(e.id)
|
const channel = channels.get(e.id)
|
||||||
|
|
||||||
@ -42,6 +44,7 @@ export default ({keys, sync, getCmd, getUserWriteRelays}) => {
|
|||||||
type: "public",
|
type: "public",
|
||||||
pubkey: e.pubkey,
|
pubkey: e.pubkey,
|
||||||
updated_at: e.created_at,
|
updated_at: e.created_at,
|
||||||
|
hints: getHints(e),
|
||||||
...content,
|
...content,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -69,13 +72,12 @@ export default ({keys, sync, getCmd, getUserWriteRelays}) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('=========', e)
|
|
||||||
|
|
||||||
channels.patch({
|
channels.patch({
|
||||||
id: channelId,
|
id: channelId,
|
||||||
type: "public",
|
type: "public",
|
||||||
pubkey: e.pubkey,
|
pubkey: e.pubkey,
|
||||||
updated_at: e.created_at,
|
updated_at: e.created_at,
|
||||||
|
hints: getHints(e),
|
||||||
...content,
|
...content,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -153,16 +155,22 @@ export default ({keys, sync, getCmd, getUserWriteRelays}) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (keys.getPubkey() === author) {
|
if (keys.getPubkey() === author) {
|
||||||
|
const channel = channels.get(recipient)
|
||||||
|
|
||||||
channels.patch({
|
channels.patch({
|
||||||
id: recipient,
|
id: recipient,
|
||||||
type: "private",
|
type: "private",
|
||||||
last_sent: e.created_at,
|
last_sent: e.created_at,
|
||||||
|
hints: uniq(getHints(e).concat(channel?.hints || [])),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
const channel = channels.get(author)
|
||||||
|
|
||||||
channels.patch({
|
channels.patch({
|
||||||
id: author,
|
id: author,
|
||||||
type: "private",
|
type: "private",
|
||||||
last_received: e.created_at,
|
last_received: e.created_at,
|
||||||
|
hints: uniq(getHints(e).concat(channel?.hints || [])),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -173,7 +181,10 @@ export default ({keys, sync, getCmd, getUserWriteRelays}) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const channelId = Tags.from(e).getMeta("e")
|
const tags = Tags.from(e)
|
||||||
|
const channelId = tags.getMeta("e")
|
||||||
|
const channel = channels.get(channelId)
|
||||||
|
const hints = uniq(pluck("url", tags.relays()).concat(channel?.hints || []))
|
||||||
|
|
||||||
messages.patch({
|
messages.patch({
|
||||||
id: e.id,
|
id: e.id,
|
||||||
@ -189,12 +200,14 @@ export default ({keys, sync, getCmd, getUserWriteRelays}) => {
|
|||||||
id: channelId,
|
id: channelId,
|
||||||
type: "public",
|
type: "public",
|
||||||
last_sent: e.created_at,
|
last_sent: e.created_at,
|
||||||
|
hints,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
channels.patch({
|
channels.patch({
|
||||||
id: channelId,
|
id: channelId,
|
||||||
type: "public",
|
type: "public",
|
||||||
last_received: e.created_at,
|
last_received: e.created_at,
|
||||||
|
hints,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user