From 3eb638b14a1ea89319e773a9b13240e40eb06cd3 Mon Sep 17 00:00:00 2001 From: Michael Demetriou Date: Wed, 9 Oct 2019 14:34:31 +0300 Subject: [PATCH] Fix @thebaer's comments in https://github.com/writeas/writefreely/commit/dccfae7a6137afbdb89c45026fdd1932d073c45e#commitcomment-35410380 --- activitypub.go | 16 ++++++++++++++++ posts.go | 5 ++--- webfinger.go | 3 ++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/activitypub.go b/activitypub.go index 68ac7c9..fa25061 100644 --- a/activitypub.go +++ b/activitypub.go @@ -589,18 +589,25 @@ func federatePost(app *App, p *PublicPost, collID int64, isUpdate bool) error { inbox = f.Inbox } if _, ok := inboxes[inbox]; ok { + // check if we're already sending to this shared inbox inboxes[inbox] = append(inboxes[inbox], f.ActorID) } else { + // add the new shared inbox to the list inboxes[inbox] = []string{f.ActorID} } } var activity *activitystreams.Activity + // for each one of the shared inboxes for si, instFolls := range inboxes { + // add all followers from that instance + // to the CC field na.CC = []string{} for _, f := range instFolls { na.CC = append(na.CC, f) } + // create a new "Create" activity + // with our article as object if isUpdate { activity = activitystreams.NewUpdateActivity(na) } else { @@ -608,12 +615,19 @@ func federatePost(app *App, p *PublicPost, collID int64, isUpdate bool) error { activity.To = na.To activity.CC = na.CC } + // and post it to that sharedInbox err = makeActivityPost(app.cfg.App.Host, actor, si, activity) if err != nil { log.Error("Couldn't post! %v", err) } } + // re-create the object so that the CC list gets reset and has + // the mentioned users. This might seem wasteful but the code is + // cleaner than adding the mentioned users to CC here instead of + // in p.ActivityObject() + na = p.ActivityObject(app.cfg) + for _, tag := range na.Tag { if tag.Type == "Mention" { activity = activitystreams.NewCreateActivity(na) @@ -632,6 +646,8 @@ func federatePost(app *App, p *PublicPost, collID int64, isUpdate bool) error { if err != nil { log.Error("Couldn't post! %v", err) } + // log.Info("Activity", activity) + } } diff --git a/posts.go b/posts.go index 520f716..4b6fcc1 100644 --- a/posts.go +++ b/posts.go @@ -1110,11 +1110,10 @@ func (p *PublicPost) ActivityObject(cfg *config.Config) *activitystreams.Object } // Find mentioned users mentionedUsers := make(map[string]string) - //:= map[string]string{"@qwazix@pleroma.site": "https://pleroma.site/users/qwazix", "@tzo@cybre.space": "https://cybre.space/users/tzo"} stripper := bluemonday.StrictPolicy() content := stripper.Sanitize(p.Content) - mentionRegex := regexp.MustCompile(`@[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}`) + mentionRegex := regexp.MustCompile(`@[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]+\b`) mentions := mentionRegex.FindAllString(content, -1) for _, handle := range mentions { @@ -1124,7 +1123,7 @@ func (p *PublicPost) ActivityObject(cfg *config.Config) *activitystreams.Object for handle, iri := range mentionedUsers { o.CC = append(o.CC, iri) - o.Tag = append(o.Tag, activitystreams.Tag{"Mention", iri, handle}) + o.Tag = append(o.Tag, activitystreams.Tag{Type: "Mention", HRef: iri, Name: handle}) } return o } diff --git a/webfinger.go b/webfinger.go index c3f8530..d19478f 100644 --- a/webfinger.go +++ b/webfinger.go @@ -87,7 +87,6 @@ func (wfr wfResolver) IsNotFoundError(err error) bool { // RemoteLookup looks up a user by handle at a remote server // and returns the actor URL -// TODO make this work func RemoteLookup(handle string) string { handle = strings.TrimLeft(handle, "@") // let's take the server part of the handle @@ -95,11 +94,13 @@ func RemoteLookup(handle string) string { resp, err := http.Get("https://" + parts[1] + "/.well-known/webfinger?resource=acct:" + handle) if err != nil { log.Error("Error performing webfinger request", err) + return "" } body, err := ioutil.ReadAll(resp.Body) if err != nil { log.Error("Error reading webfinger response", err) + return "" } var result map[string]interface{}