a little more flexibility in api

This commit is contained in:
Ted Unangst 2020-04-26 15:03:23 -04:00
parent 12183bb0f7
commit d121a83b54
2 changed files with 56 additions and 9 deletions

View File

@ -123,6 +123,41 @@ If there are no results, wait this many seconds for something to appear.
.El .El
.Pp .Pp
The result will be returned as json. The result will be returned as json.
.Ss zonkit
The
.Dq zonkit
action began life as a delete function, but has since evolved some other
powers as specified by the
.Fa wherefore
parameter.
The target of the action is specified by the
.Fa what
parameter and is generally the XID of a honk.
.Pp
Wherefore must be one of the following.
.Bl -tag -width zonvoy
.It bonk
Share honk with others.
.It unbonk
Undo share.
.It save
Mark honk as saved.
.It unsave
Unmark honk as saved.
.It react
Post an emoji reaction.
A custom reaction may be specified with
.Fa reaction .
.It ack
Mark honk as read.
.It deack
Unmark honk as read.
.It zonk
Delete this honk.
.It zonvoy
Mute this thread.
What should identify a convoy.
.El
.Ss sendactivity .Ss sendactivity
Send anything. Send anything.
No limits, no error checking. No limits, no error checking.

30
web.go
View File

@ -1163,14 +1163,10 @@ func saveuser(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/account", http.StatusSeeOther) http.Redirect(w, r, "/account", http.StatusSeeOther)
} }
func submitbonk(w http.ResponseWriter, r *http.Request) { func bonkit(xid string, user *WhatAbout) {
xid := r.FormValue("xid")
userinfo := login.GetUserInfo(r)
user, _ := butwhatabout(userinfo.Username)
log.Printf("bonking %s", xid) log.Printf("bonking %s", xid)
xonk := getxonk(userinfo.UserID, xid) xonk := getxonk(user.ID, xid)
if xonk == nil { if xonk == nil {
return return
} }
@ -1193,8 +1189,8 @@ func submitbonk(w http.ResponseWriter, r *http.Request) {
} }
dt := time.Now().UTC() dt := time.Now().UTC()
bonk := &Honk{ bonk := &Honk{
UserID: userinfo.UserID, UserID: user.ID,
Username: userinfo.Username, Username: user.Name,
What: "bonk", What: "bonk",
Honker: user.URL, Honker: user.URL,
Oonker: oonker, Oonker: oonker,
@ -1222,11 +1218,19 @@ func submitbonk(w http.ResponseWriter, r *http.Request) {
} }
go honkworldwide(user, bonk) go honkworldwide(user, bonk)
}
func submitbonk(w http.ResponseWriter, r *http.Request) {
xid := r.FormValue("xid")
userinfo := login.GetUserInfo(r)
user, _ := butwhatabout(userinfo.Username)
bonkit(xid, user)
if r.FormValue("js") != "1" { if r.FormValue("js") != "1" {
templinfo := getInfo(r) templinfo := getInfo(r)
templinfo["ServerMessage"] = "Bonked!" templinfo["ServerMessage"] = "Bonked!"
err = readviews.Execute(w, "msg.html", templinfo) err := readviews.Execute(w, "msg.html", templinfo)
if err != nil { if err != nil {
log.Print(err) log.Print(err)
} }
@ -1321,6 +1325,12 @@ func zonkit(w http.ResponseWriter, r *http.Request) {
return return
} }
if wherefore == "bonk" {
user, _ := butwhatabout(userinfo.Username)
bonkit(what, user)
return
}
if wherefore == "unbonk" { if wherefore == "unbonk" {
xonk := getbonk(userinfo.UserID, what) xonk := getbonk(userinfo.UserID, what)
if xonk != nil { if xonk != nil {
@ -2237,6 +2247,8 @@ func apihandler(w http.ResponseWriter, r *http.Request) {
return return
} }
w.Write([]byte(d.XID)) w.Write([]byte(d.XID))
case "zonkit":
zonkit(w, r)
case "gethonks": case "gethonks":
var honks []*Honk var honks []*Honk
wanted, _ := strconv.ParseInt(r.FormValue("after"), 10, 0) wanted, _ := strconv.ParseInt(r.FormValue("after"), 10, 0)