all repos — honk @ 7c24aac3d0f284da536834b968e6463f857d7ada

my fork of honk

add a raw sendactivity API action
Ted Unangst tedu@tedunangst.com
Tue, 26 Nov 2019 14:57:23 -0500
commit

7c24aac3d0f284da536834b968e6463f857d7ada

parent

445e7abe81ab0dcc331b21c09fb130b311d0b40c

7 files changed, 108 insertions(+), 10 deletions(-)

jump to
M activity.goactivity.go

@@ -1186,24 +1186,34 @@ ok := oldjonks.Get(xid, &j)

return j, ok } -func honkworldwide(user *WhatAbout, honk *Honk) { - jonk, _ := jonkjonk(user, honk) - jonk["@context"] = itiswhatitis - msg := jonk.ToBytes() - +func boxuprcpts(user *WhatAbout, addresses []string, useshared bool) map[string]bool { rcpts := make(map[string]bool) - for _, a := range honk.Audience { - if a == thewholeworld || a == user.URL || strings.HasSuffix(a, "/followers") { + for _, a := range addresses { + if a == "" || a == thewholeworld || a == user.URL || strings.HasSuffix(a, "/followers") { + continue + } + if a[0] == '%' { + rcpts[a] = true continue } var box *Box ok := boxofboxes.Get(a, &box) - if ok && honk.Public && box.Shared != "" { + if ok && useshared && box.Shared != "" { rcpts["%"+box.Shared] = true } else { rcpts[a] = true } } + return rcpts +} + +func honkworldwide(user *WhatAbout, honk *Honk) { + jonk, _ := jonkjonk(user, honk) + jonk["@context"] = itiswhatitis + msg := jonk.ToBytes() + + rcpts := boxuprcpts(user, honk.Audience, honk.Public) + if honk.Public { for _, h := range getdubs(user.ID) { if h.XID == user.URL {
M docs/changelog.txtdocs/changelog.txt

@@ -2,6 +2,8 @@ changelog

-- next ++ A raw sendactivity API action for the bold. + + More flexible meme names. -- 0.8.5 Turnkey Blaster
M docs/honk.3docs/honk.3

@@ -109,6 +109,20 @@ If there are no results, wait this many seconds for something to appear.

.El .Pp The result will be returned as json. +.Ss sendactivity +Send anything. +No limits, no error checking. +.Bl -tag -width public +.It Fa rcpt +An actor to deliver the message to to. +May be specified more than once. +An inbox may be specified directly by prefixing with %. +.It Fa msg +The message. +It should be a valid json activity, but yolo. +.It Fa public +Set to 1 to use shared inboxes for delivery. +.El .Sh EXAMPLES Refer to the sample code in the .Pa toys
M toys/Makefiletoys/Makefile

@@ -1,11 +1,14 @@

-all: gettoken saytheday youvegothonks +all: gettoken saytheday sprayandpray youvegothonks gettoken: gettoken.go go build gettoken.go saytheday: saytheday.go go build saytheday.go + +sprayandpray: sprayandpray.go + go build sprayandpray.go youvegothonks: youvegothonks.go go build youvegothonks.go
M toys/READMEtoys/README

@@ -4,6 +4,8 @@ A little of this, a little of that.

gettoken.go - obtains an authorization token -saytheday.go - posts a new honk +saytheday.go - posts a new honk that's a date based look and say sequence + +sprayandpray.go - send an activity with no error checking and hope it works youvegothonks.go - polls for new mesages
A toys/sprayandpray.go

@@ -0,0 +1,59 @@

+package main + +import ( + "flag" + "fmt" + "io/ioutil" + "log" + "net/http" + "net/url" + "os" + "strings" +) + + +func sendmsg(server, token, msg, rcpt string) { + form := make(url.Values) + form.Add("token", token) + form.Add("action", "sendactivity") + form.Add("msg", msg) + form.Add("rcpt", rcpt) + apiurl := fmt.Sprintf("https://%s/api", server) + req, err := http.NewRequest("POST", apiurl, strings.NewReader(form.Encode())) + if err != nil { + log.Fatal(err) + } + req.Header.Add("Content-Type", "application/x-www-form-urlencoded") + resp, err := http.DefaultClient.Do(req) + if err != nil { + log.Fatal(err) + } + defer resp.Body.Close() + answer, err := ioutil.ReadAll(resp.Body) + if err != nil { + log.Fatal(err) + } + if resp.StatusCode != 200 { + log.Fatalf("status: %d: %s", resp.StatusCode, answer) + } +} + +func main() { + var server, token, msgfile, rcpt string + flag.StringVar(&server, "server", server, "server to connnect") + flag.StringVar(&token, "token", token, "auth token to use") + flag.StringVar(&msgfile, "msgfile", token, "file with message to send") + flag.StringVar(&rcpt, "rcpt", rcpt, "rcpt to send it to") + flag.Parse() + + if server == "" || token == "" || msgfile == "" || rcpt == "" { + flag.Usage() + os.Exit(1) + } + msg, err := ioutil.ReadFile(msgfile) + if err != nil { + log.Fatal(err) + } + + sendmsg(server, token, string(msg), rcpt) +}
M web.goweb.go

@@ -2138,6 +2138,7 @@

func apihandler(w http.ResponseWriter, r *http.Request) { u := login.GetUserInfo(r) userid := u.UserID + user, _ := butwhatabout(u.Username) action := r.FormValue("action") wait, _ := strconv.ParseInt(r.FormValue("wait"), 10, 0) log.Printf("api request '%s' on behalf of %s", action, u.Username)

@@ -2175,6 +2176,13 @@ reverbolate(userid, honks)

j := junk.New() j["honks"] = honks j.Write(w) + case "sendactivity": + public := r.FormValue("public") == "1" + rcpts := boxuprcpts(user, r.Form["rcpt"], public) + msg := []byte(r.FormValue("msg")) + for rcpt := range rcpts { + go deliverate(0, userid, rcpt, msg) + } default: http.Error(w, "unknown action", http.StatusNotFound) return