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 _, err := stmtZonkIt.Exec(user.ID, x.RID)
279 if err != nil {
280 log.Printf("error eradicating: %s", err)
281 }
282 return
283 }
284 dt := x.Date.UTC().Format(dbtimeformat)
285 aud := strings.Join(x.Audience, " ")
286 whofore := 0
287 if strings.Contains(aud, user.URL) {
288 whofore = 1
289 }
290 res, err := stmtSaveHonk.Exec(x.UserID, x.What, x.Honker, x.XID, x.RID, dt, x.URL, aud,
291 x.Noise, x.Convoy, whofore)
292 if err != nil {
293 log.Printf("err saving xonk: %s", err)
294 return
295 }
296 x.ID, _ = res.LastInsertId()
297 for _, d := range x.Donks {
298 _, err = stmtSaveDonk.Exec(x.ID, d.FileID)
299 if err != nil {
300 log.Printf("err saving donk: %s", err)
301 return
302 }
303 }
304}
305
306type Box struct {
307 In string
308 Out string
309 Shared string
310}
311
312var boxofboxes = make(map[string]*Box)
313var boxlock sync.Mutex
314var boxinglock sync.Mutex
315
316func getboxes(ident string) (*Box, error) {
317 boxlock.Lock()
318 b, ok := boxofboxes[ident]
319 boxlock.Unlock()
320 if ok {
321 return b, nil
322 }
323
324 boxinglock.Lock()
325 defer boxinglock.Unlock()
326
327 boxlock.Lock()
328 b, ok = boxofboxes[ident]
329 boxlock.Unlock()
330 if ok {
331 return b, nil
332 }
333
334 row := stmtGetBoxes.QueryRow(ident)
335 b = &Box{}
336 err := row.Scan(&b.In, &b.Out, &b.Shared)
337 if err != nil {
338 j, err := GetJunk(ident)
339 if err != nil {
340 return nil, err
341 }
342 inbox, _ := jsongetstring(j, "inbox")
343 outbox, _ := jsongetstring(j, "outbox")
344 sbox, _ := jsonfindstring(j, []string{"endpoints", "sharedInbox"})
345 b = &Box{In: inbox, Out: outbox, Shared: sbox}
346 if inbox != "" {
347 _, err = stmtSaveBoxes.Exec(ident, inbox, outbox, sbox, "")
348 if err != nil {
349 log.Printf("error saving boxes: %s", err)
350 }
351 }
352 }
353 boxlock.Lock()
354 boxofboxes[ident] = b
355 boxlock.Unlock()
356 return b, nil
357}
358
359func peeppeep() {
360 user, _ := butwhatabout("htest")
361 honkers := gethonkers(user.ID)
362 for _, f := range honkers {
363 if f.Flavor != "peep" {
364 continue
365 }
366 log.Printf("getting updates: %s", f.XID)
367 box, err := getboxes(f.XID)
368 if err != nil {
369 log.Printf("error getting outbox: %s", err)
370 continue
371 }
372 log.Printf("getting outbox")
373 j, err := GetJunk(box.Out)
374 if err != nil {
375 log.Printf("err: %s", err)
376 continue
377 }
378 t, _ := jsongetstring(j, "type")
379 if t == "OrderedCollection" {
380 items, _ := jsongetarray(j, "orderedItems")
381 if items == nil {
382 page1, _ := jsongetstring(j, "first")
383 j, err = GetJunk(page1)
384 if err != nil {
385 log.Printf("err: %s", err)
386 continue
387 }
388 items, _ = jsongetarray(j, "orderedItems")
389 }
390
391 for _, item := range items {
392 xonk := xonkxonk(user, item)
393 if xonk != nil {
394 savexonk(user, xonk)
395 }
396 }
397 }
398 }
399}
400
401func whosthere(xid string) ([]string, string) {
402 obj, err := GetJunk(xid)
403 if err != nil {
404 log.Printf("error getting remote xonk: %s", err)
405 return nil, ""
406 }
407 convoy, _ := jsongetstring(obj, "context")
408 if convoy == "" {
409 convoy, _ = jsongetstring(obj, "conversation")
410 }
411 return newphone(nil, obj), convoy
412}
413
414func newphone(a []string, obj map[string]interface{}) []string {
415 for _, addr := range []string{"to", "cc", "attributedTo"} {
416 who, _ := jsongetstring(obj, addr)
417 if who != "" {
418 a = append(a, who)
419 }
420 whos, _ := jsongetarray(obj, addr)
421 for _, w := range whos {
422 who, _ := w.(string)
423 if who != "" {
424 a = append(a, who)
425 }
426 }
427 }
428 return a
429}
430
431func xonkxonk(user *WhatAbout, item interface{}) *Honk {
432 depth := 0
433 maxdepth := 4
434 var xonkxonkfn func(item interface{}) *Honk
435
436 saveoneup := func(xid string) {
437 log.Printf("getting oneup: %s", xid)
438 if depth >= maxdepth {
439 log.Printf("in too deep")
440 return
441 }
442 obj, err := GetJunk(xid)
443 if err != nil {
444 log.Printf("error getting oneup: %s", err)
445 return
446 }
447 depth++
448 xonk := xonkxonkfn(obj)
449 if xonk != nil {
450 savexonk(user, xonk)
451 }
452 depth--
453 }
454
455 xonkxonkfn = func(item interface{}) *Honk {
456 // id, _ := jsongetstring(item, "id")
457 what, _ := jsongetstring(item, "type")
458 dt, _ := jsongetstring(item, "published")
459
460 var audience []string
461 var err error
462 var xid, rid, url, content, convoy string
463 var obj map[string]interface{}
464 var ok bool
465 switch what {
466 case "Announce":
467 xid, ok = jsongetstring(item, "object")
468 if ok {
469 if !needxonkid(user, xid) {
470 return nil
471 }
472 log.Printf("getting bonk: %s", xid)
473 obj, err = GetJunk(xid)
474 if err != nil {
475 log.Printf("error regetting: %s", err)
476 }
477 } else {
478 obj, _ = jsongetmap(item, "object")
479 }
480 what = "bonk"
481 case "Create":
482 obj, _ = jsongetmap(item, "object")
483 what = "honk"
484 case "Note":
485 obj = item.(map[string]interface{})
486 what = "honk"
487 case "Delete":
488 obj, _ = jsongetmap(item, "object")
489 rid, _ = jsongetstring(item, "object")
490 what = "eradicate"
491 default:
492 log.Printf("unknown activity: %s", what)
493 return nil
494 }
495
496 var xonk Honk
497 who, _ := jsongetstring(item, "actor")
498 if obj != nil {
499 if who == "" {
500 who, _ = jsongetstring(obj, "attributedTo")
501 }
502 ot, _ := jsongetstring(obj, "type")
503 url, _ = jsongetstring(obj, "url")
504 if ot == "Note" || ot == "Article" {
505 audience = newphone(audience, obj)
506 xid, _ = jsongetstring(obj, "id")
507 content, _ = jsongetstring(obj, "content")
508 summary, _ := jsongetstring(obj, "summary")
509 if !strings.HasPrefix(content, "<p>") {
510 content = "<p>" + content
511 }
512 if summary != "" {
513 content = "<p>summary: " + summary + content
514 }
515 rid, _ = jsongetstring(obj, "inReplyTo")
516 convoy, _ = jsongetstring(obj, "context")
517 if convoy == "" {
518 convoy, _ = jsongetstring(obj, "conversation")
519 }
520 if what == "honk" && rid != "" {
521 what = "tonk"
522 }
523 }
524 if ot == "Tombstone" {
525 rid, _ = jsongetstring(obj, "id")
526 }
527 atts, _ := jsongetarray(obj, "attachment")
528 for i, att := range atts {
529 at, _ := jsongetstring(att, "type")
530 mt, _ := jsongetstring(att, "mediaType")
531 u, _ := jsongetstring(att, "url")
532 name, _ := jsongetstring(att, "name")
533 if i < 4 && (at == "Document" || at == "Image") {
534 mt = strings.ToLower(mt)
535 log.Printf("attachment: %s %s", mt, u)
536 if mt == "image/jpeg" || mt == "image/png" ||
537 mt == "text/plain" {
538 donk := savedonk(u, name, mt)
539 if donk != nil {
540 xonk.Donks = append(xonk.Donks, donk)
541 }
542 } else {
543 u = html.EscapeString(u)
544 content += fmt.Sprintf(
545 `<p>External attachment: <a href="%s" rel=noreferrer>%s</a>`, u, u)
546 }
547 } else {
548 log.Printf("unknown attachment: %s", at)
549 }
550 }
551 tags, _ := jsongetarray(obj, "tag")
552 for _, tag := range tags {
553 tt, _ := jsongetstring(tag, "type")
554 name, _ := jsongetstring(tag, "name")
555 if tt == "Emoji" {
556 icon, _ := jsongetmap(tag, "icon")
557 mt, _ := jsongetstring(icon, "mediaType")
558 if mt == "" {
559 mt = "image/png"
560 }
561 u, _ := jsongetstring(icon, "url")
562 donk := savedonk(u, name, mt)
563 if donk != nil {
564 xonk.Donks = append(xonk.Donks, donk)
565 }
566 }
567 }
568 }
569 audience = append(audience, who)
570
571 audience = oneofakind(audience)
572
573 xonk.UserID = user.ID
574 xonk.What = what
575 xonk.Honker = who
576 xonk.XID = xid
577 xonk.RID = rid
578 xonk.Date, _ = time.Parse(time.RFC3339, dt)
579 xonk.URL = url
580 xonk.Noise = content
581 xonk.Audience = audience
582 xonk.Convoy = convoy
583
584 if needxonk(user, &xonk) {
585 if what == "tonk" {
586 if needxonkid(user, rid) {
587 saveoneup(rid)
588 }
589 }
590 return &xonk
591 }
592 return nil
593 }
594
595 return xonkxonkfn(item)
596}
597
598func rubadubdub(user *WhatAbout, req map[string]interface{}) {
599 xid, _ := jsongetstring(req, "id")
600 reqactor, _ := jsongetstring(req, "actor")
601 j := NewJunk()
602 j["@context"] = itiswhatitis
603 j["id"] = user.URL + "/dub/" + xid
604 j["type"] = "Accept"
605 j["actor"] = user.URL
606 j["to"] = reqactor
607 j["published"] = time.Now().UTC().Format(time.RFC3339)
608 j["object"] = req
609
610 WriteJunk(os.Stdout, j)
611
612 actor, _ := jsongetstring(req, "actor")
613 box, err := getboxes(actor)
614 if err != nil {
615 log.Printf("can't get dub box: %s", err)
616 return
617 }
618 keyname, key := ziggy(user.Name)
619 err = PostJunk(keyname, key, box.In, j)
620 if err != nil {
621 log.Printf("can't rub a dub: %s", err)
622 return
623 }
624 stmtSaveDub.Exec(user.ID, actor, actor, "dub")
625}
626
627func itakeitallback(user *WhatAbout, xid string) error {
628 j := NewJunk()
629 j["@context"] = itiswhatitis
630 j["id"] = user.URL + "/unsub/" + xid
631 j["type"] = "Undo"
632 j["actor"] = user.URL
633 j["to"] = xid
634 f := NewJunk()
635 f["id"] = user.URL + "/sub/" + xid
636 f["type"] = "Follow"
637 f["actor"] = user.URL
638 f["to"] = xid
639 j["object"] = f
640 j["published"] = time.Now().UTC().Format(time.RFC3339)
641
642 box, err := getboxes(xid)
643 if err != nil {
644 return err
645 }
646 keyname, key := ziggy(user.Name)
647 err = PostJunk(keyname, key, box.In, j)
648 if err != nil {
649 return err
650 }
651 return nil
652}
653
654func subsub(user *WhatAbout, xid string) {
655 j := NewJunk()
656 j["@context"] = itiswhatitis
657 j["id"] = user.URL + "/sub/" + xid
658 j["type"] = "Follow"
659 j["actor"] = user.URL
660 j["to"] = xid
661 j["object"] = xid
662 j["published"] = time.Now().UTC().Format(time.RFC3339)
663
664 box, err := getboxes(xid)
665 if err != nil {
666 log.Printf("can't send follow: %s", err)
667 return
668 }
669 WriteJunk(os.Stdout, j)
670 keyname, key := ziggy(user.Name)
671 err = PostJunk(keyname, key, box.In, j)
672 if err != nil {
673 log.Printf("failed to subsub: %s", err)
674 }
675}
676
677func jonkjonk(user *WhatAbout, h *Honk) (map[string]interface{}, map[string]interface{}) {
678 dt := h.Date.Format(time.RFC3339)
679 var jo map[string]interface{}
680 j := NewJunk()
681 j["id"] = user.URL + "/" + h.What + "/" + h.XID
682 j["actor"] = user.URL
683 j["published"] = dt
684 j["to"] = h.Audience[0]
685 if len(h.Audience) > 1 {
686 j["cc"] = h.Audience[1:]
687 }
688
689 switch h.What {
690 case "tonk":
691 fallthrough
692 case "honk":
693 j["type"] = "Create"
694
695 jo = NewJunk()
696 jo["id"] = user.URL + "/h/" + h.XID
697 jo["type"] = "Note"
698 jo["published"] = dt
699 jo["url"] = user.URL + "/h/" + h.XID
700 jo["attributedTo"] = user.URL
701 if h.RID != "" {
702 jo["inReplyTo"] = h.RID
703 }
704 if h.Convoy != "" {
705 jo["context"] = h.Convoy
706 jo["conversation"] = h.Convoy
707 }
708 jo["to"] = h.Audience[0]
709 if len(h.Audience) > 1 {
710 jo["cc"] = h.Audience[1:]
711 }
712 if strings.HasPrefix(h.Noise, "DZ:") {
713 // alas, it's already been turned into html
714 idx := strings.Index(h.Noise, "<br>")
715 if idx == -1 {
716 jo["summary"] = h.Noise
717 jo["content"] = ""
718 } else {
719 jo["summary"] = h.Noise[:idx]
720 if strings.HasPrefix(h.Noise[idx+4:], "<br>") {
721 idx += 4
722 }
723 jo["content"] = mentionize(h.Noise[idx+4:])
724 }
725 jo["sensitive"] = true
726 } else {
727 jo["content"] = mentionize(h.Noise)
728 }
729 var tags []interface{}
730 g := bunchofgrapes(h.Noise)
731 for _, m := range g {
732 t := NewJunk()
733 t["type"] = "Mention"
734 t["name"] = m.who
735 t["href"] = m.where
736 tags = append(tags, t)
737 }
738 herd := herdofemus(h.Noise)
739 for _, e := range herd {
740 t := NewJunk()
741 t["id"] = e.ID
742 t["type"] = "Emoji"
743 t["name"] = e.Name
744 i := NewJunk()
745 i["type"] = "Image"
746 i["mediaType"] = "image/png"
747 i["url"] = e.ID
748 t["icon"] = i
749 tags = append(tags, t)
750 }
751 if len(tags) > 0 {
752 jo["tag"] = tags
753 }
754 var atts []interface{}
755 for _, d := range h.Donks {
756 if re_emus.MatchString(d.Name) {
757 continue
758 }
759 jd := NewJunk()
760 jd["mediaType"] = d.Media
761 jd["name"] = d.Name
762 jd["type"] = "Document"
763 jd["url"] = d.URL
764 atts = append(atts, jd)
765 }
766 if len(atts) > 0 {
767 jo["attachment"] = atts
768 }
769 j["object"] = jo
770 case "bonk":
771 j["type"] = "Announce"
772 j["object"] = h.XID
773 case "zonk":
774 j["type"] = "Delete"
775 j["object"] = user.URL + "/h/" + h.XID
776 }
777
778 return j, jo
779}
780
781func honkworldwide(user *WhatAbout, honk *Honk) {
782 jonk, _ := jonkjonk(user, honk)
783 jonk["@context"] = itiswhatitis
784 var buf bytes.Buffer
785 WriteJunk(&buf, jonk)
786 msg := buf.Bytes()
787
788 rcpts := make(map[string]bool)
789 for _, a := range honk.Audience {
790 if a != thewholeworld && a != user.URL && !strings.HasSuffix(a, "/followers") {
791 box, _ := getboxes(a)
792 if box != nil && box.Shared != "" {
793 rcpts["%"+box.Shared] = true
794 } else {
795 rcpts[a] = true
796 }
797 }
798 }
799 for _, f := range getdubs(user.ID) {
800 box, _ := getboxes(f.XID)
801 if box != nil && box.Shared != "" {
802 rcpts["%"+box.Shared] = true
803 } else {
804 rcpts[f.XID] = true
805 }
806 }
807 for a := range rcpts {
808 go deliverate(0, user.Name, a, msg)
809 }
810}
811
812func asjonker(user *WhatAbout) map[string]interface{} {
813 about := obfusbreak(user.About)
814
815 j := NewJunk()
816 j["@context"] = itiswhatitis
817 j["id"] = user.URL
818 j["type"] = "Person"
819 j["inbox"] = user.URL + "/inbox"
820 j["outbox"] = user.URL + "/outbox"
821 j["followers"] = user.URL + "/followers"
822 j["following"] = user.URL + "/following"
823 j["name"] = user.Display
824 j["preferredUsername"] = user.Name
825 j["summary"] = about
826 j["url"] = user.URL
827 a := NewJunk()
828 a["type"] = "icon"
829 a["mediaType"] = "image/png"
830 a["url"] = fmt.Sprintf("https://%s/a?a=%s", serverName, url.QueryEscape(user.URL))
831 j["icon"] = a
832 k := NewJunk()
833 k["id"] = user.URL + "#key"
834 k["owner"] = user.URL
835 k["publicKeyPem"] = user.Key
836 j["publicKey"] = k
837
838 return j
839}