From 608e4036e5b9bf80a7298f5c093e24aa475899bb Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Thu, 14 Apr 2022 10:08:18 -0500 Subject: [PATCH] Actually follow local user when processing follow request --- modules/activitypub/follow.go | 14 ++++++++++---- routers/api/v1/activitypub/person.go | 4 ++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/modules/activitypub/follow.go b/modules/activitypub/follow.go index 174617149..0a6ad35cd 100644 --- a/modules/activitypub/follow.go +++ b/modules/activitypub/follow.go @@ -5,16 +5,22 @@ package activitypub import ( + "strings" + + user_model "code.gitea.io/gitea/models/user" + "github.com/go-fed/activity/streams" "github.com/go-fed/activity/streams/vocab" ) func follow(activity vocab.ActivityStreamsFollow) { + actorIRI := activity.GetActivityStreamsActor().Begin().GetIRI() objectIRI := activity.GetActivityStreamsObject().Begin().GetIRI() - // user_model.FollowUser() currently only works with local users - /*s := strings.Split(objectIRI.String(), ",") - user, _ := user_model.GetUserIDsByNames(s[len(s)-1]) - user_model.FollowUser()*/ + + actorIRISplit := strings.Split(actorIRI.String(), ",") + objectIRISplit := strings.Split(objectIRI.String(), ",") + users, _ := user_model.GetUserIDsByNames([]string{actorIRISplit[len(actorIRISplit)-1], objectIRISplit[len(objectIRISplit)-1]}, false) + user_model.FollowUser(users[0], users[1]) // Send accept activity accept := streams.NewActivityStreamsAccept() diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index eff2a036d..3f4a9a613 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -142,7 +142,7 @@ func PersonInboxPost(ctx *context.APIContext) { // "$ref": "#/responses/empty" fmt.Println(ctx) - + r := ctx.Req body, _ := io.ReadAll(r.Body) var m map[string]interface{} @@ -204,7 +204,7 @@ func PersonOutboxPost(ctx *context.APIContext) { // "$ref": "#/responses/empty" fmt.Println(ctx) - + r := ctx.Req body, _ := io.ReadAll(r.Body) var m map[string]interface{}