mirror of
https://github.com/writefreely/writefreely
synced 2024-11-24 17:43:05 +00:00
Fix @thebaer's comments in dccfae7a61 (commitcomment-35410380)
This commit is contained in:
parent
dccfae7a61
commit
3eb638b14a
3 changed files with 20 additions and 4 deletions
|
@ -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)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
5
posts.go
5
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
|
||||
}
|
||||
|
|
|
@ -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{}
|
||||
|
|
Loading…
Reference in a new issue