keep track of relay publication status for every update and show it.

This commit is contained in:
fiatjaf 2020-11-17 18:58:33 -03:00
parent 299c596a72
commit f80a28c9b0
4 changed files with 63 additions and 18 deletions

View File

@ -1,5 +1,5 @@
<template>
<article>
<article :class="{ours: ours}">
<div class="pubkey">
<a :href="'#/' + pubkey">{{ pubkey }}</a>
</div>
@ -10,6 +10,13 @@
>{{ humanDate(created_at) }}</time
></a
>
<span
v-if="ours"
class="publish-status"
v-for="({time, status}, host) in ($store.state.publishStatus[id] || {})"
>
{{ host }}: {{ status }} @ {{ time }}
</span>
</em>
<div v-if="reference" class="reference">
<Note :note="reference" />
@ -57,6 +64,9 @@
}
}
return rel
},
ours() {
return this.pubkey === this.$store.getters.pubKeyHex
}
},
methods: {
@ -79,11 +89,19 @@
article {
margin: 10px 0;
}
article.ours {
background-color: orange;
}
p {
margin: 0;
padding-left: 20px;
}
.reference {
background-color: 'yellow';
background-color: lightblue;
}
.publish-status {
display: inline-block;
margin-left: 10px;
font-size: 0.5em;
}
</style>

View File

@ -7,5 +7,13 @@ db.version(1).stores({
relays: 'host',
following: 'pubkey',
mynotes: 'id, kind, created_at',
cachedmetadata: 'pubkey'
cachedmetadata: 'pubkey',
publishlog: '++index, id'
})
if (!localStorage.getItem('deleted')) {
db.delete().then(() => {
localStorage.setItem('deleted', '1')
location.reload()
})
}

View File

@ -37,19 +37,27 @@ export function publishEvent(evt, key, hosts) {
.sign(new BigInteger(key, 16), hash, makeRandom32())
.toString('hex')
for (let i = 0; i < hosts.length; i++) {
let host = hosts[i]
hosts.forEach(async host => {
if (host.length && host[host.length - 1] === '/') host = host.slice(0, -1)
window
.fetch(host + '/save_update', {
method: 'POST',
headers: {'content-type': 'application/json'},
body: JSON.stringify(evt)
})
.then(r => {
if (!r.ok) console.log(`failed to publish ${evt} to ${host}`)
})
}
let r = await window.fetch(host + '/save_update', {
method: 'POST',
headers: {'content-type': 'application/json'},
body: JSON.stringify(evt)
})
let publishLogEntry = {
id: evt.id,
time: evt.created_at,
host
}
if (!r.ok) {
console.log(`failed to publish ${evt} to ${host}`)
db.publishlog.put({...publishLogEntry, status: 'failed'})
} else {
db.publishlog.put({...publishLogEntry, status: 'succeeded'})
}
})
return evt
}

View File

@ -14,7 +14,7 @@ export default createStore({
plugins: (process.env.NODE_ENV !== 'production'
? [createLogger()]
: []
).concat([init, listener, relayLoader]),
).concat([init, listener, relayLoader, publishStatusLoader]),
state() {
let relays = [
{
@ -32,13 +32,14 @@ export default createStore({
return {
haveEventSource,
session: new Date().getTime() + '' + Math.round(Math.random() * 100000),
session: null,
relays,
key: makeRandom32().toString('hex'),
following: [],
home: new SortedMap(),
metadata: new LRU({maxSize: 100}),
browsing: new LRU({maxSize: 300})
browsing: new LRU({maxSize: 300}),
publishStatus: {}
}
},
getters: {
@ -150,6 +151,10 @@ export default createStore({
}
break
}
},
updatePublishStatus(state, {id, time, host, status}) {
if (!(id in state.publishStatus)) state.publishStatus[id] = {}
state.publishStatus[id][host] = {time, status}
}
},
actions: {
@ -281,6 +286,12 @@ function relayLoader(store) {
}
}
function publishStatusLoader(store) {
db.publishlog.hook('creating', (_, {id, time, host, status}) => {
store.commit('updatePublishStatus', {id, time, host, status})
})
}
function listener(store) {
var ess = new Map()