MCPcopy
hub / github.com/writefreely/writefreely / federatePost

Function federatePost

activitypub.go:850–948  ·  view source on GitHub ↗
(app *App, p *PublicPost, collID int64, isUpdate bool)

Source from the content-addressed store, hash-verified

848}
849
850func federatePost(app *App, p *PublicPost, collID int64, isUpdate bool) error {
851 // If app is private, do not federate
852 if app.cfg.App.Private {
853 return nil
854 }
855
856 // Do not federate posts from private or protected blogs
857 if p.Collection.Visibility == CollPrivate || p.Collection.Visibility == CollProtected {
858 return nil
859 }
860
861 if debugging {
862 if isUpdate {
863 log.Info("Federating updated post!")
864 } else {
865 log.Info("Federating new post!")
866 }
867 }
868
869 actor := p.Collection.PersonObject(collID)
870 na := p.ActivityObject(app)
871
872 // Add followers
873 p.Collection.ID = collID
874 followers, err := app.db.GetAPFollowers(&p.Collection.Collection)
875 if err != nil {
876 log.Error("Couldn't post! %v", err)
877 return err
878 }
879 log.Info("Followers for %d: %+v", collID, followers)
880
881 inboxes := map[string][]string{}
882 for _, f := range *followers {
883 inbox := f.SharedInbox
884 if inbox == "" {
885 inbox = f.Inbox
886 }
887 if _, ok := inboxes[inbox]; ok {
888 // check if we're already sending to this shared inbox
889 inboxes[inbox] = append(inboxes[inbox], f.ActorID)
890 } else {
891 // add the new shared inbox to the list
892 inboxes[inbox] = []string{f.ActorID}
893 }
894 }
895
896 var activity *activitystreams.Activity
897 // for each one of the shared inboxes
898 for si, instFolls := range inboxes {
899 // add all followers from that instance
900 // to the CC field
901 na.CC = []string{}
902 na.CC = append(na.CC, instFolls...)
903 // create a new "Create" activity
904 // with our article as object
905 if isUpdate {
906 na.Updated = &p.Updated
907 activity = activitystreams.NewUpdateActivity(na)

Callers 4

newPostFunction · 0.85
existingPostFunction · 0.85
addPostFunction · 0.85
handleImportFunction · 0.85

Calls 5

makeActivityPostFunction · 0.85
getRemoteUserFunction · 0.85
PersonObjectMethod · 0.80
ActivityObjectMethod · 0.80
GetAPFollowersMethod · 0.65

Tested by

no test coverage detected