all repos — honk @ 067b7eb1d16ebbd16267fb8b63511c1c26bd5175

my fork of honk

activity.go (view raw)

  1//
  2// Copyright (c) 2019 Ted Unangst <tedu@tedunangst.com>
  3//
  4// Permission to use, copy, modify, and distribute this software for any
  5// purpose with or without fee is hereby granted, provided that the above
  6// copyright notice and this permission notice appear in all copies.
  7//
  8// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 10// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 11// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 12// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 13// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 14// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 15
 16package main
 17
 18import (
 19	"bytes"
 20	"compress/gzip"
 21	"crypto/rsa"
 22	"database/sql"
 23	"encoding/json"
 24	"fmt"
 25	"html"
 26	"io"
 27	"log"
 28	"net/http"
 29	"net/url"
 30	"os"
 31	"strconv"
 32	"strings"
 33	"sync"
 34	"time"
 35
 36	"humungus.tedunangst.com/r/webs/image"
 37)
 38
 39func NewJunk() map[string]interface{} {
 40	return make(map[string]interface{})
 41}
 42
 43func WriteJunk(w io.Writer, j map[string]interface{}) error {
 44	e := json.NewEncoder(w)
 45	e.SetEscapeHTML(false)
 46	e.SetIndent("", "  ")
 47	err := e.Encode(j)
 48	return err
 49}
 50
 51func ReadJunk(r io.Reader) (map[string]interface{}, error) {
 52	decoder := json.NewDecoder(r)
 53	var j map[string]interface{}
 54	err := decoder.Decode(&j)
 55	if err != nil {
 56		return nil, err
 57	}
 58	return j, nil
 59}
 60
 61var theonetruename = `application/ld+json; profile="https://www.w3.org/ns/activitystreams"`
 62var thefakename = `application/activity+json`
 63var falsenames = []string{
 64	`application/ld+json`,
 65	`application/activity+json`,
 66}
 67var itiswhatitis = "https://www.w3.org/ns/activitystreams"
 68var thewholeworld = "https://www.w3.org/ns/activitystreams#Public"
 69
 70func friendorfoe(ct string) bool {
 71	ct = strings.ToLower(ct)
 72	for _, at := range falsenames {
 73		if strings.HasPrefix(ct, at) {
 74			return true
 75		}
 76	}
 77	return false
 78}
 79
 80func PostJunk(keyname string, key *rsa.PrivateKey, url string, j map[string]interface{}) error {
 81	var buf bytes.Buffer
 82	WriteJunk(&buf, j)
 83	return PostMsg(keyname, key, url, buf.Bytes())
 84}
 85
 86func PostMsg(keyname string, key *rsa.PrivateKey, url string, msg []byte) error {
 87	client := http.DefaultClient
 88	req, err := http.NewRequest("POST", url, bytes.NewReader(msg))
 89	if err != nil {
 90		return err
 91	}
 92	req.Header.Set("Content-Type", theonetruename)
 93	zig(keyname, key, req, msg)
 94	resp, err := client.Do(req)
 95	if err != nil {
 96		return err
 97	}
 98	resp.Body.Close()
 99	switch resp.StatusCode {
100	case 200:
101	case 201:
102	case 202:
103	default:
104		return fmt.Errorf("http post status: %d", resp.StatusCode)
105	}
106	log.Printf("successful post: %s %d", url, resp.StatusCode)
107	return nil
108}
109
110type gzCloser struct {
111	r     *gzip.Reader
112	under io.ReadCloser
113}
114
115func (gz *gzCloser) Read(p []byte) (int, error) {
116	return gz.r.Read(p)
117}
118
119func (gz *gzCloser) Close() error {
120	defer gz.under.Close()
121	return gz.r.Close()
122}
123
124func GetJunk(url string) (map[string]interface{}, error) {
125	client := http.DefaultClient
126	req, err := http.NewRequest("GET", url, nil)
127	if err != nil {
128		return nil, err
129	}
130	at := thefakename
131	if strings.Contains(url, ".well-known/webfinger?resource") {
132		at = "application/jrd+json"
133	}
134	req.Header.Set("Accept", at)
135	req.Header.Set("Accept-Encoding", "gzip")
136	req.Header.Set("User-Agent", "honksnonk/5.0")
137	resp, err := client.Do(req)
138	if err != nil {
139		return nil, err
140	}
141	if resp.StatusCode != 200 {
142		resp.Body.Close()
143		return nil, fmt.Errorf("http get status: %d", resp.StatusCode)
144	}
145	if strings.EqualFold(resp.Header.Get("Content-Encoding"), "gzip") {
146		gz, err := gzip.NewReader(resp.Body)
147		if err != nil {
148			resp.Body.Close()
149			return nil, err
150		}
151		resp.Body = &gzCloser{r: gz, under: resp.Body}
152	}
153	defer resp.Body.Close()
154	j, err := ReadJunk(resp.Body)
155	return j, err
156}
157
158func jsonfindinterface(ii interface{}, keys []string) interface{} {
159	for _, key := range keys {
160		idx, err := strconv.Atoi(key)
161		if err == nil {
162			m := ii.([]interface{})
163			if idx >= len(m) {
164				return nil
165			}
166			ii = m[idx]
167		} else {
168			m := ii.(map[string]interface{})
169			ii = m[key]
170			if ii == nil {
171				return nil
172			}
173		}
174	}
175	return ii
176}
177func jsonfindstring(j interface{}, keys []string) (string, bool) {
178	s, ok := jsonfindinterface(j, keys).(string)
179	return s, ok
180}
181func jsonfindarray(j interface{}, keys []string) ([]interface{}, bool) {
182	a, ok := jsonfindinterface(j, keys).([]interface{})
183	return a, ok
184}
185func jsonfindmap(j interface{}, keys []string) (map[string]interface{}, bool) {
186	m, ok := jsonfindinterface(j, keys).(map[string]interface{})
187	return m, ok
188}
189func jsongetstring(j interface{}, key string) (string, bool) {
190	return jsonfindstring(j, []string{key})
191}
192func jsongetarray(j interface{}, key string) ([]interface{}, bool) {
193	return jsonfindarray(j, []string{key})
194}
195func jsongetmap(j interface{}, key string) (map[string]interface{}, bool) {
196	return jsonfindmap(j, []string{key})
197}
198
199func savedonk(url string, name, media string) *Donk {
200	var donk Donk
201	row := stmtFindFile.QueryRow(url)
202	err := row.Scan(&donk.FileID)
203	if err == nil {
204		return &donk
205	}
206	log.Printf("saving donk: %s", url)
207	if err != nil && err != sql.ErrNoRows {
208		log.Printf("error querying: %s", err)
209	}
210	resp, err := http.Get(url)
211	if err != nil {
212		log.Printf("error fetching %s: %s", url, err)
213		return nil
214	}
215	defer resp.Body.Close()
216	if resp.StatusCode != 200 {
217		return nil
218	}
219	var buf bytes.Buffer
220	io.Copy(&buf, resp.Body)
221
222	xid := xfiltrate()
223
224	data := buf.Bytes()
225	if strings.HasPrefix(media, "image") {
226		img, err := image.Vacuum(&buf)
227		if err != nil {
228			log.Printf("unable to decode image: %s", err)
229			return nil
230		}
231		data = img.Data
232		media = "image/" + img.Format
233	}
234	res, err := stmtSaveFile.Exec(xid, name, url, media, data)
235	if err != nil {
236		log.Printf("error saving file %s: %s", url, err)
237		return nil
238	}
239	donk.FileID, _ = res.LastInsertId()
240	return &donk
241}
242
243func needxonk(user *WhatAbout, x *Honk) bool {
244	if x.What == "eradicate" {
245		return true
246	}
247	if thoudostbitethythumb(user.ID, x.Audience, x.XID) {
248		log.Printf("not saving thumb biter? %s via %s", x.XID, x.Honker)
249		return false
250	}
251	return needxonkid(user, x.XID)
252}
253func needxonkid(user *WhatAbout, xid string) bool {
254	if strings.HasPrefix(xid, user.URL+"/h/") {
255		return false
256	}
257	row := stmtFindXonk.QueryRow(user.ID, xid)
258	var id int64
259	err := row.Scan(&id)
260	if err == nil {
261		return false
262	}
263	if err != sql.ErrNoRows {
264		log.Printf("err querying xonk: %s", err)
265	}
266	return true
267}
268
269func savexonk(user *WhatAbout, x *Honk) {
270	if x.What == "eradicate" {
271		log.Printf("eradicating %s by %s", x.RID, x.Honker)
272		mh := re_unurl.FindStringSubmatch(x.Honker)
273		mr := re_unurl.FindStringSubmatch(x.RID)
274		if len(mh) < 2 || len(mr) < 2 || mh[1] != mr[1] {
275			log.Printf("not deleting owner mismatch")
276			return
277		}
278		xonk := getxonk(user.ID, x.RID)
279		if xonk != nil {
280			stmtZonkDonks.Exec(xonk.ID)
281			_, err := stmtZonkIt.Exec(user.ID, x.RID)
282			if err != nil {
283				log.Printf("error eradicating: %s", err)
284			}
285		}
286		return
287	}
288	dt := x.Date.UTC().Format(dbtimeformat)
289	aud := strings.Join(x.Audience, " ")
290	whofore := 0
291	if strings.Contains(aud, user.URL) {
292		whofore = 1
293	}
294	res, err := stmtSaveHonk.Exec(x.UserID, x.What, x.Honker, x.XID, x.RID, dt, x.URL, aud,
295		x.Noise, x.Convoy, whofore)
296	if err != nil {
297		log.Printf("err saving xonk: %s", err)
298		return
299	}
300	x.ID, _ = res.LastInsertId()
301	for _, d := range x.Donks {
302		_, err = stmtSaveDonk.Exec(x.ID, d.FileID)
303		if err != nil {
304			log.Printf("err saving donk: %s", err)
305			return
306		}
307	}
308}
309
310type Box struct {
311	In     string
312	Out    string
313	Shared string
314}
315
316var boxofboxes = make(map[string]*Box)
317var boxlock sync.Mutex
318var boxinglock sync.Mutex
319
320func getboxes(ident string) (*Box, error) {
321	boxlock.Lock()
322	b, ok := boxofboxes[ident]
323	boxlock.Unlock()
324	if ok {
325		return b, nil
326	}
327
328	boxinglock.Lock()
329	defer boxinglock.Unlock()
330
331	boxlock.Lock()
332	b, ok = boxofboxes[ident]
333	boxlock.Unlock()
334	if ok {
335		return b, nil
336	}
337
338	row := stmtGetBoxes.QueryRow(ident)
339	b = &Box{}
340	err := row.Scan(&b.In, &b.Out, &b.Shared)
341	if err != nil {
342		j, err := GetJunk(ident)
343		if err != nil {
344			return nil, err
345		}
346		inbox, _ := jsongetstring(j, "inbox")
347		outbox, _ := jsongetstring(j, "outbox")
348		sbox, _ := jsonfindstring(j, []string{"endpoints", "sharedInbox"})
349		b = &Box{In: inbox, Out: outbox, Shared: sbox}
350		if inbox != "" {
351			_, err = stmtSaveBoxes.Exec(ident, inbox, outbox, sbox, "")
352			if err != nil {
353				log.Printf("error saving boxes: %s", err)
354			}
355		}
356	}
357	boxlock.Lock()
358	boxofboxes[ident] = b
359	boxlock.Unlock()
360	return b, nil
361}
362
363func peeppeep() {
364	user, _ := butwhatabout("htest")
365	honkers := gethonkers(user.ID)
366	for _, f := range honkers {
367		if f.Flavor != "peep" {
368			continue
369		}
370		log.Printf("getting updates: %s", f.XID)
371		box, err := getboxes(f.XID)
372		if err != nil {
373			log.Printf("error getting outbox: %s", err)
374			continue
375		}
376		log.Printf("getting outbox")
377		j, err := GetJunk(box.Out)
378		if err != nil {
379			log.Printf("err: %s", err)
380			continue
381		}
382		t, _ := jsongetstring(j, "type")
383		if t == "OrderedCollection" {
384			items, _ := jsongetarray(j, "orderedItems")
385			if items == nil {
386				page1, _ := jsongetstring(j, "first")
387				j, err = GetJunk(page1)
388				if err != nil {
389					log.Printf("err: %s", err)
390					continue
391				}
392				items, _ = jsongetarray(j, "orderedItems")
393			}
394
395			for _, item := range items {
396				xonk := xonkxonk(user, item)
397				if xonk != nil {
398					savexonk(user, xonk)
399				}
400			}
401		}
402	}
403}
404
405func whosthere(xid string) ([]string, string) {
406	obj, err := GetJunk(xid)
407	if err != nil {
408		log.Printf("error getting remote xonk: %s", err)
409		return nil, ""
410	}
411	convoy, _ := jsongetstring(obj, "context")
412	if convoy == "" {
413		convoy, _ = jsongetstring(obj, "conversation")
414	}
415	return newphone(nil, obj), convoy
416}
417
418func newphone(a []string, obj map[string]interface{}) []string {
419	for _, addr := range []string{"to", "cc", "attributedTo"} {
420		who, _ := jsongetstring(obj, addr)
421		if who != "" {
422			a = append(a, who)
423		}
424		whos, _ := jsongetarray(obj, addr)
425		for _, w := range whos {
426			who, _ := w.(string)
427			if who != "" {
428				a = append(a, who)
429			}
430		}
431	}
432	return a
433}
434
435func xonkxonk(user *WhatAbout, item interface{}) *Honk {
436	depth := 0
437	maxdepth := 4
438	var xonkxonkfn func(item interface{}) *Honk
439
440	saveoneup := func(xid string) {
441		log.Printf("getting oneup: %s", xid)
442		if depth >= maxdepth {
443			log.Printf("in too deep")
444			return
445		}
446		obj, err := GetJunk(xid)
447		if err != nil {
448			log.Printf("error getting oneup: %s", err)
449			return
450		}
451		depth++
452		xonk := xonkxonkfn(obj)
453		if xonk != nil {
454			savexonk(user, xonk)
455		}
456		depth--
457	}
458
459	xonkxonkfn = func(item interface{}) *Honk {
460		// id, _ := jsongetstring(item, "id")
461		what, _ := jsongetstring(item, "type")
462		dt, _ := jsongetstring(item, "published")
463
464		var audience []string
465		var err error
466		var xid, rid, url, content, convoy string
467		var obj map[string]interface{}
468		var ok bool
469		switch what {
470		case "Announce":
471			xid, ok = jsongetstring(item, "object")
472			if ok {
473				if !needxonkid(user, xid) {
474					return nil
475				}
476				log.Printf("getting bonk: %s", xid)
477				obj, err = GetJunk(xid)
478				if err != nil {
479					log.Printf("error regetting: %s", err)
480				}
481			} else {
482				obj, _ = jsongetmap(item, "object")
483			}
484			what = "bonk"
485		case "Create":
486			obj, _ = jsongetmap(item, "object")
487			what = "honk"
488		case "Note":
489			obj = item.(map[string]interface{})
490			what = "honk"
491		case "Delete":
492			obj, _ = jsongetmap(item, "object")
493			rid, _ = jsongetstring(item, "object")
494			what = "eradicate"
495		default:
496			log.Printf("unknown activity: %s", what)
497			return nil
498		}
499
500		var xonk Honk
501		who, _ := jsongetstring(item, "actor")
502		if obj != nil {
503			if who == "" {
504				who, _ = jsongetstring(obj, "attributedTo")
505			}
506			ot, _ := jsongetstring(obj, "type")
507			url, _ = jsongetstring(obj, "url")
508			if ot == "Note" || ot == "Article" {
509				audience = newphone(audience, obj)
510				xid, _ = jsongetstring(obj, "id")
511				content, _ = jsongetstring(obj, "content")
512				summary, _ := jsongetstring(obj, "summary")
513				if !strings.HasPrefix(content, "<p>") {
514					content = "<p>" + content
515				}
516				if summary != "" {
517					content = "<p>summary: " + summary + content
518				}
519				rid, _ = jsongetstring(obj, "inReplyTo")
520				convoy, _ = jsongetstring(obj, "context")
521				if convoy == "" {
522					convoy, _ = jsongetstring(obj, "conversation")
523				}
524				if what == "honk" && rid != "" {
525					what = "tonk"
526				}
527			}
528			if ot == "Tombstone" {
529				rid, _ = jsongetstring(obj, "id")
530			}
531			atts, _ := jsongetarray(obj, "attachment")
532			for i, att := range atts {
533				at, _ := jsongetstring(att, "type")
534				mt, _ := jsongetstring(att, "mediaType")
535				u, _ := jsongetstring(att, "url")
536				name, _ := jsongetstring(att, "name")
537				if i < 4 && (at == "Document" || at == "Image") {
538					mt = strings.ToLower(mt)
539					log.Printf("attachment: %s %s", mt, u)
540					if mt == "image/jpeg" || mt == "image/png" ||
541						mt == "text/plain" {
542						donk := savedonk(u, name, mt)
543						if donk != nil {
544							xonk.Donks = append(xonk.Donks, donk)
545						}
546					} else {
547						u = html.EscapeString(u)
548						content += fmt.Sprintf(
549							`<p>External attachment: <a href="%s" rel=noreferrer>%s</a>`, u, u)
550					}
551				} else {
552					log.Printf("unknown attachment: %s", at)
553				}
554			}
555			tags, _ := jsongetarray(obj, "tag")
556			for _, tag := range tags {
557				tt, _ := jsongetstring(tag, "type")
558				name, _ := jsongetstring(tag, "name")
559				if tt == "Emoji" {
560					icon, _ := jsongetmap(tag, "icon")
561					mt, _ := jsongetstring(icon, "mediaType")
562					if mt == "" {
563						mt = "image/png"
564					}
565					u, _ := jsongetstring(icon, "url")
566					donk := savedonk(u, name, mt)
567					if donk != nil {
568						xonk.Donks = append(xonk.Donks, donk)
569					}
570				}
571			}
572		}
573		audience = append(audience, who)
574
575		audience = oneofakind(audience)
576
577		xonk.UserID = user.ID
578		xonk.What = what
579		xonk.Honker = who
580		xonk.XID = xid
581		xonk.RID = rid
582		xonk.Date, _ = time.Parse(time.RFC3339, dt)
583		xonk.URL = url
584		xonk.Noise = content
585		xonk.Audience = audience
586		xonk.Convoy = convoy
587
588		if needxonk(user, &xonk) {
589			if what == "tonk" {
590				if needxonkid(user, rid) {
591					saveoneup(rid)
592				}
593			}
594			return &xonk
595		}
596		return nil
597	}
598
599	return xonkxonkfn(item)
600}
601
602func rubadubdub(user *WhatAbout, req map[string]interface{}) {
603	xid, _ := jsongetstring(req, "id")
604	reqactor, _ := jsongetstring(req, "actor")
605	j := NewJunk()
606	j["@context"] = itiswhatitis
607	j["id"] = user.URL + "/dub/" + xid
608	j["type"] = "Accept"
609	j["actor"] = user.URL
610	j["to"] = reqactor
611	j["published"] = time.Now().UTC().Format(time.RFC3339)
612	j["object"] = req
613
614	WriteJunk(os.Stdout, j)
615
616	actor, _ := jsongetstring(req, "actor")
617	box, err := getboxes(actor)
618	if err != nil {
619		log.Printf("can't get dub box: %s", err)
620		return
621	}
622	keyname, key := ziggy(user.Name)
623	err = PostJunk(keyname, key, box.In, j)
624	if err != nil {
625		log.Printf("can't rub a dub: %s", err)
626		return
627	}
628	stmtSaveDub.Exec(user.ID, actor, actor, "dub")
629}
630
631func itakeitallback(user *WhatAbout, xid string) error {
632	j := NewJunk()
633	j["@context"] = itiswhatitis
634	j["id"] = user.URL + "/unsub/" + xid
635	j["type"] = "Undo"
636	j["actor"] = user.URL
637	j["to"] = xid
638	f := NewJunk()
639	f["id"] = user.URL + "/sub/" + xid
640	f["type"] = "Follow"
641	f["actor"] = user.URL
642	f["to"] = xid
643	j["object"] = f
644	j["published"] = time.Now().UTC().Format(time.RFC3339)
645
646	box, err := getboxes(xid)
647	if err != nil {
648		return err
649	}
650	keyname, key := ziggy(user.Name)
651	err = PostJunk(keyname, key, box.In, j)
652	if err != nil {
653		return err
654	}
655	return nil
656}
657
658func subsub(user *WhatAbout, xid string) {
659	j := NewJunk()
660	j["@context"] = itiswhatitis
661	j["id"] = user.URL + "/sub/" + xid
662	j["type"] = "Follow"
663	j["actor"] = user.URL
664	j["to"] = xid
665	j["object"] = xid
666	j["published"] = time.Now().UTC().Format(time.RFC3339)
667
668	box, err := getboxes(xid)
669	if err != nil {
670		log.Printf("can't send follow: %s", err)
671		return
672	}
673	WriteJunk(os.Stdout, j)
674	keyname, key := ziggy(user.Name)
675	err = PostJunk(keyname, key, box.In, j)
676	if err != nil {
677		log.Printf("failed to subsub: %s", err)
678	}
679}
680
681func jonkjonk(user *WhatAbout, h *Honk) (map[string]interface{}, map[string]interface{}) {
682	dt := h.Date.Format(time.RFC3339)
683	var jo map[string]interface{}
684	j := NewJunk()
685	j["id"] = user.URL + "/" + h.What + "/" + h.XID
686	j["actor"] = user.URL
687	j["published"] = dt
688	j["to"] = h.Audience[0]
689	if len(h.Audience) > 1 {
690		j["cc"] = h.Audience[1:]
691	}
692
693	switch h.What {
694	case "tonk":
695		fallthrough
696	case "honk":
697		j["type"] = "Create"
698
699		jo = NewJunk()
700		jo["id"] = user.URL + "/h/" + h.XID
701		jo["type"] = "Note"
702		jo["published"] = dt
703		jo["url"] = user.URL + "/h/" + h.XID
704		jo["attributedTo"] = user.URL
705		if h.RID != "" {
706			jo["inReplyTo"] = h.RID
707		}
708		if h.Convoy != "" {
709			jo["context"] = h.Convoy
710			jo["conversation"] = h.Convoy
711		}
712		jo["to"] = h.Audience[0]
713		if len(h.Audience) > 1 {
714			jo["cc"] = h.Audience[1:]
715		}
716		if strings.HasPrefix(h.Noise, "DZ:") {
717			// alas, it's already been turned into html
718			idx := strings.Index(h.Noise, "<br>")
719			if idx == -1 {
720				jo["summary"] = h.Noise
721				jo["content"] = ""
722			} else {
723				jo["summary"] = h.Noise[:idx]
724				if strings.HasPrefix(h.Noise[idx+4:], "<br>") {
725					idx += 4
726				}
727				jo["content"] = mentionize(h.Noise[idx+4:])
728			}
729			jo["sensitive"] = true
730		} else {
731			jo["content"] = mentionize(h.Noise)
732		}
733		var tags []interface{}
734		g := bunchofgrapes(h.Noise)
735		for _, m := range g {
736			t := NewJunk()
737			t["type"] = "Mention"
738			t["name"] = m.who
739			t["href"] = m.where
740			tags = append(tags, t)
741		}
742		herd := herdofemus(h.Noise)
743		for _, e := range herd {
744			t := NewJunk()
745			t["id"] = e.ID
746			t["type"] = "Emoji"
747			t["name"] = e.Name
748			i := NewJunk()
749			i["type"] = "Image"
750			i["mediaType"] = "image/png"
751			i["url"] = e.ID
752			t["icon"] = i
753			tags = append(tags, t)
754		}
755		if len(tags) > 0 {
756			jo["tag"] = tags
757		}
758		var atts []interface{}
759		for _, d := range h.Donks {
760			if re_emus.MatchString(d.Name) {
761				continue
762			}
763			jd := NewJunk()
764			jd["mediaType"] = d.Media
765			jd["name"] = d.Name
766			jd["type"] = "Document"
767			jd["url"] = d.URL
768			atts = append(atts, jd)
769		}
770		if len(atts) > 0 {
771			jo["attachment"] = atts
772		}
773		j["object"] = jo
774	case "bonk":
775		j["type"] = "Announce"
776		j["object"] = h.XID
777	case "zonk":
778		j["type"] = "Delete"
779		j["object"] = user.URL + "/h/" + h.XID
780	}
781
782	return j, jo
783}
784
785func honkworldwide(user *WhatAbout, honk *Honk) {
786	jonk, _ := jonkjonk(user, honk)
787	jonk["@context"] = itiswhatitis
788	var buf bytes.Buffer
789	WriteJunk(&buf, jonk)
790	msg := buf.Bytes()
791
792	rcpts := make(map[string]bool)
793	for _, a := range honk.Audience {
794		if a != thewholeworld && a != user.URL && !strings.HasSuffix(a, "/followers") {
795			box, _ := getboxes(a)
796			if box != nil && box.Shared != "" {
797				rcpts["%"+box.Shared] = true
798			} else {
799				rcpts[a] = true
800			}
801		}
802	}
803	for _, f := range getdubs(user.ID) {
804		box, _ := getboxes(f.XID)
805		if box != nil && box.Shared != "" {
806			rcpts["%"+box.Shared] = true
807		} else {
808			rcpts[f.XID] = true
809		}
810	}
811	for a := range rcpts {
812		go deliverate(0, user.Name, a, msg)
813	}
814}
815
816func asjonker(user *WhatAbout) map[string]interface{} {
817	about := obfusbreak(user.About)
818
819	j := NewJunk()
820	j["@context"] = itiswhatitis
821	j["id"] = user.URL
822	j["type"] = "Person"
823	j["inbox"] = user.URL + "/inbox"
824	j["outbox"] = user.URL + "/outbox"
825	j["followers"] = user.URL + "/followers"
826	j["following"] = user.URL + "/following"
827	j["name"] = user.Display
828	j["preferredUsername"] = user.Name
829	j["summary"] = about
830	j["url"] = user.URL
831	a := NewJunk()
832	a["type"] = "icon"
833	a["mediaType"] = "image/png"
834	a["url"] = fmt.Sprintf("https://%s/a?a=%s", serverName, url.QueryEscape(user.URL))
835	j["icon"] = a
836	k := NewJunk()
837	k["id"] = user.URL + "#key"
838	k["owner"] = user.URL
839	k["publicKeyPem"] = user.Key
840	j["publicKey"] = k
841
842	return j
843}