start saving boxes in the db

This commit is contained in:
Ted Unangst 2019-04-20 11:38:16 -04:00
parent 770e57797e
commit 30e1657d7a
1 changed files with 17 additions and 6 deletions

View File

@ -302,14 +302,25 @@ func getboxes(ident string) (*Box, error) {
return b, nil return b, nil
} }
j, err := GetJunk(ident) db := opendatabase()
row := db.QueryRow("select ibox, obox, sbox from xonkers where xid = ?", ident)
b = &Box{}
err := row.Scan(&b.In, &b.Out, &b.Shared)
if err != nil { if err != nil {
return nil, err j, err := GetJunk(ident)
if err != nil {
return nil, err
}
inbox, _ := jsongetstring(j, "inbox")
outbox, _ := jsongetstring(j, "outbox")
sbox, _ := jsonfindstring(j, []string{"endpoints", "sharedInbox"})
b = &Box{In: inbox, Out: outbox, Shared: sbox}
if inbox != "" {
db.Exec("insert into xonkers (xid, ibox, obox, sbox, pubkey) values (?, ?, ?, ?, ?)",
ident, inbox, outbox, sbox, "")
}
} }
inbox, _ := jsongetstring(j, "inbox")
outbox, _ := jsongetstring(j, "outbox")
sbox, _ := jsonfindstring(j, []string{"endpoints", "sharedInbox"})
b = &Box{In: inbox, Out: outbox, Shared: sbox}
boxlock.Lock() boxlock.Lock()
boxofboxes[ident] = b boxofboxes[ident] = b
boxlock.Unlock() boxlock.Unlock()