mirror of
https://github.com/owncast/owncast.git
synced 2024-12-18 15:23:55 +03:00
e46f8e2a66
Store the original follow request object and use it for approvals. Closes #1690
52 lines
1.6 KiB
Go
52 lines
1.6 KiB
Go
package requests
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/url"
|
|
|
|
"github.com/go-fed/activity/streams"
|
|
"github.com/go-fed/activity/streams/vocab"
|
|
"github.com/owncast/owncast/activitypub/apmodels"
|
|
"github.com/owncast/owncast/activitypub/crypto"
|
|
"github.com/owncast/owncast/activitypub/workerpool"
|
|
|
|
"github.com/teris-io/shortid"
|
|
)
|
|
|
|
// SendFollowAccept will send an accept activity to a follow request from a specified local user.
|
|
func SendFollowAccept(inbox *url.URL, originalFollowActivity vocab.ActivityStreamsFollow, fromLocalAccountName string) error {
|
|
followAccept := makeAcceptFollow(originalFollowActivity, fromLocalAccountName)
|
|
localAccountIRI := apmodels.MakeLocalIRIForAccount(fromLocalAccountName)
|
|
|
|
var jsonmap map[string]interface{}
|
|
jsonmap, _ = streams.Serialize(followAccept)
|
|
b, _ := json.Marshal(jsonmap)
|
|
req, err := crypto.CreateSignedRequest(b, inbox, localAccountIRI)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
workerpool.AddToOutboundQueue(req)
|
|
|
|
return nil
|
|
}
|
|
|
|
func makeAcceptFollow(originalFollowActivity vocab.ActivityStreamsFollow, fromAccountName string) vocab.ActivityStreamsAccept {
|
|
acceptIDString := shortid.MustGenerate()
|
|
acceptID := apmodels.MakeLocalIRIForResource(acceptIDString)
|
|
actorID := apmodels.MakeLocalIRIForAccount(fromAccountName)
|
|
|
|
accept := streams.NewActivityStreamsAccept()
|
|
idProperty := streams.NewJSONLDIdProperty()
|
|
idProperty.SetIRI(acceptID)
|
|
accept.SetJSONLDId(idProperty)
|
|
|
|
actor := apmodels.MakeActorPropertyWithID(actorID)
|
|
accept.SetActivityStreamsActor(actor)
|
|
|
|
object := streams.NewActivityStreamsObjectProperty()
|
|
object.AppendActivityStreamsFollow(originalFollowActivity)
|
|
accept.SetActivityStreamsObject(object)
|
|
|
|
return accept
|
|
}
|