Comment out broken go-fed code

This commit is contained in:
Anthony Wang 2022-05-26 16:25:39 -05:00
parent 98dad2053c
commit e5d7a28269
Signed by: a
GPG key ID: BC96B00AEC5F2D76
6 changed files with 47 additions and 54 deletions

View file

@ -7,24 +7,21 @@ package activitypub
import (
"fmt"
user_model "code.gitea.io/gitea/models/user"
"github.com/go-fed/activity/streams"
"github.com/go-fed/activity/streams/vocab"
ap "github.com/go-ap/activitypub"
)
func databaseAddToInbox(t vocab.Type) {
fmt.Println(t)
func databaseAddToInbox(activity ap.Activity) {
fmt.Println(activity)
}
func databaseAddToOutbox(t vocab.Type) {
fmt.Println(t)
func databaseAddToOutbox(activity ap.Activity) {
fmt.Println(activity)
}
func GetInbox(user *user_model.User) vocab.ActivityStreamsOrderedCollection {
return streams.NewActivityStreamsOrderedCollection()
/*func GetInbox(user *user_model.User) *ap.OrderedCollection {
return ap.OrderedCollectionNew()
}
func GetOutbox(user *user_model.User) vocab.ActivityStreamsOrderedCollection {
return streams.NewActivityStreamsOrderedCollection()
}
func GetOutbox(user *user_model.User) *ap.OrderedCollection {
return ap.OrderedCollectionNew()
}*/

View file

@ -18,11 +18,10 @@ func Fetch(iri *url.URL) (b []byte, err error) {
req := httplib.NewRequest(iri.String(), http.MethodGet)
req.Header("Accept", ActivityStreamsContentType)
req.Header("Accept-Charset", "utf-8")
clock, err := NewClock()
if err != nil {
return
}
req.Header("Date", fmt.Sprintf("%s GMT", clock.Now().UTC().Format(time.RFC1123)))
req.Header("Date", fmt.Sprintf("%s GMT", time.Now().UTC().Format(time.RFC1123)))
resp, err := req.Response()
if err != nil {
return

View file

@ -6,16 +6,15 @@ package activitypub
import (
"context"
"strings"
//"strings"
user_model "code.gitea.io/gitea/models/user"
//user_model "code.gitea.io/gitea/models/user"
"github.com/go-fed/activity/streams"
"github.com/go-fed/activity/streams/vocab"
ap "github.com/go-ap/activitypub"
)
func Follow(ctx context.Context, activity vocab.ActivityStreamsFollow) error {
actorIRI := activity.GetActivityStreamsActor().Begin().GetIRI()
func Follow(ctx context.Context, activity ap.Follow) error {
/*actorIRI := activity.GetActivityStreamsActor().Begin().GetIRI()
objectIRI := activity.GetActivityStreamsObject().Begin().GetIRI()
actorIRISplit := strings.Split(actorIRI.String(), "/")
@ -39,6 +38,6 @@ func Follow(ctx context.Context, activity vocab.ActivityStreamsFollow) error {
accept.SetActivityStreamsObject(object)
user, _ := user_model.GetUserByName(ctx, objectIRISplit[len(objectIRISplit)-1])
AddToOutbox(accept, user, actorIRI)
AddToOutbox(accept, user, actorIRI)*/
return nil
}

View file

@ -5,19 +5,18 @@
package activitypub
import (
"context"
//"context"
"code.gitea.io/gitea/modules/log"
//"code.gitea.io/gitea/modules/log"
"github.com/go-fed/activity/streams"
"github.com/go-fed/activity/streams/vocab"
ap "github.com/go-ap/activitypub"
)
// Add an activity to a user's inbox
func AddToInbox(t vocab.Type) {
databaseAddToInbox(t)
func AddToInbox(activity ap.Activity) {
databaseAddToInbox(activity)
resolver, _ := streams.NewTypeResolver(Follow)
/*resolver, _ := streams.NewTypeResolver(Follow)
c := context.Background()
err := resolver.Resolve(c, t)
@ -28,5 +27,5 @@ func AddToInbox(t vocab.Type) {
// 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

@ -5,22 +5,21 @@
package activitypub
import (
"context"
//"context"
"net/url"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/setting"
//"code.gitea.io/gitea/modules/json"
//"code.gitea.io/gitea/modules/setting"
"github.com/go-fed/activity/streams"
"github.com/go-fed/activity/streams/vocab"
ap "github.com/go-ap/activitypub"
)
// Add an activity to a user's outbox
func AddToOutbox(t vocab.Type, user *user_model.User, to *url.URL) {
databaseAddToOutbox(t)
func AddToOutbox(activity ap.Activity, user *user_model.User, to *url.URL) {
databaseAddToOutbox(activity)
fetched, _ := Fetch(to)
/*fetched, _ := Fetch(to)
var m map[string]interface{}
json.Unmarshal(fetched, &m)
@ -37,5 +36,5 @@ func AddToOutbox(t vocab.Type, user *user_model.User, to *url.URL) {
jsonmap, _ := streams.Serialize(t)
body, _ := json.Marshal(jsonmap)
client.Post(body, inboxIRI)
client.Post(body, inboxIRI)*/
}

View file

@ -5,18 +5,18 @@
package activitypub
import (
"fmt"
"io"
//"fmt"
//"io"
"net/http"
"strings"
user_model "code.gitea.io/gitea/models/user"
//user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/activitypub"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/json"
//"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/routers/api/v1/user"
"code.gitea.io/gitea/routers/api/v1/utils"
//"code.gitea.io/gitea/routers/api/v1/utils"
ap "github.com/go-ap/activitypub"
)
@ -90,13 +90,13 @@ func PersonInboxGet(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/ActivityPub"
user := user.GetUserByParamsName(ctx, "username")
/*user := user.GetUserByParamsName(ctx, "username")
inbox := activitypub.GetInbox(user)
jsonmap, err := streams.Serialize(inbox)
if err != nil {
ctx.Error(http.StatusInternalServerError, "Serialize", err)
}
ctx.JSON(http.StatusOK, jsonmap)
ctx.JSON(http.StatusOK, jsonmap)*/
}
// PersonInboxPost function
@ -116,7 +116,7 @@ func PersonInboxPost(ctx *context.APIContext) {
// "204":
// "$ref": "#/responses/empty"
r := ctx.Req
/*r := ctx.Req
body, err := io.ReadAll(r.Body)
if err != nil {
ctx.Error(http.StatusInternalServerError, "Error reading request body", err)
@ -132,7 +132,7 @@ func PersonInboxPost(ctx *context.APIContext) {
fmt.Println(m) // Debugging
activitypub.AddToInbox(t)
activitypub.AddToInbox(t)*/
ctx.Status(http.StatusNoContent)
}
@ -154,7 +154,7 @@ func PersonOutboxGet(ctx *context.APIContext) {
// "$ref": "#/responses/ActivityPub"
// Alright so this function is kinda useless right now so let's misuse it for testing following
follow := streams.NewActivityStreamsFollow()
/*follow := streams.NewActivityStreamsFollow()
username := ctx.Params("username")
@ -182,7 +182,7 @@ func PersonOutboxGet(ctx *context.APIContext) {
object.AppendIRI(objectIRI)
follow.SetActivityStreamsObject(object)
activitypub.AddToOutbox(follow, user.GetUserByParamsName(ctx, "username"), objectIRI)
activitypub.AddToOutbox(follow, user.GetUserByParamsName(ctx, "username"), objectIRI)*/
ctx.Status(http.StatusNoContent)
}
@ -244,7 +244,7 @@ func PersonFollowing(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/ActivityPub"
user := user.GetUserByParamsName(ctx, "username")
/*user := user.GetUserByParamsName(ctx, "username")
if user == nil {
return
}
@ -271,7 +271,7 @@ func PersonFollowing(ctx *context.APIContext) {
if err != nil {
ctx.Error(http.StatusInternalServerError, "Serialize", err)
}
ctx.JSON(http.StatusOK, jsonmap)
ctx.JSON(http.StatusOK, jsonmap)*/
}
// PersonFollowers function
@ -291,7 +291,7 @@ func PersonFollowers(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/ActivityPub"
user := user.GetUserByParamsName(ctx, "username")
/*user := user.GetUserByParamsName(ctx, "username")
if user == nil {
return
}
@ -319,5 +319,5 @@ func PersonFollowers(ctx *context.APIContext) {
if err != nil {
ctx.Error(http.StatusInternalServerError, "Serialize", err)
}
ctx.JSON(http.StatusOK, jsonmap)
ctx.JSON(http.StatusOK, jsonmap)*/
}