allow replying to private messages with private replies

This commit is contained in:
Ted Unangst 2019-05-28 02:36:47 -04:00
parent 33b57b6874
commit 0faf2b0556
6 changed files with 62 additions and 40 deletions

View File

@ -809,19 +809,25 @@ func honkworldwide(user *WhatAbout, honk *Honk) {
for _, a := range honk.Audience { for _, a := range honk.Audience {
if a != thewholeworld && a != user.URL && !strings.HasSuffix(a, "/followers") { if a != thewholeworld && a != user.URL && !strings.HasSuffix(a, "/followers") {
box, _ := getboxes(a) box, _ := getboxes(a)
if box != nil && box.Shared != "" { if box != nil {
rcpts["%"+box.Shared] = true if honk.Public && box.Shared != "" {
rcpts["%"+box.Shared] = true
} else {
rcpts["%"+box.In] = true
}
} else { } else {
rcpts[a] = true rcpts[a] = true
} }
} }
} }
for _, f := range getdubs(user.ID) { if honk.Public {
box, _ := getboxes(f.XID) for _, f := range getdubs(user.ID) {
if box != nil && box.Shared != "" { box, _ := getboxes(f.XID)
rcpts["%"+box.Shared] = true if box != nil && box.Shared != "" {
} else { rcpts["%"+box.Shared] = true
rcpts[f.XID] = true } else {
rcpts[f.XID] = true
}
} }
} }
for a := range rcpts { for a := range rcpts {

View File

@ -93,9 +93,6 @@ func deliverate(goarounds int, username string, rcpt string, msg []byte) {
return return
} }
inbox = box.In inbox = box.In
if box.Shared != "" {
inbox = box.Shared
}
} }
err := PostMsg(keyname, key, inbox, msg) err := PostMsg(keyname, key, inbox, msg)
if err != nil { if err != nil {

View File

@ -43,6 +43,7 @@ Honks are public. Welcome to the internet.
Received messages are only visible when logged in, regardless of addressing. Received messages are only visible when logged in, regardless of addressing.
Received messages that are less than public are tagged with a red border. Received messages that are less than public are tagged with a red border.
Replies to private messages will also be private.
-- css -- css

9
fun.go
View File

@ -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 { func oneofakind(a []string) []string {
var x []string var x []string
for n, s := range a { for n, s := range a {

61
honk.go
View File

@ -63,7 +63,7 @@ type Honk struct {
Precis string Precis string
Convoy string Convoy string
Audience []string Audience []string
Privacy string Public bool
Whofore int64 Whofore int64
HTML template.HTML HTML template.HTML
Donks []*Donk Donks []*Donk
@ -156,7 +156,7 @@ func showrss(w http.ResponseWriter, r *http.Request) {
var honks []*Honk var honks []*Honk
if name != "" { if name != "" {
honks = gethonksbyuser(name) honks = gethonksbyuser(name, false)
} else { } else {
honks = getpublichonks() honks = getpublichonks()
} }
@ -368,7 +368,7 @@ func outbox(w http.ResponseWriter, r *http.Request) {
http.NotFound(w, r) http.NotFound(w, r)
return return
} }
honks := gethonksbyuser(name) honks := gethonksbyuser(name, false)
var jonks []map[string]interface{} var jonks []map[string]interface{}
for _, h := range honks { for _, h := range honks {
@ -425,8 +425,8 @@ func showuser(w http.ResponseWriter, r *http.Request) {
WriteJunk(w, j) WriteJunk(w, j)
return return
} }
honks := gethonksbyuser(name)
u := login.GetUserInfo(r) u := login.GetUserInfo(r)
honks := gethonksbyuser(name, u != nil && u.Username == name)
honkpage(w, r, u, user, honks, "") 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) xid := fmt.Sprintf("https://%s%s", serverName, r.URL.Path)
h := getxonk(user.ID, xid) h := getxonk(user.ID, xid)
if h == nil { if h == nil || !h.Public {
http.NotFound(w, r) http.NotFound(w, r)
return return
} }
@ -477,11 +477,6 @@ func showhonk(w http.ResponseWriter, r *http.Request) {
return return
} }
honks := gethonksbyconvoy(-1, h.Convoy) honks := gethonksbyconvoy(-1, h.Convoy)
for _, hh := range honks {
if hh.XID != h.XID {
hh.Privacy = "limited"
}
}
u := login.GetUserInfo(r) u := login.GetUserInfo(r)
honkpage(w, r, u, nil, honks, "one honk maybe more") 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.Date, _ = time.Parse(dbtimeformat, dt)
h.Audience = strings.Split(aud, " ") h.Audience = strings.Split(aud, " ")
h.Public = !keepitquiet(h.Audience)
return h return h
} }
@ -599,9 +595,13 @@ func getpublichonks() []*Honk {
rows, err := stmtPublicHonks.Query(dt) rows, err := stmtPublicHonks.Query(dt)
return getsomehonks(rows, err) 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) 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) return getsomehonks(rows, err)
} }
func gethonksforuser(userid int64) []*Honk { func gethonksforuser(userid int64) []*Honk {
@ -650,13 +650,7 @@ func getsomehonks(rows *sql.Rows, err error) []*Honk {
} }
h.Date, _ = time.Parse(dbtimeformat, dt) h.Date, _ = time.Parse(dbtimeformat, dt)
h.Audience = strings.Split(aud, " ") h.Audience = strings.Split(aud, " ")
h.Privacy = "limited" h.Public = !keepitquiet(h.Audience)
for _, a := range h.Audience {
if a == thewholeworld {
h.Privacy = ""
break
}
}
honks = append(honks, &h) honks = append(honks, &h)
} }
rows.Close() rows.Close()
@ -703,6 +697,9 @@ func savebonk(w http.ResponseWriter, r *http.Request) {
if xonk == nil { if xonk == nil {
return return
} }
if !xonk.Public {
return
}
donksforhonks([]*Honk{xonk}) donksforhonks([]*Honk{xonk})
dt := time.Now().UTC() dt := time.Now().UTC()
@ -767,7 +764,7 @@ func zonkit(w http.ResponseWriter, r *http.Request) {
if xonk != nil { if xonk != nil {
stmtZonkDonks.Exec(xonk.ID) stmtZonkDonks.Exec(xonk.ID)
stmtZonkIt.Exec(userinfo.UserID, what) stmtZonkIt.Exec(userinfo.UserID, what)
if xonk.Whofore == 2 { if xonk.Whofore == 2 || xonk.Whofore == 3 {
zonk := Honk{ zonk := Honk{
What: "zonk", What: "zonk",
XID: xonk.XID, XID: xonk.XID,
@ -823,11 +820,6 @@ func savehonk(w http.ResponseWriter, r *http.Request) {
noise = strings.TrimSpace(noise) noise = strings.TrimSpace(noise)
honk.Precis = strings.TrimSpace(honk.Precis) 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 var convoy string
if rid != "" { if rid != "" {
xonk := getxonk(userinfo.UserID, rid) xonk := getxonk(userinfo.UserID, rid)
@ -839,13 +831,27 @@ func savehonk(w http.ResponseWriter, r *http.Request) {
honk.Audience = append(honk.Audience, xonkaud...) honk.Audience = append(honk.Audience, xonkaud...)
convoy = c 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 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 == "" { if convoy == "" {
convoy = "data:,electrichonkytonk-" + xfiltrate() convoy = "data:,electrichonkytonk-" + xfiltrate()
} }
butnottooloud(honk.Audience) butnottooloud(honk.Audience)
honk.Audience = oneofakind(honk.Audience) honk.Audience = oneofakind(honk.Audience)
honk.Public = !keepitquiet(honk.Audience)
noise = obfusbreak(noise) noise = obfusbreak(noise)
honk.Noise = noise honk.Noise = noise
honk.Convoy = convoy honk.Convoy = convoy
@ -914,6 +920,9 @@ func savehonk(w http.ResponseWriter, r *http.Request) {
aud := strings.Join(honk.Audience, " ") aud := strings.Join(honk.Audience, " ")
whofore := 2 whofore := 2
if !honk.Public {
whofore = 3
}
res, err := stmtSaveHonk.Exec(userinfo.UserID, what, honk.Honker, xid, rid, res, err := stmtSaveHonk.Exec(userinfo.UserID, what, honk.Honker, xid, rid,
dt.Format(dbtimeformat), "", aud, noise, convoy, whofore, "html", honk.Precis, honk.Oonker) dt.Format(dbtimeformat), "", aud, noise, convoy, whofore, "html", honk.Precis, honk.Oonker)
if err != nil { 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)" 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 = ?") stmtOneXonk = preparetodie(db, selecthonks+"where honks.userid = ? and xid = ?")
stmtPublicHonks = preparetodie(db, selecthonks+"where whofore = 2 and dt > ?"+limit) 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) 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) 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) stmtHonksByHonker = preparetodie(db, selecthonks+"join honkers on honkers.xid = honks.honker where honks.userid = ? and honkers.name = ?"+butnotthose+limit)

View File

@ -1,4 +1,4 @@
<article class="honk {{ .Honk.What }} {{ .Honk.Privacy }}"> <article class="honk {{ .Honk.What }} {{ and (not .Honk.Public) "limited" }}">
{{ with .Honk }} {{ with .Honk }}
<header> <header>
<img alt="avatar" src="/a?a={{ .Honker}}"> <img alt="avatar" src="/a?a={{ .Honker}}">
@ -39,10 +39,10 @@ convoy: <a href="/t?c={{ .Convoy }}">{{ .Convoy }}</a>
{{ if .BonkCSRF }} {{ if .BonkCSRF }}
<p> <p>
<div> <div>
{{ if not .Honk.Privacy }} {{ if .Honk.Public }}
<button onclick="bonk(this, '{{ .Honk.XID }}'); return false;"><a href="/bonk">bonk</a></button> <button onclick="bonk(this, '{{ .Honk.XID }}'); return false;"><a href="/bonk">bonk</a></button>
<button onclick="showhonkform('{{ .Honk.XID }}', '{{ .Honk.Username }}'); return false;"><a href="/newhonk">tonk</a></button>
{{ end }} {{ end }}
<button onclick="showhonkform('{{ .Honk.XID }}', '{{ .Honk.Username }}'); return false;"><a href="/newhonk">tonk</a></button>
<form class="inlineform" action="/zonkit" method="POST"> <form class="inlineform" action="/zonkit" method="POST">
<input type="hidden" name="CSRF" value="{{ .BonkCSRF }}"> <input type="hidden" name="CSRF" value="{{ .BonkCSRF }}">
<input type="hidden" name="honk" value="{{ .Honk.XID }}"> <input type="hidden" name="honk" value="{{ .Honk.XID }}">