save mentions in honkmeta

This commit is contained in:
Ted Unangst 2019-11-27 14:36:29 -05:00
parent a144795b13
commit 0b89e1b06c
5 changed files with 34 additions and 12 deletions

View File

@ -635,7 +635,7 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
xonk.Audience = append(xonk.Audience, xonk.Honker) xonk.Audience = append(xonk.Audience, xonk.Honker)
xonk.Audience = oneofakind(xonk.Audience) xonk.Audience = oneofakind(xonk.Audience)
var mentions []string var mentions []Mention
if obj != nil { if obj != nil {
ot, _ := obj.GetString("type") ot, _ := obj.GetString("type")
url, _ = obj.GetString("url") url, _ = obj.GetString("url")
@ -773,7 +773,9 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
xonk.Place = p xonk.Place = p
} }
if tt == "Mention" { if tt == "Mention" {
m, _ := tag.GetString("href") var m Mention
m.Who, _ = tag.GetString("name")
m.Where, _ = tag.GetString("href")
mentions = append(mentions, m) mentions = append(mentions, m)
} }
} }
@ -852,8 +854,9 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
xonk.Precis = precis xonk.Precis = precis
xonk.Format = "html" xonk.Format = "html"
xonk.Convoy = convoy xonk.Convoy = convoy
xonk.Mentions = mentions
for _, m := range mentions { for _, m := range mentions {
if m == user.URL { if m.Where == user.URL {
xonk.Whofore = 1 xonk.Whofore = 1
} }
} }
@ -873,6 +876,7 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
prev.Onts = xonk.Onts prev.Onts = xonk.Onts
prev.Place = xonk.Place prev.Place = xonk.Place
prev.Whofore = xonk.Whofore prev.Whofore = xonk.Whofore
prev.Mentions = xonk.Mentions
updatehonk(prev) updatehonk(prev)
} }
} }
@ -1050,8 +1054,8 @@ func jonkjonk(user *WhatAbout, h *Honk) (junk.Junk, junk.Junk) {
for _, m := range mentions { for _, m := range mentions {
t := junk.New() t := junk.New()
t["type"] = "Mention" t["type"] = "Mention"
t["name"] = m.who t["name"] = m.Who
t["href"] = m.where t["href"] = m.Where
tags = append(tags, t) tags = append(tags, t)
} }
for _, o := range h.Onts { for _, o := range h.Onts {

View File

@ -413,6 +413,12 @@ func donksforhonks(honks []*Honk) {
continue continue
} }
h.Time = t h.Time = t
case "mentions":
err = unjsonify(j, &h.Mentions)
if err != nil {
log.Printf("error parsing mentions: %s", err)
continue
}
case "oldrev": case "oldrev":
default: default:
log.Printf("unknown meta genus: %s", genus) log.Printf("unknown meta genus: %s", genus)
@ -577,6 +583,16 @@ func saveextras(tx *sql.Tx, h *Honk) error {
return 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
}
}
return nil return nil
} }

9
fun.go
View File

@ -277,11 +277,6 @@ func ontologies(s string) []string {
return m[:j] return m[:j]
} }
type Mention struct {
who string
where string
}
var re_mentions = regexp.MustCompile(`@[[:alnum:]._-]+@[[:alnum:].-]*[[:alnum:]]`) var re_mentions = regexp.MustCompile(`@[[:alnum:]._-]+@[[:alnum:].-]*[[:alnum:]]`)
var re_urltions = regexp.MustCompile(`@https://\S+`) var re_urltions = regexp.MustCompile(`@https://\S+`)
@ -307,12 +302,12 @@ func bunchofgrapes(s string) []Mention {
for i := range m { for i := range m {
where := gofish(m[i]) where := gofish(m[i])
if where != "" { 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) m = re_urltions.FindAllString(s, -1)
for i := range m { 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 return mentions
} }

View File

@ -88,6 +88,12 @@ type Honk struct {
Onts []string Onts []string
Place *Place Place *Place
Time *Time Time *Time
Mentions []Mention
}
type Mention struct {
Who string
Where string
} }
type OldRevision struct { type OldRevision struct {

1
web.go
View File

@ -1435,6 +1435,7 @@ func submithonk(w http.ResponseWriter, r *http.Request, isAPI bool) {
noise = strings.Replace(noise, "\r", "", -1) noise = strings.Replace(noise, "\r", "", -1)
noise = quickrename(noise, userinfo.UserID) noise = quickrename(noise, userinfo.UserID)
noise = hooterize(noise) noise = hooterize(noise)
honk.Mentions = bunchofgrapes(noise)
honk.Noise = noise honk.Noise = noise
translate(honk, false) translate(honk, false)