From 30e1657d7a0a892aa94aefe05b98670482fd55d7 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Sat, 20 Apr 2019 11:38:16 -0400 Subject: [PATCH] start saving boxes in the db --- activity.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/activity.go b/activity.go index 511467b..2640a5b 100644 --- a/activity.go +++ b/activity.go @@ -302,14 +302,25 @@ func getboxes(ident string) (*Box, error) { 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 { - 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() boxofboxes[ident] = b boxlock.Unlock()