address activitypub notes to the streamer's follower collection (#4314)
* make a new function to generate appropriate to and cc apub objects * use new addressing function to set "public" message addressing appropriately with the followers collection * early return from sending federated message if federation is disabled * cleanup old addressing code, apply new addressing mechanism to live notifications as well * linter fix * Update activitypub/outbox/outbox.go --------- Co-authored-by: Gabe Kangas <gabek@real-ity.com>
This commit is contained in:
co-authored by
Gabe Kangas
parent
6d97def04a
commit
c9a69b281c
@@ -31,6 +31,20 @@ func MakeNotePublic(note vocab.ActivityStreamsNote) vocab.ActivityStreamsNote {
|
|||||||
return note
|
return note
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func MakeAddressingToFollowers(followers_iri *url.URL, public bool) (vocab.ActivityStreamsToProperty, vocab.ActivityStreamsCcProperty) {
|
||||||
|
to := streams.NewActivityStreamsToProperty()
|
||||||
|
cc := streams.NewActivityStreamsCcProperty()
|
||||||
|
|
||||||
|
if public {
|
||||||
|
public, _ := url.Parse(PUBLIC)
|
||||||
|
to.AppendIRI(public)
|
||||||
|
cc.AppendIRI(followers_iri)
|
||||||
|
} else {
|
||||||
|
to.AppendIRI(followers_iri)
|
||||||
|
}
|
||||||
|
return to, cc
|
||||||
|
}
|
||||||
|
|
||||||
// MakeNoteDirect sets the required properties to make this note seen as a
|
// MakeNoteDirect sets the required properties to make this note seen as a
|
||||||
// direct message.
|
// direct message.
|
||||||
func MakeNoteDirect(note vocab.ActivityStreamsNote, toIRI *url.URL) vocab.ActivityStreamsNote {
|
func MakeNoteDirect(note vocab.ActivityStreamsNote, toIRI *url.URL) vocab.ActivityStreamsNote {
|
||||||
|
|||||||
@@ -66,11 +66,11 @@ func SendLive() error {
|
|||||||
|
|
||||||
activity, _, note, noteID := createBaseOutboundMessage(textContent)
|
activity, _, note, noteID := createBaseOutboundMessage(textContent)
|
||||||
|
|
||||||
// To the public if we're not treating ActivityPub as "private".
|
to, cc := getAddressingToFollowers()
|
||||||
if !configRepository.GetFederationIsPrivate() {
|
note.SetActivityStreamsTo(to)
|
||||||
note = apmodels.MakeNotePublic(note)
|
note.SetActivityStreamsCc(cc)
|
||||||
activity = apmodels.MakeActivityPublic(activity)
|
activity.SetActivityStreamsTo(to)
|
||||||
}
|
activity.SetActivityStreamsCc(cc)
|
||||||
|
|
||||||
note.SetActivityStreamsTag(tagProp)
|
note.SetActivityStreamsTag(tagProp)
|
||||||
|
|
||||||
@@ -153,8 +153,6 @@ func SendDirectMessageToAccount(textContent, account string) error {
|
|||||||
|
|
||||||
// SendPublicMessage will send a public message to all followers.
|
// SendPublicMessage will send a public message to all followers.
|
||||||
func SendPublicMessage(textContent string) error {
|
func SendPublicMessage(textContent string) error {
|
||||||
configRepository := configrepository.Get()
|
|
||||||
|
|
||||||
originalContent := textContent
|
originalContent := textContent
|
||||||
textContent = utils.RenderSimpleMarkdown(textContent)
|
textContent = utils.RenderSimpleMarkdown(textContent)
|
||||||
|
|
||||||
@@ -177,10 +175,11 @@ func SendPublicMessage(textContent string) error {
|
|||||||
activity, _, note, noteID := createBaseOutboundMessage(textContent)
|
activity, _, note, noteID := createBaseOutboundMessage(textContent)
|
||||||
note.SetActivityStreamsTag(tagProp)
|
note.SetActivityStreamsTag(tagProp)
|
||||||
|
|
||||||
if !configRepository.GetFederationIsPrivate() {
|
to, cc := getAddressingToFollowers()
|
||||||
note = apmodels.MakeNotePublic(note)
|
note.SetActivityStreamsTo(to)
|
||||||
activity = apmodels.MakeActivityPublic(activity)
|
note.SetActivityStreamsCc(cc)
|
||||||
}
|
activity.SetActivityStreamsTo(to)
|
||||||
|
activity.SetActivityStreamsCc(cc)
|
||||||
|
|
||||||
b, err := apmodels.Serialize(activity)
|
b, err := apmodels.Serialize(activity)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -199,6 +198,18 @@ func SendPublicMessage(textContent string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if public, cc the followers and to the Public uri, else private, address followers directly.
|
||||||
|
func getAddressingToFollowers() (vocab.ActivityStreamsToProperty, vocab.ActivityStreamsCcProperty) {
|
||||||
|
configRepository := configrepository.Get()
|
||||||
|
server_url := configRepository.GetServerURL()
|
||||||
|
followers_iri, _ := url.Parse(server_url)
|
||||||
|
username := configRepository.GetDefaultFederationUsername()
|
||||||
|
|
||||||
|
followers_iri = followers_iri.JoinPath("federation", "user", username, "followers")
|
||||||
|
|
||||||
|
return apmodels.MakeAddressingToFollowers(followers_iri, !configRepository.GetFederationIsPrivate())
|
||||||
|
}
|
||||||
|
|
||||||
// nolint: unparam
|
// nolint: unparam
|
||||||
func createBaseOutboundMessage(textContent string) (vocab.ActivityStreamsCreate, string, vocab.ActivityStreamsNote, string) {
|
func createBaseOutboundMessage(textContent string) (vocab.ActivityStreamsCreate, string, vocab.ActivityStreamsNote, string) {
|
||||||
configRepository := configrepository.Get()
|
configRepository := configrepository.Get()
|
||||||
|
|||||||
@@ -16,6 +16,13 @@ func SendFederatedMessage(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
configRepository := configrepository.Get()
|
||||||
|
|
||||||
|
if !configRepository.GetFederationEnabled() {
|
||||||
|
webutils.WriteSimpleResponse(w, false, "Federation is disabled")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
configValue, success := getValueFromRequest(w, r)
|
configValue, success := getValueFromRequest(w, r)
|
||||||
if !success {
|
if !success {
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user