From 0faf2b0556f60090a55747760d770f47a8ae785b Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Tue, 28 May 2019 02:36:47 -0400 Subject: [PATCH] allow replying to private messages with private replies --- activity.go | 22 +++++++++++------- deliverator.go | 3 --- docs/manual.txt | 1 + fun.go | 9 ++++++++ honk.go | 61 ++++++++++++++++++++++++++++--------------------- views/honk.html | 6 ++--- 6 files changed, 62 insertions(+), 40 deletions(-) diff --git a/activity.go b/activity.go index 0d97b38..9864a98 100644 --- a/activity.go +++ b/activity.go @@ -809,19 +809,25 @@ func honkworldwide(user *WhatAbout, honk *Honk) { for _, a := range honk.Audience { if a != thewholeworld && a != user.URL && !strings.HasSuffix(a, "/followers") { box, _ := getboxes(a) - if box != nil && box.Shared != "" { - rcpts["%"+box.Shared] = true + if box != nil { + if honk.Public && box.Shared != "" { + rcpts["%"+box.Shared] = true + } else { + rcpts["%"+box.In] = true + } } else { rcpts[a] = true } } } - for _, f := range getdubs(user.ID) { - box, _ := getboxes(f.XID) - if box != nil && box.Shared != "" { - rcpts["%"+box.Shared] = true - } else { - rcpts[f.XID] = true + if honk.Public { + for _, f := range getdubs(user.ID) { + box, _ := getboxes(f.XID) + if box != nil && box.Shared != "" { + rcpts["%"+box.Shared] = true + } else { + rcpts[f.XID] = true + } } } for a := range rcpts { diff --git a/deliverator.go b/deliverator.go index 0d54538..734c08e 100644 --- a/deliverator.go +++ b/deliverator.go @@ -93,9 +93,6 @@ func deliverate(goarounds int, username string, rcpt string, msg []byte) { return } inbox = box.In - if box.Shared != "" { - inbox = box.Shared - } } err := PostMsg(keyname, key, inbox, msg) if err != nil { diff --git a/docs/manual.txt b/docs/manual.txt index b62d1e8..f7c769d 100644 --- a/docs/manual.txt +++ b/docs/manual.txt @@ -43,6 +43,7 @@ Honks are public. Welcome to the internet. Received messages are only visible when logged in, regardless of addressing. Received messages that are less than public are tagged with a red border. +Replies to private messages will also be private. -- css diff --git a/fun.go b/fun.go index b0d70c8..b58fe07 100644 --- a/fun.go +++ b/fun.go @@ -281,6 +281,15 @@ func butnottooloud(aud []string) { } } +func keepitquiet(aud []string) bool { + for _, a := range aud { + if a == thewholeworld { + return false + } + } + return true +} + func oneofakind(a []string) []string { var x []string for n, s := range a { diff --git a/honk.go b/honk.go index aca8cd8..ecec2df 100644 --- a/honk.go +++ b/honk.go @@ -63,7 +63,7 @@ type Honk struct { Precis string Convoy string Audience []string - Privacy string + Public bool Whofore int64 HTML template.HTML Donks []*Donk @@ -156,7 +156,7 @@ func showrss(w http.ResponseWriter, r *http.Request) { var honks []*Honk if name != "" { - honks = gethonksbyuser(name) + honks = gethonksbyuser(name, false) } else { honks = getpublichonks() } @@ -368,7 +368,7 @@ func outbox(w http.ResponseWriter, r *http.Request) { http.NotFound(w, r) return } - honks := gethonksbyuser(name) + honks := gethonksbyuser(name, false) var jonks []map[string]interface{} for _, h := range honks { @@ -425,8 +425,8 @@ func showuser(w http.ResponseWriter, r *http.Request) { WriteJunk(w, j) return } - honks := gethonksbyuser(name) u := login.GetUserInfo(r) + honks := gethonksbyuser(name, u != nil && u.Username == name) honkpage(w, r, u, user, honks, "") } @@ -463,7 +463,7 @@ func showhonk(w http.ResponseWriter, r *http.Request) { } xid := fmt.Sprintf("https://%s%s", serverName, r.URL.Path) h := getxonk(user.ID, xid) - if h == nil { + if h == nil || !h.Public { http.NotFound(w, r) return } @@ -477,11 +477,6 @@ func showhonk(w http.ResponseWriter, r *http.Request) { return } honks := gethonksbyconvoy(-1, h.Convoy) - for _, hh := range honks { - if hh.XID != h.XID { - hh.Privacy = "limited" - } - } u := login.GetUserInfo(r) honkpage(w, r, u, nil, honks, "one honk maybe more") } @@ -591,6 +586,7 @@ func getxonk(userid int64, xid string) *Honk { } h.Date, _ = time.Parse(dbtimeformat, dt) h.Audience = strings.Split(aud, " ") + h.Public = !keepitquiet(h.Audience) return h } @@ -599,9 +595,13 @@ func getpublichonks() []*Honk { rows, err := stmtPublicHonks.Query(dt) return getsomehonks(rows, err) } -func gethonksbyuser(name string) []*Honk { +func gethonksbyuser(name string, includeprivate bool) []*Honk { dt := time.Now().UTC().Add(-7 * 24 * time.Hour).Format(dbtimeformat) - rows, err := stmtUserHonks.Query(name, dt) + whofore := 2 + if includeprivate { + whofore = 3 + } + rows, err := stmtUserHonks.Query(whofore, name, dt) return getsomehonks(rows, err) } func gethonksforuser(userid int64) []*Honk { @@ -650,13 +650,7 @@ func getsomehonks(rows *sql.Rows, err error) []*Honk { } h.Date, _ = time.Parse(dbtimeformat, dt) h.Audience = strings.Split(aud, " ") - h.Privacy = "limited" - for _, a := range h.Audience { - if a == thewholeworld { - h.Privacy = "" - break - } - } + h.Public = !keepitquiet(h.Audience) honks = append(honks, &h) } rows.Close() @@ -703,6 +697,9 @@ func savebonk(w http.ResponseWriter, r *http.Request) { if xonk == nil { return } + if !xonk.Public { + return + } donksforhonks([]*Honk{xonk}) dt := time.Now().UTC() @@ -767,7 +764,7 @@ func zonkit(w http.ResponseWriter, r *http.Request) { if xonk != nil { stmtZonkDonks.Exec(xonk.ID) stmtZonkIt.Exec(userinfo.UserID, what) - if xonk.Whofore == 2 { + if xonk.Whofore == 2 || xonk.Whofore == 3 { zonk := Honk{ What: "zonk", XID: xonk.XID, @@ -823,11 +820,6 @@ func savehonk(w http.ResponseWriter, r *http.Request) { noise = strings.TrimSpace(noise) honk.Precis = strings.TrimSpace(honk.Precis) - if noise != "" && noise[0] == '@' { - honk.Audience = append(grapevine(noise), thewholeworld) - } else { - honk.Audience = prepend(thewholeworld, grapevine(noise)) - } var convoy string if rid != "" { xonk := getxonk(userinfo.UserID, rid) @@ -839,13 +831,27 @@ func savehonk(w http.ResponseWriter, r *http.Request) { honk.Audience = append(honk.Audience, xonkaud...) convoy = c } + for i, a := range honk.Audience { + if a == thewholeworld { + honk.Audience[0], honk.Audience[i] = honk.Audience[i], honk.Audience[0] + break + } + } honk.RID = rid + } else { + honk.Audience = []string{thewholeworld} + } + if noise != "" && noise[0] == '@' { + honk.Audience = append(grapevine(noise), honk.Audience...) + } else { + honk.Audience = append(honk.Audience, grapevine(noise)...) } if convoy == "" { convoy = "data:,electrichonkytonk-" + xfiltrate() } butnottooloud(honk.Audience) honk.Audience = oneofakind(honk.Audience) + honk.Public = !keepitquiet(honk.Audience) noise = obfusbreak(noise) honk.Noise = noise honk.Convoy = convoy @@ -914,6 +920,9 @@ func savehonk(w http.ResponseWriter, r *http.Request) { aud := strings.Join(honk.Audience, " ") whofore := 2 + if !honk.Public { + whofore = 3 + } res, err := stmtSaveHonk.Exec(userinfo.UserID, what, honk.Honker, xid, rid, dt.Format(dbtimeformat), "", aud, noise, convoy, whofore, "html", honk.Precis, honk.Oonker) if err != nil { @@ -1350,7 +1359,7 @@ func prepareStatements(db *sql.DB) { butnotthose := " and convoy not in (select name from zonkers where userid = ? and wherefore = 'zonvoy' order by zonkerid desc limit 100)" stmtOneXonk = preparetodie(db, selecthonks+"where honks.userid = ? and xid = ?") stmtPublicHonks = preparetodie(db, selecthonks+"where whofore = 2 and dt > ?"+limit) - stmtUserHonks = preparetodie(db, selecthonks+"where whofore = 2 and username = ? and dt > ?"+limit) + stmtUserHonks = preparetodie(db, selecthonks+"where (whofore = 2 or whofore = ?) and username = ? and dt > ?"+limit) stmtHonksForUser = preparetodie(db, selecthonks+"where honks.userid = ? and dt > ? and honker in (select xid from honkers where userid = ? and flavor = 'sub' and combos not like '% - %')"+butnotthose+limit) stmtHonksForMe = preparetodie(db, selecthonks+"where honks.userid = ? and dt > ? and whofore = 1"+butnotthose+limit) stmtHonksByHonker = preparetodie(db, selecthonks+"join honkers on honkers.xid = honks.honker where honks.userid = ? and honkers.name = ?"+butnotthose+limit) diff --git a/views/honk.html b/views/honk.html index 5987194..96b144d 100644 --- a/views/honk.html +++ b/views/honk.html @@ -1,4 +1,4 @@ -
+
{{ with .Honk }}
avatar @@ -39,10 +39,10 @@ convoy: {{ .Convoy }} {{ if .BonkCSRF }}

-{{ if not .Honk.Privacy }} +{{ if .Honk.Public }} - {{ end }} +