Commit 5b969a52 authored by Lukas Matt's avatar Lukas Matt

wip

parent f790ca98
......@@ -21,6 +21,7 @@ import (
"net/http"
// run "github.com/revel/modules/jobs/app/jobs"
// "git.feneas.org/ganggo/ganggo/app/jobs"
"git.feneas.org/ganggo/federation"
"github.com/revel/revel"
"net/url"
"github.com/go-fed/activity/pub"
......@@ -88,10 +89,11 @@ func init() {
clock := &Clock{}
client := &http.Client{}
pubber = pub.NewFederatingPubber(
pubber = pub.NewPubber(
clock,
ap,
cb,
cb,
deliverer,
client,
"GGG/v0 UA",
......@@ -99,6 +101,8 @@ func init() {
5,
)
catchAllHandler = pub.ServeActivityPubObject(ap, clock)
federation.SetPubber(pubber)
}
func (a ApiAPResult) Apply(req *revel.Request, resp *revel.Response) {
......
This diff is collapsed.
......@@ -18,48 +18,151 @@ package controllers
//
import (
// run "github.com/revel/modules/jobs/app/jobs"
// "git.feneas.org/ganggo/ganggo/app/jobs"
api "git.feneas.org/ganggo/api/app"
run "github.com/revel/modules/jobs/app/jobs"
"git.feneas.org/ganggo/ganggo/app/jobs"
"git.feneas.org/ganggo/ganggo/app/models"
federation "git.feneas.org/ganggo/federation"
"github.com/revel/revel"
//"github.com/go-fed/activity/deliverer"
"github.com/go-fed/activity/streams"
"github.com/go-fed/activity/vocab"
"context"
//"golang.org/x/time/rate"
"regexp"
"strings"
"fmt"
)
type ApiAPCallbacker struct {}
func (ApiAPCallbacker) Create(c context.Context, s *streams.Create) error {
revel.AppLog.Debug("ApiAPCallbacker Create")
m, _ := s.Raw().Serialize()
revel.AppLog.Debug("ApiAPCallbacker Create",
"objLen", s.Raw().ObjectLen(), "m", m)
for i := 0; i < s.Raw().ObjectLen(); i += 1 {
usernameRegex := regexp.MustCompile(`/person/([^/]+?)(/.*){0,1}$`)
obj := s.Raw().GetObject(i)
switch {
case vocab.HasTypeNote(obj):
post := &federation.ActivityPubPost{
CreateType: s.Raw(),
NoteType: obj.(vocab.NoteType),
}
msg := federation.ActivityPubMessage{}
msg.SetEntity(post)
if post.Public() {
run.Now(jobs.Receiver{Message: msg})
} else {
for i := 0; i < post.NoteType.ToLen(); i += 1 {
to := post.NoteType.GetToIRI(i).String()
if !strings.HasPrefix(to, fmt.Sprintf("%s%s", api.PROTO, api.ADDRESS)) {
continue
}
regexParts := usernameRegex.FindAllStringSubmatch(to, 1)
if len(regexParts) <= 0 || len(regexParts[0]) <= 1 {
continue
}
username := regexParts[0][1]
var user models.User
err := user.FindByUsername(username)
if err != nil {
continue
}
run.Now(jobs.Receiver{Guid:user.Person.Guid, Message: msg})
}
}
}
}
return nil
}
func (ApiAPCallbacker) Update(c context.Context, s *streams.Update) error {
revel.AppLog.Debug("ApiAPCallbacker Update")
return nil }
revel.AppLog.Error("ApiAPCallbacker Update")
return nil
}
func (ApiAPCallbacker) Delete(c context.Context, s *streams.Delete) error {
revel.AppLog.Debug("ApiAPCallbacker Delete")
return nil }
revel.AppLog.Error("ApiAPCallbacker Delete")
return nil
}
func (ApiAPCallbacker) Add(c context.Context, s *streams.Add) error {
revel.AppLog.Debug("ApiAPCallbacker Add")
return nil }
func (ApiAPCallbacker) Remove(c context.Context, s *streams.Remove) error {
revel.AppLog.Debug("ApiAPCallbacker Remove")
return nil }
func (ApiAPCallbacker) Like(c context.Context, s *streams.Like) error {
revel.AppLog.Error("ApiAPCallbacker Add")
return nil
}
func (ApiAPCallbacker) Remove(c context.Context, s *streams.Remove) error {
revel.AppLog.Error("ApiAPCallbacker Remove")
return nil
}
func (ApiAPCallbacker) Like(c context.Context, s *streams.Like) error {
revel.AppLog.Debug("ApiAPCallbacker Like")
return nil }
func (ApiAPCallbacker) Block(c context.Context, s *streams.Block) error {
revel.AppLog.Debug("ApiAPCallbacker Block")
return nil }
func (ApiAPCallbacker) Follow(c context.Context, s *streams.Follow) error {
revel.AppLog.Debug("ApiAPCallbacker Follow")
return nil }
func (ApiAPCallbacker) Undo(c context.Context, s *streams.Undo) error {
//
return nil
}
func (ApiAPCallbacker) Block(c context.Context, s *streams.Block) error {
revel.AppLog.Error("ApiAPCallbacker Block")
return nil
}
func (a ApiAPCallbacker) Follow(c context.Context, s *streams.Follow) error {
revel.AppLog.Debug("ApiAPCallbacker Follow", "ActorLen", s.Raw().ActorLen())
return a.follow(c, true, s)
}
func (ApiAPCallbacker) follow(c context.Context, f bool, s *streams.Follow) error {
for i := 0; i < s.Raw().ActorLen(); i+= 1 {
follow := &federation.ActivityPubFollow{FollowType: s.Raw()}
follow.SetSharing(f)
msg := federation.ActivityPubMessage{}
msg.SetEntity(follow)
run.Now(jobs.Receiver{Message: msg})
}
return nil
}
func (a ApiAPCallbacker) Undo(c context.Context, s *streams.Undo) error {
revel.AppLog.Debug("ApiAPCallbacker Undo")
return nil }
func (ApiAPCallbacker) Accept(c context.Context, s *streams.Accept) error {
revel.AppLog.Debug("ApiAPCallbacker Accept")
return nil }
func (ApiAPCallbacker) Reject(c context.Context, s *streams.Reject) error {
revel.AppLog.Debug("ApiAPCallbacker Reject")
return nil }
for i := 0; i < s.Raw().ObjectLen(); i+= 1 {
if !s.Raw().IsObject(i) {
continue
}
m, err := s.Raw().GetObject(i).Serialize()
if err != nil {
revel.AppLog.Error("ApiAPCallbacker Undo", "err", err)
continue
}
resolver := &streams.Resolver{
FollowCallback: func(follow *streams.Follow) error {
return a.follow(c, false, follow)
},
}
err = resolver.Deserialize(m)
if err != nil {
revel.AppLog.Error("ApiAPCallbacker Undo", "err", err)
continue
}
}
return nil
}
func (ApiAPCallbacker) Accept(c context.Context, s *streams.Accept) error {
revel.AppLog.Error("ApiAPCallbacker Accept")
return nil
}
func (ApiAPCallbacker) Reject(c context.Context, s *streams.Reject) error {
revel.AppLog.Error("ApiAPCallbacker Reject")
return nil
}
......@@ -72,6 +72,7 @@ func (ApiAPFederation) PrivateKey(boxIRI *url.URL) (crypto.PrivateKey, string, e
usernameRegex := regexp.MustCompile(`/person/([^/]+?)(/.*){0,1}$`)
regexParts := usernameRegex.FindAllStringSubmatch(boxIRI.String(), 1)
if len(regexParts) <= 0 || len(regexParts[0]) <= 1 {
revel.AppLog.Error("ApiAPApplication PrivateKey", "url", boxIRI.String())
return nil, "", errors.New(ERR_USER_NOT_FOUND)
}
username := regexParts[0][1]
......
......@@ -264,6 +264,7 @@ func (a ApiAspect) DeletePerson() revel.Result {
run.Now(jobs.Dispatcher{
User: a.CurrentUser,
Message: membership,
Retract: true,
})
}
return a.RenderJSON(membership)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment