need to fix avatating
Anirudh Oppiliappan x@icyphox.sh
Fri, 12 Jul 2024 14:05:31 +0300
4 files changed,
53 insertions(+),
38 deletions(-)
M
database.go
→
database.go
@@ -255,7 +255,14 @@ }
func getlimitedhonksforuser(userid UserID, minid, maxid int64, limit int) []*Honk { dt := time.Now().Add(-honkwindow).UTC().Format(dbtimeformat) - rows, err := stmtHonksForUserPrecise.Query(minid, maxid, userid, dt, userid, userid, limit) + rows := &sql.Rows{} + var err error + if maxid == 0 { + rows, err = stmtHonksForUserGreaterThan.Query(minid, userid, dt, userid, userid, limit) + } + if minid == 0 { + rows, err = stmtHonksForUserLessThan.Query(maxid, userid, dt, userid, userid, limit) + } return getsomehonks(rows, err) } func gethonksforuserfirstclass(userid UserID, wanted int64) []*Honk {@@ -1298,7 +1305,8 @@ var stmtGetTracks *sql.Stmt
var stmtSaveChonk, stmtLoadChonks, stmtGetChatters *sql.Stmt var stmtDeliquentCheck, stmtDeliquentUpdate *sql.Stmt var stmtGetUserCount *sql.Stmt -var stmtHonksForUserPrecise *sql.Stmt +var stmtHonksForUserLessThan *sql.Stmt +var stmtHonksForUserGreaterThan *sql.Stmt var stmtGetActiveUserCount *sql.Stmt var stmtGetLocalHonkCount *sql.Stmt var stmtSaveMastoApp *sql.Stmt@@ -1363,7 +1371,8 @@ stmtEventHonks = preparetodie(db, selecthonks+"where (whofore = 2 or honks.userid = ?) and what = 'event'"+smalllimit)
stmtUserHonks = preparetodie(db, selecthonks+"where honks.honkid > ? and (whofore = 2 or whofore = ?) and username = ? and dt > ?"+smalllimit) myhonkers := " and honker in (select xid from honkers where userid = ? and (flavor = 'sub' or flavor = 'peep' or flavor = 'presub') and combos not like '% - %')" stmtHonksForUser = preparetodie(db, selecthonks+"where honks.honkid > ? and honks.userid = ? and dt > ?"+myhonkers+butnotthose+customlimit) - stmtHonksForUserPrecise = preparetodie(db, selecthonks+"where honks.honkid > ? and honks.honkid < ? and honks.userid = ? and dt > ?"+myhonkers+butnotthose+customlimit) + stmtHonksForUserLessThan = preparetodie(db, selecthonks+"where honks.honkid < ? and honks.userid = ? and dt > ?"+myhonkers+butnotthose+customlimit) + stmtHonksForUserGreaterThan = preparetodie(db, selecthonks+"where honks.honkid > ? and honks.userid = ? and dt > ?"+myhonkers+butnotthose+customlimit) stmtHonksForUserFirstClass = preparetodie(db, selecthonks+"where honks.honkid > ? and honks.userid = ? and dt > ? and (rid = '' or what = 'bonk')"+myhonkers+butnotthose+limit) stmtHonksForMe = preparetodie(db, selecthonks+"where honks.honkid > ? and honks.userid = ? and dt > ? and whofore = 1"+butnotthose+smalllimit) sqlHonksFromLongAgo = selecthonks + "where honks.honkid > ? and honks.userid = ? and (WHERECLAUSE) and (whofore = 2 or flags & 4)" + butnotthose + limit
M
fun.go
→
fun.go
@@ -35,6 +35,7 @@ "golang.org/x/net/html"
"humungus.tedunangst.com/r/webs/gencache" "humungus.tedunangst.com/r/webs/htfilter" "humungus.tedunangst.com/r/webs/httpsig" + "humungus.tedunangst.com/r/webs/login" "humungus.tedunangst.com/r/webs/mz" "humungus.tedunangst.com/r/webs/templates" )@@ -785,3 +786,37 @@ return origin
} return "" } + +func avatator(n string, uinfo *login.UserInfo) []byte { + var a []byte + if isurl(n) { + if uinfo != nil { + j, err := GetJunkFast(UserID(uinfo.UserID), n) + if err != nil { + dlog.Println("avatating: getting junk:", err) + a = avatateautogen(n) + } + pfpurl, _ := j.GetString("icon", "url") + res, err := http.Get(pfpurl) + if err != nil { + dlog.Println("avatating: getting pfp url:", err) + a = avatateautogen(n) + } else { + defer res.Body.Close() + + pfpbytes, err := io.ReadAll(res.Body) + if err != nil { + dlog.Println("avatating: bruh shits clapped:", err) + a = avatateautogen(n) + } + a = pfpbytes + } + } else { + a = avatateautogen(n) + } + } else { + a = avatateautogen(n) + } + + return a +}
M
masto_util.go
→
masto_util.go
@@ -74,7 +74,7 @@ j["url"] = h.URL
j["replies_count"] = len(h.Replies) j["reblogs_count"] = 0 j["favourites_count"] = 0 - j["reblogged"] = false + j["reblogged"] = h.IsBonked() j["favourited"] = false j["muted"] = false j["bookmarked"] = false@@ -84,8 +84,8 @@ "id": "2019",
"username": h.Username, "acct": h.Handle, "display_name": h.Username, - "avatar": "https://h.icyphox.sh/a?a=foo", - "avatar_static": "https://h.icyphox.sh/a?a=foo", + "avatar": "https://h.icyphox.sh/a?a=" + h.Handle, + "avatar_static": "https://h.icyphox.sh/a?a=" + h.Handle, "header": "https://h.icyphox.sh/meme/banner.jpg", "header_static": "https://h.icyphox.sh/meme/banner.jpg", "note": "foo bar baz",
M
web.go
→
web.go
@@ -2556,8 +2556,7 @@ u, err := url.Parse(s)
return err == nil && u.Scheme != "" && u.Host != "" } -func avatateautogen(r *http.Request) []byte { - n := r.FormValue("a") +func avatateautogen(n string) []byte { return genAvatar(n) }@@ -2567,36 +2566,8 @@ loadAvatarColors()
} var a []byte n := r.FormValue("a") - - if isurl(n) { - uinfo := login.GetUserInfo(r) - if uinfo != nil { - j, err := GetJunkFast(UserID(uinfo.UserID), n) - if err != nil { - dlog.Println("avatating: getting junk:", err) - a = avatateautogen(r) - } - pfpurl, _ := j.GetString("icon", "url") - res, err := http.Get(pfpurl) - if err != nil { - dlog.Println("avatating: getting pfp url:", err) - a = avatateautogen(r) - } else { - defer res.Body.Close() - - pfpbytes, err := io.ReadAll(res.Body) - if err != nil { - dlog.Println("avatating: bruh shits clapped:", err) - a = avatateautogen(r) - } - a = pfpbytes - } - } else { - a = avatateautogen(r) - } - } else { - a = avatateautogen(r) - } + uinfo := login.GetUserInfo(r) + a = avatator(n, uinfo) if !develMode { w.Header().Set("Cache-Control", "max-age="+somedays())