show names in following list.

This commit is contained in:
fiatjaf 2020-12-17 13:00:43 -03:00
parent 4ed92f6179
commit 1905355c8a
3 changed files with 49 additions and 36 deletions

View File

@ -4,7 +4,9 @@
<h2>Following</h2>
<ul>
<li v-for="key in $store.state.following">
<a :href="'#/' + key">{{ key }}</a>
<a :href="'#/' + key">
<Name :pubkey="key" />
</a>
</li>
</ul>
</div>

View File

@ -29,6 +29,7 @@
v-if="petnames.length === 0 && !selfGiven"
>{{ abbr }}</span
>
<span v-if="$store.getters.pubKeyHex === pubkey"> (yourself)</span>
</div>
</template>

View File

@ -193,47 +193,57 @@ function listener(store) {
async function listenToRelay(host) {
if (store.state.following.length === 0) return
if (host.length && host[host.length - 1] === '/') host = host.slice(0, -1)
let es = new EventSource(
host + '/listen_events?session=' + store.state.session
)
ess.set(host, es)
es.onerror = err => {
console.log(`${host}/listen_events error`, err)
es.close()
ess.delete(host)
}
es.onopen = () => {
store.commit('gotEventSource')
}
try {
let es = new EventSource(
host + '/listen_events?session=' + store.state.session
)
ess.set(host, es)
// add initial keys
await window.fetch(host + '/request_watch?session=' + store.state.session, {
method: 'POST',
headers: {'content-type': 'application/json'},
body: JSON.stringify({keys: store.state.following})
})
es.onerror = err => {
console.log(`${host}/listen_events error`, err)
es.close()
ess.delete(host)
}
es.onopen = () => {
store.commit('gotEventSource')
}
// handle anything
es.addEventListener('notice', e => {
console.log(e.data)
})
;['p', 'n', 'r'].forEach(context => {
es.addEventListener(context, e => {
store.dispatch('receivedEvent', {
event: JSON.parse(e.data),
context
// add initial keys
await window.fetch(
host + '/request_watch?session=' + store.state.session,
{
method: 'POST',
headers: {'content-type': 'application/json'},
body: JSON.stringify({keys: store.state.following})
}
)
// handle anything
es.addEventListener('notice', e => {
console.log(e.data)
})
;['p', 'n', 'r'].forEach(context => {
es.addEventListener(context, e => {
store.dispatch('receivedEvent', {
event: JSON.parse(e.data),
context
})
})
})
})
// request initial feed
await window.fetch(host + '/request_feed?session=' + store.state.session, {
method: 'POST',
headers: {'content-type': 'application/json'},
body: JSON.stringify({limit: 100})
})
// request initial feed
await window.fetch(
host + '/request_feed?session=' + store.state.session,
{
method: 'POST',
headers: {'content-type': 'application/json'},
body: JSON.stringify({limit: 100})
}
)
} catch (err) {
console.log('error listening to relay:', host)
}
}
}