conclusion of the donks for chonks trilogy

Ted Unangst 4 years ago
parent 92b300d184
commit c2936c65ba

@ -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

@ -2,7 +2,7 @@
<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 @@
<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 @@ chatter: {{ .Target }}
{{ 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 }}

@ -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)

Loading…
Cancel
Save