all repos — honk @ ccc6b5a9de02e7af2cda8749f6b76296bb48c448

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