diff --git a/activity.go b/activity.go index 561a338..a67aa3c 100644 --- a/activity.go +++ b/activity.go @@ -635,7 +635,7 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk { 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 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk { 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 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk { 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 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk { prev.Onts = xonk.Onts prev.Place = xonk.Place prev.Whofore = xonk.Whofore + prev.Mentions = xonk.Mentions updatehonk(prev) } } @@ -1050,8 +1054,8 @@ func jonkjonk(user *WhatAbout, h *Honk) (junk.Junk, 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 { diff --git a/database.go b/database.go index 789559c..9cfe7b2 100644 --- a/database.go +++ b/database.go @@ -413,6 +413,12 @@ func donksforhonks(honks []*Honk) { 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) @@ -577,6 +583,16 @@ func saveextras(tx *sql.Tx, h *Honk) error { 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 } diff --git a/fun.go b/fun.go index 8c9c77d..577bd40 100644 --- a/fun.go +++ b/fun.go @@ -277,11 +277,6 @@ func ontologies(s string) []string { 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 @@ func bunchofgrapes(s string) []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 } diff --git a/honk.go b/honk.go index 7b46f6c..33c852e 100644 --- a/honk.go +++ b/honk.go @@ -88,6 +88,12 @@ type Honk struct { Onts []string Place *Place Time *Time + Mentions []Mention +} + +type Mention struct { + Who string + Where string } type OldRevision struct { diff --git a/web.go b/web.go index 8389b3f..12b04ff 100644 --- a/web.go +++ b/web.go @@ -1435,6 +1435,7 @@ func submithonk(w http.ResponseWriter, r *http.Request, isAPI bool) { noise = strings.Replace(noise, "\r", "", -1) noise = quickrename(noise, userinfo.UserID) noise = hooterize(noise) + honk.Mentions = bunchofgrapes(noise) honk.Noise = noise translate(honk, false)