aboutsummaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorFChannel <>2022-05-06 22:45:27 -0700
committerFChannel <>2022-06-19 12:53:29 -0700
commit39012c6b17073f6933a5ead8beed64df555f7348 (patch)
tree7784d092fe196a9051c81cf6833997607ad2d268 /db
parentaf542e339e5a611d2a1b5876450bee841b577640 (diff)
converting functions to activitypub object functions
Diffstat (limited to 'db')
-rw-r--r--db/database.go55
-rw-r--r--db/follow.go26
-rw-r--r--db/verification.go2
3 files changed, 41 insertions, 42 deletions
diff --git a/db/database.go b/db/database.go
index eb0bb98..4c97fe5 100644
--- a/db/database.go
+++ b/db/database.go
@@ -388,7 +388,7 @@ func IsInactiveTimestamp(timeStamp string) bool {
func ArchivePosts(actor activitypub.Actor) error {
if actor.Id != "" && actor.Id != config.Domain {
- col, err := activitypub.GetAllActorArchiveDB(actor.Id, 165)
+ col, err := actor.GetAllArchive(165)
if err != nil {
return err
}
@@ -409,27 +409,6 @@ func ArchivePosts(actor activitypub.Actor) error {
return nil
}
-func UnArchiveLast(actorId string) error {
- col, err := activitypub.GetActorCollectionDBTypeLimit(actorId, "Archive", 1)
- if err != nil {
- return err
- }
-
- for _, e := range col.OrderedItems {
- for _, k := range e.Replies.OrderedItems {
- if err := activitypub.UpdateObjectTypeDB(k.Id, "Note"); err != nil {
- return err
- }
- }
-
- if err := activitypub.UpdateObjectTypeDB(e.Id, "Note"); err != nil {
- return err
- }
- }
-
- return nil
-}
-
func IsReplyInThread(inReplyTo string, id string) (bool, error) {
obj, _, err := webfinger.CheckValidActivity(inReplyTo)
if err != nil {
@@ -628,17 +607,19 @@ func GetActorReported(w http.ResponseWriter, r *http.Request, id string) error {
return err
}
+ actor, _ := activitypub.GetActorFromDB(id)
+
var following activitypub.Collection
var err error
following.AtContext.Context = "https://www.w3.org/ns/activitystreams"
following.Type = "Collection"
- following.TotalItems, err = activitypub.GetActorReportedTotal(id)
+ following.TotalItems, err = actor.GetReportedTotal()
if err != nil {
return err
}
- following.Items, err = activitypub.GetActorReportedDB(id)
+ following.Items, err = actor.GetReported()
if err != nil {
return err
}
@@ -686,8 +667,8 @@ func DeleteObjectRequest(id string) error {
return err
}
activity.Actor = &actor
-
- followers, err := activitypub.GetActorFollowDB(obj.Actor)
+ objActor, _ := webfinger.GetActor(obj.Actor)
+ followers, err := objActor.GetFollow()
if err != nil {
return err
}
@@ -696,7 +677,7 @@ func DeleteObjectRequest(id string) error {
activity.To = append(activity.To, e.Id)
}
- following, err := activitypub.GetActorFollowingDB(obj.Actor)
+ following, err := objActor.GetFollowing()
if err != nil {
return err
}
@@ -727,7 +708,8 @@ func DeleteObjectAndRepliesRequest(id string) error {
activity.Object = &obj.OrderedItems[0]
- followers, err := activitypub.GetActorFollowDB(obj.OrderedItems[0].Actor)
+ objActor, _ := webfinger.GetActor(obj.OrderedItems[0].Actor)
+ followers, err := objActor.GetFollow()
if err != nil {
return err
}
@@ -735,7 +717,7 @@ func DeleteObjectAndRepliesRequest(id string) error {
activity.To = append(activity.To, e.Id)
}
- following, err := activitypub.GetActorFollowingDB(obj.OrderedItems[0].Actor)
+ following, err := objActor.GetFollowing()
if err != nil {
return err
}
@@ -746,3 +728,18 @@ func DeleteObjectAndRepliesRequest(id string) error {
return MakeActivityRequest(activity)
}
+
+// root actor is used to follow remote feeds that are not local
+//name, prefname, summary, auth requirements, restricted
+func InitInstance() {
+ if config.InstanceName != "" {
+ if _, err := CreateNewBoardDB(*activitypub.CreateNewActor("", config.InstanceName, config.InstanceSummary, config.AuthReq, false)); err != nil {
+ //panic(err)
+ }
+
+ if config.PublicIndexing == "true" {
+ // TODO: comment out later
+ //AddInstanceToIndex(config.Domain)
+ }
+ }
+}
diff --git a/db/follow.go b/db/follow.go
index 3f7868d..e3c0583 100644
--- a/db/follow.go
+++ b/db/follow.go
@@ -40,7 +40,8 @@ func SetActorFollowingDB(activity activitypub.Activity) (activitypub.Activity, e
var query string
alreadyFollowing := false
alreadyFollower := false
- following, err := activitypub.GetActorFollowingDB(activity.Object.Actor)
+ objActor, _ := webfinger.GetActor(activity.Object.Actor)
+ following, err := objActor.GetFollowing()
if err != nil {
return activity, err
}
@@ -77,7 +78,7 @@ func SetActorFollowingDB(activity activitypub.Activity) (activitypub.Activity, e
query = `delete from following where id=$1 and following=$2`
activity.Summary = activity.Object.Actor + " Unfollowing " + activity.Actor.Id
if res, err := activitypub.IsActorLocal(activity.Actor.Id); err == nil && !res {
- go activitypub.DeleteActorCache(activity.Actor.Id)
+ go activity.Actor.DeleteCache()
} else {
return activity, err
}
@@ -108,13 +109,14 @@ func SetActorFollowingDB(activity activitypub.Activity) (activitypub.Activity, e
return activity, nil
}
-func AutoFollow(actor string) error {
- following, err := activitypub.GetActorFollowingDB(actor)
+func AutoFollow(actorID string) error {
+ actor, _ := webfinger.GetActor(actorID)
+ following, err := actor.GetFollowing()
if err != nil {
return err
}
- follower, err := activitypub.GetActorFollowDB(actor)
+ follower, err := actor.GetFollow()
if err != nil {
return err
}
@@ -128,8 +130,8 @@ func AutoFollow(actor string) error {
}
}
- if !isFollowing && e.Id != config.Domain && e.Id != actor {
- followActivity, err := MakeFollowActivity(actor, e.Id)
+ if !isFollowing && e.Id != config.Domain && e.Id != actor.Id {
+ followActivity, err := MakeFollowActivity(actor.Id, e.Id)
if err != nil {
return err
}
@@ -204,7 +206,7 @@ func MakeActivityRequestOutbox(activity activitypub.Activity) error {
path = re.ReplaceAllString(path, "")
sig := fmt.Sprintf("(request-target): %s %s\nhost: %s\ndate: %s", "post", path, instance, date)
- encSig, err := activitypub.ActivitySign(*activity.Actor, sig)
+ encSig, err := activity.Actor.ActivitySign(sig)
if err != nil {
return err
}
@@ -246,7 +248,7 @@ func MakeActivityRequest(activity activitypub.Activity) error {
path = re.ReplaceAllString(path, "")
sig := fmt.Sprintf("(request-target): %s %s\nhost: %s\ndate: %s", "post", path, instance, date)
- encSig, err := activitypub.ActivitySign(*activity.Actor, sig)
+ encSig, err := activity.Actor.ActivitySign(sig)
if err != nil {
return err
}
@@ -271,15 +273,15 @@ func MakeActivityRequest(activity activitypub.Activity) error {
return nil
}
-func SendToFollowers(actor string, activity activitypub.Activity) error {
- nActor, err := activitypub.GetActorFromDB(actor)
+func SendToFollowers(actorID string, activity activitypub.Activity) error {
+ nActor, err := activitypub.GetActorFromDB(actorID)
if err != nil {
return err
}
activity.Actor = &nActor
- followers, err := activitypub.GetActorFollowDB(actor)
+ followers, err := nActor.GetFollow()
if err != nil {
return err
}
diff --git a/db/verification.go b/db/verification.go
index a178d52..eea22ea 100644
--- a/db/verification.go
+++ b/db/verification.go
@@ -464,7 +464,7 @@ func HasBoardAccess(verify Verify) (bool, error) {
}
func BoardHasAuthType(board string, auth string) (bool, error) {
- authTypes, err := activitypub.GetActorAuth(board)
+ authTypes, err := util.GetBoardAuth(board)
if err != nil {
return false, err
}