This commit is contained in:
Ted Unangst 2022-05-03 15:20:34 -04:00
commit 64329252e9
6 changed files with 121 additions and 45 deletions

View File

@ -972,6 +972,52 @@ func savexonker(what, value, flav, when string) {
stmtSaveXonker.Exec(what, value, flav, when) stmtSaveXonker.Exec(what, value, flav, when)
} }
func savehonker(user *WhatAbout, url, name, flavor, combos, mj string) error {
var owner string
if url[0] == '#' {
flavor = "peep"
if name == "" {
name = url[1:]
}
owner = url
} else {
info, err := investigate(url)
if err != nil {
ilog.Printf("failed to investigate honker: %s", err)
return err
}
url = info.XID
if name == "" {
name = info.Name
}
owner = info.Owner
}
var x string
db := opendatabase()
row := db.QueryRow("select xid from honkers where xid = ? and userid = ? and flavor in ('sub', 'unsub', 'peep')", url, user.ID)
err := row.Scan(&x)
if err != sql.ErrNoRows {
if err != nil {
elog.Printf("honker scan err: %s", err)
} else {
err = fmt.Errorf("it seems you are already subscribed to them")
}
return err
}
res, err := stmtSaveHonker.Exec(user.ID, name, url, flavor, combos, owner, mj)
if err != nil {
elog.Print(err)
return err
}
honkerid, _ := res.LastInsertId()
if flavor == "presub" {
followyou(user, honkerid)
}
return nil
}
func cleanupdb(arg string) { func cleanupdb(arg string) {
db := opendatabase() db := opendatabase()
days, err := strconv.Atoi(arg) days, err := strconv.Atoi(arg)

View File

@ -1,5 +1,19 @@
changelog changelog
=== next
+ Add atme class to mentions
+ Improvements to the mastodon importer.
+ More hydration capable pages.
+ Support for local.js.
+ Better error messages for timeouts.
+ Some improved html and markdown.
=== 0.9.7 Witless Weekender === 0.9.7 Witless Weekender
+++ Word guessing game. Wonk wonk! +++ Word guessing game. Wonk wonk!

3
fun.go
View File

@ -73,6 +73,9 @@ func reverbolate(userid int64, honks []*Honk) {
if !h.Public { if !h.Public {
h.Style += " limited" h.Style += " limited"
} }
if h.Whofore == 1 {
h.Style += " atme"
}
translate(h) translate(h)
local := false local := false
if h.Whofore == 2 || h.Whofore == 3 { if h.Whofore == 2 || h.Whofore == 3 {

View File

@ -16,6 +16,7 @@
package main package main
import ( import (
"encoding/csv"
"encoding/json" "encoding/json"
"fmt" "fmt"
"html" "html"
@ -69,6 +70,20 @@ func importMastodon(username, source string) {
if err != nil { if err != nil {
elog.Fatal(err) elog.Fatal(err)
} }
if _, err := os.Stat(source + "/outbox.json"); err == nil {
importMastotoots(user, source)
} else {
ilog.Printf("skipping outbox.json!")
}
if _, err := os.Stat(source + "/following_accounts.csv"); err == nil {
importMastotooters(user, source)
} else {
ilog.Printf("skipping following_accounts.csv!")
}
}
func importMastotoots(user *WhatAbout, source string) {
type Toot struct { type Toot struct {
Id string Id string
Type string Type string
@ -79,6 +94,7 @@ func importMastodon(username, source string) {
var outbox struct { var outbox struct {
OrderedItems []Toot OrderedItems []Toot
} }
ilog.Println("Importing honks...")
fd, err := os.Open(source + "/outbox.json") fd, err := os.Open(source + "/outbox.json")
if err != nil { if err != nil {
elog.Fatal(err) elog.Fatal(err)
@ -169,6 +185,37 @@ func importMastodon(username, source string) {
} }
} }
func importMastotooters(user *WhatAbout, source string) {
ilog.Println("Importing honkers...")
fd, err := os.Open(source + "/following_accounts.csv")
if err != nil {
elog.Fatal(err)
}
r := csv.NewReader(fd)
data, err := r.ReadAll()
if err != nil {
elog.Fatal(err)
}
fd.Close()
var meta HonkerMeta
mj, _ := jsonify(&meta)
for i, d := range data {
if i == 0 {
continue
}
url := "@" + d[0]
name := ""
flavor := "peep"
combos := ""
err := savehonker(user, url, name, flavor, combos, mj)
if err != nil {
elog.Printf("trouble with a honker: %s", err)
}
}
}
func importTwitter(username, source string) { func importTwitter(username, source string) {
user, err := butwhatabout(username) user, err := butwhatabout(username)
if err != nil { if err != nil {

View File

@ -148,6 +148,8 @@ function hydrargs() {
args["c"] = arg args["c"] = arg
} else if (name == "honker") { } else if (name == "honker") {
args["xid"] = arg args["xid"] = arg
} else if (name == "user") {
args["uname"] = arg
} }
return args return args
} }

54
web.go
View File

@ -712,6 +712,8 @@ func showuser(w http.ResponseWriter, r *http.Request) {
u := login.GetUserInfo(r) u := login.GetUserInfo(r)
honks := gethonksbyuser(name, u != nil && u.Username == name, 0) honks := gethonksbyuser(name, u != nil && u.Username == name, 0)
templinfo := getInfo(r) templinfo := getInfo(r)
templinfo["PageName"] = "user"
templinfo["PageArg"] = name
templinfo["Name"] = user.Name templinfo["Name"] = user.Name
templinfo["WhatAbout"] = user.HTAbout templinfo["WhatAbout"] = user.HTAbout
templinfo["ServerMessage"] = "" templinfo["ServerMessage"] = ""
@ -1921,53 +1923,12 @@ func submithonker(w http.ResponseWriter, r *http.Request) {
flavor = "peep" flavor = "peep"
} }
if url[0] == '#' { err := savehonker(user, url, name, flavor, combos, mj)
flavor = "peep"
if name == "" {
name = url[1:]
}
_, err := stmtSaveHonker.Exec(u.UserID, name, url, flavor, combos, url, mj)
if err != nil {
elog.Print(err)
return
}
http.Redirect(w, r, "/honkers", http.StatusSeeOther)
return
}
info, err := investigate(url)
if err != nil { if err != nil {
http.Error(w, "error investigating: "+err.Error(), http.StatusInternalServerError) http.Error(w, "had some trouble with that: "+err.Error(), http.StatusInternalServerError)
ilog.Printf("failed to investigate honker: %s", err)
return
}
url = info.XID
if name == "" {
name = info.Name
}
var x string
db := opendatabase()
row := db.QueryRow("select xid from honkers where xid = ? and userid = ? and flavor in ('sub', 'unsub', 'peep')", url, u.UserID)
err = row.Scan(&x)
if err != sql.ErrNoRows {
http.Error(w, "it seems you are already subscribed to them", http.StatusInternalServerError)
if err != nil {
elog.Printf("honker scan err: %s", err)
}
return return
} }
res, err := stmtSaveHonker.Exec(u.UserID, name, url, flavor, combos, info.Owner, mj)
if err != nil {
elog.Print(err)
return
}
honkerid, _ = res.LastInsertId()
if flavor == "presub" {
followyou(user, honkerid)
}
http.Redirect(w, r, "/honkers", http.StatusSeeOther) http.Redirect(w, r, "/honkers", http.StatusSeeOther)
} }
@ -2272,6 +2233,10 @@ func webhydra(w http.ResponseWriter, r *http.Request) {
</form>`, login.GetCSRF("submithonker", r), xid) </form>`, login.GetCSRF("submithonker", r), xid)
msg := templates.Sprintf(`honks by honker: <a href="%s" ref="noreferrer">%s</a>%s`, xid, xid, miniform) msg := templates.Sprintf(`honks by honker: <a href="%s" ref="noreferrer">%s</a>%s`, xid, xid, miniform)
hydra.Srvmsg = msg hydra.Srvmsg = msg
case "user":
uname := r.FormValue("uname")
honks = gethonksbyuser(uname, u != nil && u.Username == uname, wanted)
hydra.Srvmsg = templates.Sprintf("honks by user: %s", uname)
default: default:
http.NotFound(w, r) http.NotFound(w, r)
} }
@ -2395,8 +2360,7 @@ var workinprogress = 0
func enditall() { func enditall() {
sig := make(chan os.Signal) sig := make(chan os.Signal)
signal.Notify(sig, os.Interrupt) signal.Notify(sig, os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT)
signal.Notify(sig, syscall.SIGTERM)
<-sig <-sig
ilog.Printf("stopping...") ilog.Printf("stopping...")
for i := 0; i < workinprogress; i++ { for i := 0; i < workinprogress; i++ {