relay and web-client working.
except for the fact that this websocket is short-lived and keeps dying.
This commit is contained in:
parent
b04a38b20a
commit
5c134a71cc
|
@ -4,6 +4,7 @@ import (
|
|||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/fiatjaf/schnorr"
|
||||
|
@ -24,11 +25,29 @@ type Event struct {
|
|||
|
||||
Kind uint8 `db:"kind" json:"kind"`
|
||||
|
||||
Tags []Tag `db:"tag" json:"tags"`
|
||||
Tags Tags `db:"tags" json:"tags"`
|
||||
Content string `db:"content" json:"content"`
|
||||
Sig string `db:"sig" json:"sig"`
|
||||
}
|
||||
|
||||
type Tags []Tag
|
||||
|
||||
func (t Tags) Scan(src interface{}) error {
|
||||
var jtags []byte = make([]byte, 0)
|
||||
|
||||
switch v := src.(type) {
|
||||
case []byte:
|
||||
jtags = v
|
||||
case string:
|
||||
jtags = []byte(v)
|
||||
default:
|
||||
return errors.New("couldn't scan tags, it's not a json string")
|
||||
}
|
||||
|
||||
json.Unmarshal(jtags, t)
|
||||
return nil
|
||||
}
|
||||
|
||||
type Tag []interface{}
|
||||
|
||||
// Serialize outputs a byte array that can be hashed/signed to identify/authenticate
|
||||
|
@ -50,7 +69,11 @@ func (evt *Event) Serialize() []byte {
|
|||
arr[3] = int64(evt.Kind)
|
||||
|
||||
// tags
|
||||
arr[4] = evt.Tags
|
||||
if evt.Tags != nil {
|
||||
arr[4] = evt.Tags
|
||||
} else {
|
||||
arr[4] = make([]bool, 0)
|
||||
}
|
||||
|
||||
// content
|
||||
arr[5] = evt.Content
|
||||
|
|
|
@ -9,6 +9,7 @@ require (
|
|||
github.com/gorilla/websocket v1.4.2
|
||||
github.com/jmoiron/sqlx v1.2.0
|
||||
github.com/kelseyhightower/envconfig v1.4.0
|
||||
github.com/kr/pretty v0.2.1
|
||||
github.com/lib/pq v1.8.0
|
||||
github.com/mattn/go-sqlite3 v1.14.4
|
||||
github.com/rs/cors v1.7.0
|
||||
|
|
|
@ -36,6 +36,11 @@ github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dv
|
|||
github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
|
||||
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
|
||||
github.com/kkdai/bstream v0.0.0-20181106074824-b3251f7901ec/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
|
||||
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
|
||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/lib/pq v1.8.0 h1:9xohqzkUwzR4Ga4ivdTcawVS89YSDVxXMa3xJX3cGzg=
|
||||
github.com/lib/pq v1.8.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
|
|
|
@ -16,7 +16,10 @@ db.relays
|
|||
.then(() => db.relays.toArray())
|
||||
.then(relays => {
|
||||
relays.forEach(({host, policy}) => {
|
||||
pool.addRelay(host, parsePolicy(policy))
|
||||
let relay = pool.addRelay(host, parsePolicy(policy))
|
||||
setTimeout(() => {
|
||||
relay.reqFeed()
|
||||
}, 1)
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -24,7 +27,7 @@ export function relayStorePlugin(store) {
|
|||
store.subscribe(mutation => {
|
||||
switch (mutation.type) {
|
||||
case 'setInit':
|
||||
mutation.payload.following.forEach(key => {
|
||||
store.state.following.forEach(key => {
|
||||
pool.subKey(key)
|
||||
})
|
||||
break
|
||||
|
@ -38,7 +41,7 @@ export function relayStorePlugin(store) {
|
|||
})
|
||||
|
||||
// setup event listener
|
||||
pool.onEvent(async (context, event, {url: relayURL}) => {
|
||||
pool.onEvent(async (event, context, {url: relayURL}) => {
|
||||
store.dispatch('receivedEvent', {event, context})
|
||||
|
||||
// is this our note? mark it as published on this relay
|
||||
|
@ -61,9 +64,4 @@ export function relayStorePlugin(store) {
|
|||
status
|
||||
})
|
||||
})
|
||||
|
||||
// request initial feed
|
||||
setTimeout(() => {
|
||||
pool.reqFeed()
|
||||
}, 1)
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ export default createStore({
|
|||
plugins: (process.env.NODE_ENV !== 'production'
|
||||
? [createLogger()]
|
||||
: []
|
||||
).concat([init, relayStorePlugin, publishStatusLoader]),
|
||||
).concat([relayStorePlugin, init, publishStatusLoader]),
|
||||
state() {
|
||||
let secretKey = localStorage.getItem('key')
|
||||
if (!secretKey) {
|
||||
|
|
Loading…
Reference in New Issue