aboutsummaryrefslogtreecommitdiff
path: root/activitypub
diff options
context:
space:
mode:
authorFChannel <>2022-06-12 15:36:19 -0700
committerFChannel <>2022-06-19 12:53:29 -0700
commitf57d5722e6f2187bea249240eb14c881f989c3c1 (patch)
treeef8f4d23f9c40e0b0ba1ab2efb03e3795efe8ec0 /activitypub
parentdac4b267cab31fb3a4ce301f1bcdf364fcb541a1 (diff)
first pass on federation working
Diffstat (limited to 'activitypub')
-rw-r--r--activitypub/activity.go14
-rw-r--r--activitypub/activityPubStruct.go22
-rw-r--r--activitypub/actor.go8
-rw-r--r--activitypub/object.go88
-rw-r--r--activitypub/util.go4
5 files changed, 32 insertions, 104 deletions
diff --git a/activitypub/activity.go b/activitypub/activity.go
index 036a5ce..5d89272 100644
--- a/activitypub/activity.go
+++ b/activitypub/activity.go
@@ -23,7 +23,7 @@ func (activity Activity) AcceptFollow() Activity {
accept.Actor = &nActor
accept.Actor.Id = activity.Object.Actor
var nObj ObjectBase
- accept.Object = &nObj
+ accept.Object = nObj
accept.Object.Actor = activity.Actor.Id
var nNested NestedObjectBase
accept.Object.Object = &nNested
@@ -181,7 +181,7 @@ func (activity Activity) Reject() Activity {
accept.AtContext.Context = activity.AtContext.Context
accept.Type = "Reject"
var nObj ObjectBase
- accept.Object = &nObj
+ accept.Object = nObj
var nActor Actor
accept.Actor = &nActor
accept.Actor.Id = activity.Object.Actor
@@ -196,8 +196,8 @@ func (activity Activity) Reject() Activity {
}
func (activity Activity) Report(reason string) (bool, error) {
- if isLocal, err := activity.Object.IsLocal(); !isLocal || err != nil {
- return false, util.MakeError(err, "Report")
+ if isLocal, _ := activity.Object.IsLocal(); !isLocal {
+ return false, nil
}
reqActivity := Activity{Id: activity.Object.Id}
@@ -288,7 +288,7 @@ func (activity Activity) SetActorFollowing() (Activity, error) {
var query string
if alreadyFollowing && alreadyFollower {
- if res, err := activity.Actor.IsLocal(); err == nil && !res {
+ if res, _ := activity.Actor.IsLocal(); !res {
go activity.Actor.DeleteCache()
} else if err != nil {
return activity, util.MakeError(err, "SetActorFollowing")
@@ -306,10 +306,8 @@ func (activity Activity) SetActorFollowing() (Activity, error) {
}
if !alreadyFollowing && !alreadyFollower {
- if res, err := activity.Actor.IsLocal(); err == nil && !res {
+ if res, _ := activity.Actor.IsLocal(); !res {
go activity.Actor.WriteCache()
- } else if err != nil {
- return activity, util.MakeError(err, "SetActorFollowing")
}
query = `insert into following (id, following) values ($1, $2)`
diff --git a/activitypub/activityPubStruct.go b/activitypub/activityPubStruct.go
index ee1e451..b8e3180 100644
--- a/activitypub/activityPubStruct.go
+++ b/activitypub/activityPubStruct.go
@@ -93,17 +93,17 @@ type PublicKeyPem struct {
type Activity struct {
AtContext
- Type string `json:"type,omitempty"`
- Id string `json:"id,omitempty"`
- Actor *Actor `json:"actor,omitempty"`
- Name string `json:"name,omitempty"`
- Summary string `json:"summary,omitempty"`
- Auth string `json:"auth,omitempty"`
- To []string `json:"to,omitempty"`
- Bto []string `json:"bto,omitempty"`
- Cc []string `json:"cc,omitempty"`
- Published time.Time `json:"published,omitempty"`
- Object *ObjectBase `json:"object,omitempty"`
+ Type string `json:"type,omitempty"`
+ Id string `json:"id,omitempty"`
+ Actor *Actor `json:"actor,omitempty"`
+ Name string `json:"name,omitempty"`
+ Summary string `json:"summary,omitempty"`
+ Auth string `json:"auth,omitempty"`
+ To []string `json:"to,omitempty"`
+ Bto []string `json:"bto,omitempty"`
+ Cc []string `json:"cc,omitempty"`
+ Published time.Time `json:"published,omitempty"`
+ Object ObjectBase `json:"object,omitempty"`
}
type ObjectBase struct {
diff --git a/activitypub/actor.go b/activitypub/actor.go
index e54088d..b69c831 100644
--- a/activitypub/actor.go
+++ b/activitypub/actor.go
@@ -818,8 +818,8 @@ func (actor Actor) IsAlreadyFollower(follow string) (bool, error) {
}
func (actor Actor) IsLocal() (bool, error) {
- actor, err := GetActorFromDB(actor.Id)
- return actor.Id != "", util.MakeError(err, "IsLocal")
+ actor, _ = GetActorFromDB(actor.Id)
+ return actor.Id != "", nil
}
func (actor Actor) IsValid() (Actor, bool, error) {
@@ -1048,7 +1048,7 @@ func (actor Actor) WriteCache() error {
}
for _, e := range collection.OrderedItems {
- if err := e.WriteCache(); err != nil {
+ if _, err := e.WriteCache(); err != nil {
return util.MakeError(err, "WriteCache")
}
}
@@ -1077,7 +1077,7 @@ func (actor Actor) MakeFollowActivity(follow string) (Activity, error) {
}
followActivity.Actor = &nactor
- followActivity.Object = &obj
+ followActivity.Object = obj
followActivity.Object.Actor = follow
followActivity.To = append(followActivity.To, follow)
diff --git a/activitypub/object.go b/activitypub/object.go
index 891cb23..e26514d 100644
--- a/activitypub/object.go
+++ b/activitypub/object.go
@@ -26,7 +26,7 @@ func (obj ObjectBase) CreateActivity(activityType string) (Activity, error) {
newActivity.Type = activityType
newActivity.Published = obj.Published
newActivity.Actor = &actor
- newActivity.Object = &obj
+ newActivity.Object = obj
for _, e := range obj.To {
if obj.Actor != e {
@@ -114,7 +114,7 @@ func (obj ObjectBase) DeleteAndRepliesRequest() error {
}
activity.Actor.Id = nObj.OrderedItems[0].Actor
- activity.Object = &nObj.OrderedItems[0]
+ activity.Object = nObj.OrderedItems[0]
objActor, _ := GetActor(nObj.OrderedItems[0].Actor)
followers, err := objActor.GetFollower()
@@ -736,7 +736,7 @@ func (obj ObjectBase) IsLocal() (bool, error) {
query := `select id from activitystream where id=$1`
if err := config.DB.QueryRow(query, obj.Id).Scan(&nID); err != nil {
- return false, util.MakeError(err, "GetType")
+ return false, nil
}
return true, nil
@@ -1138,7 +1138,7 @@ func (obj ObjectBase) WriteAttachmentCache() error {
return nil
}
-func (obj ObjectBase) WriteCache() error {
+func (obj ObjectBase) _WriteCache() error {
var id string
obj.Name = util.EscapeString(obj.Name)
@@ -1153,7 +1153,7 @@ func (obj ObjectBase) WriteCache() error {
query = `insert into cacheactivitystream (id, type, name, content, published, updated, attributedto, actor, tripcode, sensitive) values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)`
_, err = config.DB.Exec(query, obj.Id, obj.Type, obj.Name, obj.Content, obj.Published, obj.Updated, obj.AttributedTo, obj.Actor, obj.TripCode, obj.Sensitive)
- return util.MakeError(err, "WriteCache")
+ return util.MakeError(err, "_WriteCache")
}
return nil
@@ -1264,79 +1264,9 @@ func (obj ObjectBase) WriteReply() error {
return nil
}
-func (obj ObjectBase) WriteReplyCache() error {
- for i, e := range obj.InReplyTo {
- res, err := obj.InReplyTo[0].IsReplyInThread(e.Id)
- if err != nil {
- return util.MakeError(err, "WriteReplyCache")
- }
-
- if i == 0 || res {
- query := `select id from replies where id=$1`
-
- rows, err := config.DB.Query(query, obj.Id)
- if err != nil {
- return util.MakeError(err, "WriteReplyCache")
- }
- defer rows.Close()
-
- var id string
- rows.Next()
- err = rows.Scan(&id)
- if err != nil {
- return util.MakeError(err, "WriteReplyCache")
- } else if id != "" {
- return nil // TODO: error?
- }
-
- query = `insert into cachereplies (id, inreplyto) values ($1, $2)`
-
- _, err = config.DB.Exec(query, obj.Id, e.Id)
- if err != nil {
- return util.MakeError(err, "WriteReplyCache")
- }
- }
- }
-
- if len(obj.InReplyTo) < 1 {
- query := `insert into cachereplies (id, inreplyto) values ($1, $2)`
-
- _, err := config.DB.Exec(query, obj.Id, "")
- return util.MakeError(err, "WriteReplyCache")
- }
-
- return nil
-}
-
-func (obj ObjectBase) WriteReplyLocal(replyto string) error {
- var nID string
-
- query := `select id from replies where id=$1 and inreplyto=$2`
- if err := config.DB.QueryRow(query, obj.Id, replyto).Scan(&nID); err != nil {
- query := `insert into replies (id, inreplyto) values ($1, $2)`
- if _, err := config.DB.Exec(query, obj.Id, replyto); err != nil {
- return util.MakeError(err, "WriteReplyLocal")
- }
- }
-
- var val string
-
- query = `select inreplyto from replies where id=$1`
- if err := config.DB.QueryRow(query, replyto).Scan(&val); err != nil {
- updated := time.Now().UTC().Format(time.RFC3339)
- query := `update activitystream set updated=$1 where id=$2`
-
- if _, err := config.DB.Exec(query, updated, replyto); err != nil {
- return util.MakeError(err, "WriteReplyLocal")
- }
- }
-
- return nil
-}
-
-func (obj ObjectBase) WriteObjectToCache() (ObjectBase, error) {
+func (obj ObjectBase) WriteCache() (ObjectBase, error) {
if isBlacklisted, err := util.IsPostBlacklist(obj.Content); err != nil || isBlacklisted {
- config.Log.Println("\n\nBlacklist post blocked\n\n")
+ config.Log.Println("Blacklist post blocked")
return obj, util.MakeError(err, "WriteObjectToCache")
}
@@ -1350,14 +1280,14 @@ func (obj ObjectBase) WriteObjectToCache() (ObjectBase, error) {
obj.WriteCacheWithAttachment(obj.Attachment[i])
}
} else {
- obj.WriteCache()
+ obj._WriteCache()
}
obj.WriteReply()
if obj.Replies.OrderedItems != nil {
for _, e := range obj.Replies.OrderedItems {
- e.WriteCache()
+ e._WriteCache()
}
}
diff --git a/activitypub/util.go b/activitypub/util.go
index 274493f..a55e4c4 100644
--- a/activitypub/util.go
+++ b/activitypub/util.go
@@ -159,7 +159,7 @@ func GetActivityFromJson(ctx *fiber.Ctx) (Activity, error) {
}
nActivity.Name = respActivity.Name
- nActivity.Object = &jObj
+ nActivity.Object = jObj
} else if err != nil {
return nActivity, util.MakeError(err, "GetActivityFromJson")
}
@@ -351,7 +351,7 @@ func GetActorFromDB(id string) (Actor, error) {
err := config.DB.QueryRow(query, id).Scan(&nActor.Type, &nActor.Id, &nActor.Name, &nActor.PreferredUsername, &nActor.Inbox, &nActor.Outbox, &nActor.Following, &nActor.Followers, &nActor.Restricted, &nActor.Summary, &publicKeyPem)
if err != nil {
- return nActor, nil
+ return nActor, util.MakeError(err, "GetActorFromDB")
}
nActor.PublicKey, err = GetActorPemFromDB(publicKeyPem)