conclusion of the donks for chonks trilogy

This commit is contained in:
Ted Unangst 2020-05-17 21:09:54 -04:00
parent 4b493f2162
commit 0b0d4eaedf
3 changed files with 39 additions and 16 deletions

View File

@ -1030,6 +1030,23 @@ func subsub(user *WhatAbout, xid string, owner string) {
deliverate(0, user.ID, owner, j.ToBytes()) 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 // returns activity, object
func jonkjonk(user *WhatAbout, h *Honk) (junk.Junk, junk.Junk) { func jonkjonk(user *WhatAbout, h *Honk) (junk.Junk, junk.Junk) {
dt := h.Date.Format(time.RFC3339) 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()) jo["duration"] = "PT" + strings.ToUpper(t.Duration.String())
} }
} }
var atts []junk.Junk atts := activatedonks(h.Donks)
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)
}
if len(atts) > 0 { if len(atts) > 0 {
jo["attachment"] = atts jo["attachment"] = atts
} }
@ -1300,6 +1305,10 @@ func sendchonk(user *WhatAbout, ch *Chonk) {
jo["attributedTo"] = user.URL jo["attributedTo"] = user.URL
jo["to"] = aud jo["to"] = aud
jo["content"] = ch.HTML jo["content"] = ch.HTML
atts := activatedonks(ch.Donks)
if len(atts) > 0 {
jo["attachment"] = atts
}
j := junk.New() j := junk.New()
j["@context"] = itiswhatitis j["@context"] = itiswhatitis

View File

@ -2,7 +2,7 @@
<main> <main>
<div class="info"> <div class="info">
<p> <p>
<form action="/sendchonk" method="POST"> <form action="/sendchonk" method="POST" enctype="multipart/form-data">
<h3>new chatter</h3> <h3>new chatter</h3>
<input type="hidden" name="CSRF" value="{{ .ChonkCSRF }}"> <input type="hidden" name="CSRF" value="{{ .ChonkCSRF }}">
<p><label for=target>target:</label><br> <p><label for=target>target:</label><br>
@ -11,6 +11,12 @@
<textarea name="noise" id="noise"></textarea> <textarea name="noise" id="noise"></textarea>
<p><button name="chonk" value="chonk">chonk</button> <p><button name="chonk" value="chonk">chonk</button>
</form> </form>
<script>
function updatedonker(el) {
el = el.parentElement
el.children[1].textContent = el.children[0].value.slice(-20)
}
</script>
</div> </div>
{{ $chonkcsrf := .ChonkCSRF }} {{ $chonkcsrf := .ChonkCSRF }}
{{ range .Chatter }} {{ range .Chatter }}
@ -49,12 +55,13 @@ chatter: {{ .Target }}
{{ end }} {{ end }}
</div> </div>
{{ end }} {{ 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="CSRF" value="{{ $chonkcsrf }}">
<input type="hidden" name="target" value="{{ $target }}" autocomplete=off> <input type="hidden" name="target" value="{{ $target }}" autocomplete=off>
<p><label for=noise>noise:</label><br> <p><label for=noise>noise:</label><br>
<textarea name="noise" id="noise"></textarea> <textarea name="noise" id="noise"></textarea>
<p><button name="chonk" value="chonk">chonk</button> <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> </form>
</section> </section>
{{ end }} {{ end }}

9
web.go
View File

@ -1804,7 +1804,6 @@ func submitchonk(w http.ResponseWriter, r *http.Request) {
http.Error(w, "who is that?", http.StatusInternalServerError) http.Error(w, "who is that?", http.StatusInternalServerError)
return return
} }
ch := Chonk{ ch := Chonk{
UserID: u.UserID, UserID: u.UserID,
XID: xid, XID: xid,
@ -1814,6 +1813,14 @@ func submitchonk(w http.ResponseWriter, r *http.Request) {
Noise: noise, Noise: noise,
Format: format, 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) filterchonk(&ch)
savechonk(&ch) savechonk(&ch)
go sendchonk(user, &ch) go sendchonk(user, &ch)