diff --git a/activity.go b/activity.go index d7accfe..561a338 100644 --- a/activity.go +++ b/activity.go @@ -1186,24 +1186,34 @@ func gimmejonk(xid string) ([]byte, bool) { 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 { diff --git a/docs/changelog.txt b/docs/changelog.txt index 20269c1..6cfd523 100644 --- a/docs/changelog.txt +++ b/docs/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 diff --git a/docs/honk.3 b/docs/honk.3 index c12600e..bfd524d 100644 --- a/docs/honk.3 +++ b/docs/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 diff --git a/toys/Makefile b/toys/Makefile index c2c2f3b..dcf7319 100644 --- a/toys/Makefile +++ b/toys/Makefile @@ -1,5 +1,5 @@ -all: gettoken saytheday youvegothonks +all: gettoken saytheday sprayandpray youvegothonks gettoken: gettoken.go go build gettoken.go @@ -7,5 +7,8 @@ gettoken: gettoken.go saytheday: saytheday.go go build saytheday.go +sprayandpray: sprayandpray.go + go build sprayandpray.go + youvegothonks: youvegothonks.go go build youvegothonks.go diff --git a/toys/README b/toys/README index 9239b9a..6f98c43 100644 --- a/toys/README +++ b/toys/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 diff --git a/toys/sprayandpray.go b/toys/sprayandpray.go new file mode 100644 index 0000000..44ee302 --- /dev/null +++ b/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) +} diff --git a/web.go b/web.go index bdefaec..8389b3f 100644 --- a/web.go +++ b/web.go @@ -2138,6 +2138,7 @@ func honkhonkline() { 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 @@ func apihandler(w http.ResponseWriter, r *http.Request) { 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