all repos — honk @ 6a23f35877106f3ed8fb743429b58bbc16c613c4

my fork of honk

conclusion of the donks for chonks trilogy
Ted Unangst tedu@tedunangst.com
Sun, 17 May 2020 21:09:54 -0400
commit

6a23f35877106f3ed8fb743429b58bbc16c613c4

parent

31e533b9bc375f7e307d01b898f0dde25e2e33e8

3 files changed, 39 insertions(+), 16 deletions(-)

jump to
M activity.goactivity.go

@@ -1030,6 +1030,23 @@

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 @@ if t.Duration != 0 {

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 @@ jo["published"] = dt

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
M views/chatter.htmlviews/chatter.html

@@ -2,7 +2,7 @@ {{ template "header.html" . }}

<main> <div class="info"> <p> -<form action="/sendchonk" method="POST"> +<form action="/sendchonk" method="POST" enctype="multipart/form-data"> <h3>new chatter</h3> <input type="hidden" name="CSRF" value="{{ .ChonkCSRF }}"> <p><label for=target>target:</label><br>

@@ -11,6 +11,12 @@ <p><label for=noise>noise:</label><br>

<textarea name="noise" id="noise"></textarea> <p><button name="chonk" value="chonk">chonk</button> </form> +<script> +function updatedonker(el) { + el = el.parentElement + el.children[1].textContent = el.children[0].value.slice(-20) +} +</script> </div> {{ $chonkcsrf := .ChonkCSRF }} {{ range .Chatter }}

@@ -49,12 +55,13 @@ {{ end }}

{{ end }} </div> {{ end }} -<form action="/sendchonk" method="POST"> +<form action="/sendchonk" method="POST" enctype="multipart/form-data"> <input type="hidden" name="CSRF" value="{{ $chonkcsrf }}"> <input type="hidden" name="target" value="{{ $target }}" autocomplete=off> <p><label for=noise>noise:</label><br> <textarea name="noise" id="noise"></textarea> <p><button name="chonk" value="chonk">chonk</button> +<label class=button id="donker">attach: <input onchange="updatedonker(this);" type="file" name="donk"><span></span></label> </form> </section> {{ end }}
M web.goweb.go

@@ -1804,7 +1804,6 @@ if target == "" {

http.Error(w, "who is that?", http.StatusInternalServerError) return } - ch := Chonk{ UserID: u.UserID, XID: xid,

@@ -1814,6 +1813,14 @@ Date: dt,

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)