Actually follow local user when processing follow request

This commit is contained in:
Anthony Wang 2022-04-14 10:08:18 -05:00
parent f9b38495fd
commit 608e4036e5
Signed by: a
GPG key ID: BC96B00AEC5F2D76
2 changed files with 12 additions and 6 deletions

View file

@ -5,16 +5,22 @@
package activitypub package activitypub
import ( import (
"strings"
user_model "code.gitea.io/gitea/models/user"
"github.com/go-fed/activity/streams" "github.com/go-fed/activity/streams"
"github.com/go-fed/activity/streams/vocab" "github.com/go-fed/activity/streams/vocab"
) )
func follow(activity vocab.ActivityStreamsFollow) { func follow(activity vocab.ActivityStreamsFollow) {
actorIRI := activity.GetActivityStreamsActor().Begin().GetIRI()
objectIRI := activity.GetActivityStreamsObject().Begin().GetIRI() objectIRI := activity.GetActivityStreamsObject().Begin().GetIRI()
// user_model.FollowUser() currently only works with local users
/*s := strings.Split(objectIRI.String(), ",") actorIRISplit := strings.Split(actorIRI.String(), ",")
user, _ := user_model.GetUserIDsByNames(s[len(s)-1]) objectIRISplit := strings.Split(objectIRI.String(), ",")
user_model.FollowUser()*/ users, _ := user_model.GetUserIDsByNames([]string{actorIRISplit[len(actorIRISplit)-1], objectIRISplit[len(objectIRISplit)-1]}, false)
user_model.FollowUser(users[0], users[1])
// Send accept activity // Send accept activity
accept := streams.NewActivityStreamsAccept() accept := streams.NewActivityStreamsAccept()

View file

@ -142,7 +142,7 @@ func PersonInboxPost(ctx *context.APIContext) {
// "$ref": "#/responses/empty" // "$ref": "#/responses/empty"
fmt.Println(ctx) fmt.Println(ctx)
r := ctx.Req r := ctx.Req
body, _ := io.ReadAll(r.Body) body, _ := io.ReadAll(r.Body)
var m map[string]interface{} var m map[string]interface{}
@ -204,7 +204,7 @@ func PersonOutboxPost(ctx *context.APIContext) {
// "$ref": "#/responses/empty" // "$ref": "#/responses/empty"
fmt.Println(ctx) fmt.Println(ctx)
r := ctx.Req r := ctx.Req
body, _ := io.ReadAll(r.Body) body, _ := io.ReadAll(r.Body)
var m map[string]interface{} var m map[string]interface{}