save mentions in honkmeta
Ted Unangst tedu@tedunangst.com
Wed, 27 Nov 2019 14:36:29 -0500
5 files changed,
34 insertions(+),
12 deletions(-)
M
activity.go
→
activity.go
@@ -635,7 +635,7 @@ }
xonk.Audience = append(xonk.Audience, xonk.Honker) xonk.Audience = oneofakind(xonk.Audience) - var mentions []string + var mentions []Mention if obj != nil { ot, _ := obj.GetString("type") url, _ = obj.GetString("url")@@ -773,7 +773,9 @@ p.Url, _ = tag.GetString("url")
xonk.Place = p } if tt == "Mention" { - m, _ := tag.GetString("href") + var m Mention + m.Who, _ = tag.GetString("name") + m.Where, _ = tag.GetString("href") mentions = append(mentions, m) } }@@ -852,8 +854,9 @@ xonk.Noise = content
xonk.Precis = precis xonk.Format = "html" xonk.Convoy = convoy + xonk.Mentions = mentions for _, m := range mentions { - if m == user.URL { + if m.Where == user.URL { xonk.Whofore = 1 } }@@ -873,6 +876,7 @@ prev.Donks = xonk.Donks
prev.Onts = xonk.Onts prev.Place = xonk.Place prev.Whofore = xonk.Whofore + prev.Mentions = xonk.Mentions updatehonk(prev) } }@@ -1050,8 +1054,8 @@ var tags []junk.Junk
for _, m := range mentions { t := junk.New() t["type"] = "Mention" - t["name"] = m.who - t["href"] = m.where + t["name"] = m.Who + t["href"] = m.Where tags = append(tags, t) } for _, o := range h.Onts {
M
database.go
→
database.go
@@ -413,6 +413,12 @@ log.Printf("error parsing time: %s", err)
continue } h.Time = t + case "mentions": + err = unjsonify(j, &h.Mentions) + if err != nil { + log.Printf("error parsing mentions: %s", err) + continue + } case "oldrev": default: log.Printf("unknown meta genus: %s", genus)@@ -574,6 +580,16 @@ _, err = tx.Stmt(stmtSaveMeta).Exec(h.ID, "time", j)
} if err != nil { log.Printf("error saving time: %s", err) + return err + } + } + if m := h.Mentions; len(m) > 0 { + j, err := jsonify(m) + if err == nil { + _, err = tx.Stmt(stmtSaveMeta).Exec(h.ID, "mentions", j) + } + if err != nil { + log.Printf("error saving mentions: %s", err) return err } }
M
fun.go
→
fun.go
@@ -277,11 +277,6 @@ }
return m[:j] } -type Mention struct { - who string - where string -} - var re_mentions = regexp.MustCompile(`@[[:alnum:]._-]+@[[:alnum:].-]*[[:alnum:]]`) var re_urltions = regexp.MustCompile(`@https://\S+`)@@ -307,12 +302,12 @@ var mentions []Mention
for i := range m { where := gofish(m[i]) if where != "" { - mentions = append(mentions, Mention{who: m[i], where: where}) + mentions = append(mentions, Mention{Who: m[i], Where: where}) } } m = re_urltions.FindAllString(s, -1) for i := range m { - mentions = append(mentions, Mention{who: m[i][1:], where: m[i][1:]}) + mentions = append(mentions, Mention{Who: m[i][1:], Where: m[i][1:]}) } return mentions }