Troubleshoot misskey follows
Store the original follow request object and use it for approvals. Closes #1690
This commit is contained in:
@@ -30,6 +30,8 @@ type ActivityPubActor struct {
|
||||
FullUsername string
|
||||
// Image is the avatar image of the Actor.
|
||||
Image *url.URL
|
||||
// RequestObject is the actual follow request object.
|
||||
RequestObject vocab.ActivityStreamsFollow
|
||||
// W3IDSecurityV1PublicKey is the public key of the actor.
|
||||
W3IDSecurityV1PublicKey vocab.W3IDSecurityV1PublicKeyProperty
|
||||
// DisabledAt is the time, if any, this follower was blocked/removed.
|
||||
|
||||
@@ -39,7 +39,7 @@ func handleFollowInboxRequest(c context.Context, activity vocab.ActivityStreamsF
|
||||
localAccountName := data.GetDefaultFederationUsername()
|
||||
|
||||
if approved {
|
||||
if err := requests.SendFollowAccept(follow.Inbox, follow.FollowRequestIri, localAccountName); err != nil {
|
||||
if err := requests.SendFollowAccept(follow.Inbox, activity, localAccountName); err != nil {
|
||||
log.Errorln("unable to send follow accept", err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -74,10 +74,12 @@ func TestBlockedDomains(t *testing.T) {
|
||||
|
||||
func TestBlockedActors(t *testing.T) {
|
||||
person := makeFakePerson()
|
||||
fakeRequest := streams.NewActivityStreamsFollow()
|
||||
persistence.AddFollow(apmodels.ActivityPubActor{
|
||||
ActorIri: person.GetJSONLDId().GetIRI(),
|
||||
Inbox: person.GetJSONLDId().GetIRI(),
|
||||
FollowRequestIri: person.GetJSONLDId().GetIRI(),
|
||||
RequestObject: fakeRequest,
|
||||
}, false)
|
||||
persistence.BlockOrRejectFollower(person.GetJSONLDId().GetIRI().String())
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ func createFederationFollowersTable() {
|
||||
"created_at" TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
"approved_at" TIMESTAMP,
|
||||
"disabled_at" TIMESTAMP,
|
||||
"request_object" BLOB,
|
||||
PRIMARY KEY (iri));
|
||||
CREATE INDEX iri_index ON ap_followers (iri);
|
||||
CREATE INDEX approved_at_index ON ap_followers (approved_at);`
|
||||
|
||||
@@ -36,7 +36,13 @@ func AddFollow(follow apmodels.ActivityPubActor, approved bool) error {
|
||||
if follow.Image != nil {
|
||||
image = follow.Image.String()
|
||||
}
|
||||
return createFollow(follow.ActorIri.String(), follow.Inbox.String(), follow.FollowRequestIri.String(), follow.Name, follow.Username, image, approved)
|
||||
|
||||
followRequestObject, err := apmodels.Serialize(follow.RequestObject)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error serializing follow request object")
|
||||
}
|
||||
|
||||
return createFollow(follow.ActorIri.String(), follow.Inbox.String(), follow.FollowRequestIri.String(), follow.Name, follow.Username, image, followRequestObject, approved)
|
||||
}
|
||||
|
||||
// RemoveFollow will remove a follow from the datastore.
|
||||
@@ -109,7 +115,7 @@ func BlockOrRejectFollower(iri string) error {
|
||||
})
|
||||
}
|
||||
|
||||
func createFollow(actor string, inbox string, request string, name string, username string, image string, approved bool) error {
|
||||
func createFollow(actor, inbox, request, name, username, image string, requestObject []byte, approved bool) error {
|
||||
tx, err := _datastore.DB.Begin()
|
||||
if err != nil {
|
||||
log.Debugln(err)
|
||||
@@ -127,13 +133,14 @@ func createFollow(actor string, inbox string, request string, name string, usern
|
||||
}
|
||||
|
||||
if err = _datastore.GetQueries().WithTx(tx).AddFollower(context.Background(), db.AddFollowerParams{
|
||||
Iri: actor,
|
||||
Inbox: inbox,
|
||||
Name: sql.NullString{String: name, Valid: true},
|
||||
Username: username,
|
||||
Image: sql.NullString{String: image, Valid: true},
|
||||
ApprovedAt: approvedAt,
|
||||
Request: request,
|
||||
Iri: actor,
|
||||
Inbox: inbox,
|
||||
Name: sql.NullString{String: name, Valid: true},
|
||||
Username: username,
|
||||
Image: sql.NullString{String: image, Valid: true},
|
||||
ApprovedAt: approvedAt,
|
||||
Request: request,
|
||||
RequestObject: requestObject,
|
||||
}); err != nil {
|
||||
log.Errorln("error creating new federation follow: ", err)
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@ import (
|
||||
)
|
||||
|
||||
// SendFollowAccept will send an accept activity to a follow request from a specified local user.
|
||||
func SendFollowAccept(inbox *url.URL, followRequestIRI *url.URL, fromLocalAccountName string) error {
|
||||
followAccept := makeAcceptFollow(followRequestIRI, fromLocalAccountName)
|
||||
func SendFollowAccept(inbox *url.URL, originalFollowActivity vocab.ActivityStreamsFollow, fromLocalAccountName string) error {
|
||||
followAccept := makeAcceptFollow(originalFollowActivity, fromLocalAccountName)
|
||||
localAccountIRI := apmodels.MakeLocalIRIForAccount(fromLocalAccountName)
|
||||
|
||||
var jsonmap map[string]interface{}
|
||||
@@ -31,7 +31,7 @@ func SendFollowAccept(inbox *url.URL, followRequestIRI *url.URL, fromLocalAccoun
|
||||
return nil
|
||||
}
|
||||
|
||||
func makeAcceptFollow(followRequestIri *url.URL, fromAccountName string) vocab.ActivityStreamsAccept {
|
||||
func makeAcceptFollow(originalFollowActivity vocab.ActivityStreamsFollow, fromAccountName string) vocab.ActivityStreamsAccept {
|
||||
acceptIDString := shortid.MustGenerate()
|
||||
acceptID := apmodels.MakeLocalIRIForResource(acceptIDString)
|
||||
actorID := apmodels.MakeLocalIRIForAccount(fromAccountName)
|
||||
@@ -45,7 +45,7 @@ func makeAcceptFollow(followRequestIri *url.URL, fromAccountName string) vocab.A
|
||||
accept.SetActivityStreamsActor(actor)
|
||||
|
||||
object := streams.NewActivityStreamsObjectProperty()
|
||||
object.AppendIRI(followRequestIri)
|
||||
object.AppendActivityStreamsFollow(originalFollowActivity)
|
||||
accept.SetActivityStreamsObject(object)
|
||||
|
||||
return accept
|
||||
|
||||
@@ -2,11 +2,11 @@ package resolvers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/go-fed/activity/streams/vocab"
|
||||
"github.com/owncast/owncast/activitypub/apmodels"
|
||||
"github.com/pkg/errors"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -32,6 +32,7 @@ func MakeFollowRequest(c context.Context, activity vocab.ActivityStreamsFollow)
|
||||
Name: person.Name,
|
||||
Username: fullUsername,
|
||||
Image: person.Image,
|
||||
RequestObject: activity,
|
||||
}
|
||||
|
||||
return &followRequest, nil
|
||||
|
||||
Reference in New Issue
Block a user