Add notes about remote users

This commit is contained in:
Anthony Wang 2022-04-15 13:39:50 -05:00
parent 3f77a36a2c
commit eed4644409
Signed by: a
GPG key ID: BC96B00AEC5F2D76
5 changed files with 57 additions and 22 deletions

View file

@ -13,12 +13,12 @@ import (
"github.com/go-fed/activity/streams/vocab"
)
func databaseAddToInbox(activity vocab.ActivityStreamsActivity) {
fmt.Println(activity)
func databaseAddToInbox(t vocab.Type) {
fmt.Println(t)
}
func databaseAddToOutbox(activity vocab.ActivityStreamsActivity) {
fmt.Println(activity)
func databaseAddToOutbox(t vocab.Type) {
fmt.Println(t)
}
func GetInbox(user *user_model.User) vocab.ActivityStreamsOrderedCollection {

View file

@ -6,7 +6,6 @@ package activitypub
import (
"context"
"fmt"
"strings"
user_model "code.gitea.io/gitea/models/user"
@ -16,8 +15,6 @@ import (
)
func Follow(ctx context.Context, activity vocab.ActivityStreamsFollow) error {
fmt.Println("inside follow.go", activity)
actorIRI := activity.GetActivityStreamsActor().Begin().GetIRI()
objectIRI := activity.GetActivityStreamsObject().Begin().GetIRI()

View file

@ -5,16 +5,28 @@
package activitypub
import (
"context"
"code.gitea.io/gitea/modules/log"
"github.com/go-fed/activity/streams"
"github.com/go-fed/activity/streams/vocab"
)
// Add an activity to a user's inbox
func AddToInbox(activity vocab.ActivityStreamsFollow) {
//databaseAddToInbox(activity)
func AddToInbox(t vocab.Type) {
databaseAddToInbox(t)
// Probably should use callbacks here
// https://github.com/owncast/owncast/blob/develop/activitypub/resolvers/resolve.go
if activity.GetJSONLDType().Name() == "Follow" {
//follow(activity)
resolver, _ := streams.NewTypeResolver(Follow)
c := context.Background()
err := resolver.Resolve(c, t)
if err != nil && !streams.IsUnmatchedErr(err) {
// Something went wrong
log.Error("Failed to resolve", err)
} else if streams.IsUnmatchedErr(err) {
// Everything went right but the callback didn't match or the ActivityStreams
// type is one that wasn't code generated.
log.Error("No match", err)
}
}

View file

@ -1,4 +1,6 @@
implementing inboxes/outboxes and federated following
## Federated following
### Inboxes/outboxes
https://github.com/go-gitea/gitea/issues/14186 has an in-depth overview of what needs to happen for this
@ -19,3 +21,20 @@ function to add to outbox
add to database
Check the to field (C2S) for which actor to forward this to (technically there are to, bto, cc, bcc, and audience but that's too much for now)
do a POST request with httpsigs using the activitypub.client stuff
### Remote users
Use the existing `users` table.
https://github.com/go-gitea/gitea/issues/9045
I think we will also need to implement WebFinger because this is the de-facto standard for resolving a username like @ta180m@git.exozy.me into the actor IRI like https://git.exozy.me/api/v1/activitypub/user/ta180m
Also, for the federated following UI, I propose that if no user is logged into the current instance, there should be a popup box for the user to type in their own instance, and then the remote user should be rendered on their own instance.
> Since user table already has two types column, one is LoginType which could be NoType, Plain, LDAP, SMTP, PAM, DLDAP, OAuth2,SSPI. Another column is UserType which could be Individual or Organization.
> We can have a new value for LoginType if reuse user table.
> Federate, but we need another table to store extra information. Maybe external_login_user table.
> And every external Gitea instance could be added as a record in login_source
> A login_source could also be disabled from Admin UI.

View file

@ -117,8 +117,6 @@ func PersonInboxGet(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/ActivityPub"
fmt.Println(ctx)
user := user.GetUserByParamsName(ctx, "username")
inbox := activitypub.GetInbox(user)
jsonmap, err := streams.Serialize(inbox)
@ -146,15 +144,22 @@ func PersonInboxPost(ctx *context.APIContext) {
// "$ref": "#/responses/empty"
r := ctx.Req
body, _ := io.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
ctx.Error(http.StatusInternalServerError, "Error reading request body", err)
}
var m map[string]interface{}
json.Unmarshal(body, &m)
fmt.Println(m)
var t vocab.Type
t, err = streams.ToType(ctx, m)
if err != nil {
ctx.Error(http.StatusInternalServerError, "Could not serialize payload", err)
}
resolver, _ := streams.NewJSONResolver(activitypub.Follow)
c := go_context.Background()
_ = resolver.Resolve(c, m)
fmt.Println(m)
activitypub.AddToInbox(m)
ctx.Status(http.StatusNoContent)
}
@ -199,6 +204,8 @@ func PersonOutboxGet(ctx *context.APIContext) {
object.AppendIRI(objectIRI)
follow.SetActivityStreamsObject(object)
//activitypub.AddToOutbox(follow.(vocab.ActivityStreamsActivity))
user, _ := user_model.GetUserByName("ta180m")
c, _ := activitypub.NewClient(user, "https://git.exozy.me/api/v1/activitypub/user/ta180m#main-key")
@ -227,7 +234,7 @@ func PersonOutboxPost(ctx *context.APIContext) {
// "204":
// "$ref": "#/responses/empty"
fmt.Println(ctx)
// This code below doesn't actually work :/
r := ctx.Req
body, _ := io.ReadAll(r.Body)