From 0b0d4eaedfe264b7ba885068cffe87d0b42237d8 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Sun, 17 May 2020 21:09:54 -0400 Subject: [PATCH] conclusion of the donks for chonks trilogy --- activity.go | 35 ++++++++++++++++++++++------------- views/chatter.html | 11 +++++++++-- web.go | 9 ++++++++- 3 files changed, 39 insertions(+), 16 deletions(-) diff --git a/activity.go b/activity.go index d6d73c2..b84288f 100644 --- a/activity.go +++ b/activity.go @@ -1030,6 +1030,23 @@ func subsub(user *WhatAbout, xid string, owner string) { deliverate(0, user.ID, owner, j.ToBytes()) } +func activatedonks(donks []*Donk) []junk.Junk { + var atts []junk.Junk + for _, d := range donks { + if re_emus.MatchString(d.Name) { + continue + } + jd := junk.New() + jd["mediaType"] = d.Media + jd["name"] = d.Name + jd["summary"] = html.EscapeString(d.Desc) + jd["type"] = "Document" + jd["url"] = d.URL + atts = append(atts, jd) + } + return atts +} + // returns activity, object func jonkjonk(user *WhatAbout, h *Honk) (junk.Junk, junk.Junk) { dt := h.Date.Format(time.RFC3339) @@ -1173,19 +1190,7 @@ func jonkjonk(user *WhatAbout, h *Honk) (junk.Junk, junk.Junk) { jo["duration"] = "PT" + strings.ToUpper(t.Duration.String()) } } - var atts []junk.Junk - for _, d := range h.Donks { - if re_emus.MatchString(d.Name) { - continue - } - jd := junk.New() - jd["mediaType"] = d.Media - jd["name"] = d.Name - jd["summary"] = html.EscapeString(d.Desc) - jd["type"] = "Document" - jd["url"] = d.URL - atts = append(atts, jd) - } + atts := activatedonks(h.Donks) if len(atts) > 0 { jo["attachment"] = atts } @@ -1300,6 +1305,10 @@ func sendchonk(user *WhatAbout, ch *Chonk) { jo["attributedTo"] = user.URL jo["to"] = aud jo["content"] = ch.HTML + atts := activatedonks(ch.Donks) + if len(atts) > 0 { + jo["attachment"] = atts + } j := junk.New() j["@context"] = itiswhatitis diff --git a/views/chatter.html b/views/chatter.html index 5d53284..c7119fb 100644 --- a/views/chatter.html +++ b/views/chatter.html @@ -2,7 +2,7 @@

-

+

new chatter


@@ -11,6 +11,12 @@

+
{{ $chonkcsrf := .ChonkCSRF }} {{ range .Chatter }} @@ -49,12 +55,13 @@ chatter: {{ .Target }} {{ end }} {{ end }} -
+


+

{{ end }} diff --git a/web.go b/web.go index 14020f4..d9ac26a 100644 --- a/web.go +++ b/web.go @@ -1804,7 +1804,6 @@ func submitchonk(w http.ResponseWriter, r *http.Request) { http.Error(w, "who is that?", http.StatusInternalServerError) return } - ch := Chonk{ UserID: u.UserID, XID: xid, @@ -1814,6 +1813,14 @@ func submitchonk(w http.ResponseWriter, r *http.Request) { Noise: noise, Format: format, } + d, err := submitdonk(w, r) + if err != nil && err != http.ErrMissingFile { + return + } + if d != nil { + ch.Donks = append(ch.Donks, d) + } + filterchonk(&ch) savechonk(&ch) go sendchonk(user, &ch)