diff --git a/database.go b/database.go index 3696c35..262510c 100644 --- a/database.go +++ b/database.go @@ -798,6 +798,20 @@ func saveextras(tx *sql.Tx, h *Honk) error { return nil } +func addreaction(user *WhatAbout, xid string, who, react string) { + h := getxonk(user.ID, xid) + if h == nil { + return + } + h.Badonks = append(h.Badonks, Badonk{Who: who, What: react}) + j, _ := jsonify(h.Badonks) + db := opendatabase() + tx, _ := db.Begin() + _, _ = tx.Stmt(stmtDeleteOneMeta).Exec(h.ID, "badonks") + _, _ = tx.Stmt(stmtSaveMeta).Exec(h.ID, "badonks", j) + tx.Commit() +} + func deleteextras(tx *sql.Tx, honkid int64, everything bool) error { _, err := tx.Stmt(stmtDeleteDonks).Exec(honkid) if err != nil { @@ -914,7 +928,7 @@ var stmtUntagged, stmtDeleteHonk, stmtDeleteDonks, stmtDeleteOnts, stmtSaveZonke var stmtGetZonkers, stmtRecentHonkers, stmtGetXonker, stmtSaveXonker, stmtDeleteXonker *sql.Stmt var stmtAllOnts, stmtSaveOnt, stmtUpdateFlags, stmtClearFlags *sql.Stmt var stmtHonksForUserFirstClass *sql.Stmt -var stmtSaveMeta, stmtDeleteAllMeta, stmtDeleteSomeMeta, stmtUpdateHonk *sql.Stmt +var stmtSaveMeta, stmtDeleteAllMeta, stmtDeleteOneMeta, stmtDeleteSomeMeta, stmtUpdateHonk *sql.Stmt var stmtHonksISaved, stmtGetFilters, stmtSaveFilter, stmtDeleteFilter *sql.Stmt var stmtGetTracks *sql.Stmt var stmtSaveChonk, stmtLoadChonks, stmtGetChatters *sql.Stmt @@ -962,6 +976,7 @@ func prepareStatements(db *sql.DB) { stmtSaveMeta = preparetodie(db, "insert into honkmeta (honkid, genus, json) values (?, ?, ?)") stmtDeleteAllMeta = preparetodie(db, "delete from honkmeta where honkid = ?") stmtDeleteSomeMeta = preparetodie(db, "delete from honkmeta where honkid = ? and genus not in ('oldrev')") + stmtDeleteOneMeta = preparetodie(db, "delete from honkmeta where honkid = ? and genus = ?") stmtSaveHonk = preparetodie(db, "insert into honks (userid, what, honker, xid, rid, dt, url, audience, noise, convoy, whofore, format, precis, oonker, flags) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") stmtDeleteHonk = preparetodie(db, "delete from honks where honkid = ?") stmtUpdateHonk = preparetodie(db, "update honks set precis = ?, noise = ?, format = ?, whofore = ?, dt = ? where honkid = ?") diff --git a/honk.go b/honk.go index 663725d..a2304c8 100644 --- a/honk.go +++ b/honk.go @@ -96,6 +96,12 @@ type Honk struct { Place *Place Time *Time Mentions []Mention + Badonks []Badonk +} + +type Badonk struct { + Who string + What string } type Chonk struct { diff --git a/web.go b/web.go index 09e1547..0318696 100644 --- a/web.go +++ b/web.go @@ -429,6 +429,12 @@ func inbox(w http.ResponseWriter, r *http.Request) { default: log.Printf("unknown undo: %s", what) } + case "EmojiReact": + obj, ok := j.GetString("object") + if ok { + content, _ := j.GetString("content") + addreaction(user, obj, who, content) + } default: go xonksaver(user, j, origin) }