diff options
author | FChannel <> | 2022-06-18 13:57:30 -0700 |
---|---|---|
committer | FChannel <> | 2022-06-19 12:53:29 -0700 |
commit | 25829d2d0e379c323b8f2ae6e7c2aad7548f0a30 (patch) | |
tree | c828eb5bb04ce04141c717c26b637a59b32ab979 /activitypub/object.go | |
parent | f3d1683d6562afb30522afb98fb3a22456473275 (diff) |
sticky and lock implemented
Diffstat (limited to 'activitypub/object.go')
-rw-r--r-- | activitypub/object.go | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/activitypub/object.go b/activitypub/object.go index 5eb8e67..acbe4a1 100644 --- a/activitypub/object.go +++ b/activitypub/object.go @@ -367,6 +367,9 @@ func (obj ObjectBase) GetCollectionLocal() (Collection, error) { return nColl, util.MakeError(err, "GetCollectionLocal") } + post.Sticky, _ = post.IsSticky() + post.Locked, _ = post.IsLocked() + post.Actor = actor.Id if post.InReplyTo, err = post.GetInReplyTo(); err != nil { @@ -462,6 +465,9 @@ func (obj ObjectBase) GetCollectionFromPath() (Collection, error) { return nColl, nil } + post.Sticky, _ = post.IsSticky() + post.Locked, _ = post.IsLocked() + post.Actor = actor.Id if post.InReplyTo, err = post.GetInReplyTo(); err != nil { @@ -1361,3 +1367,96 @@ func (obj ObjectBase) WriteWithAttachment(attachment ObjectBase) { panic(e) } } + +func (obj ObjectBase) MarkSticky(actorID string) error { + var count int + + var query = `select count(id) from replies where inreplyto='' and id=$1` + if err := config.DB.QueryRow(query, obj.Id).Scan(&count); err != nil { + return util.MakeError(err, "MarkSticky") + } + + if count == 1 { + var nCount int + query = `select count(activity_id) from sticky where activity_id=$1` + if err := config.DB.QueryRow(query, obj.Id).Scan(&nCount); err != nil { + return util.MakeError(err, "MarkSticky") + } + + if nCount > 0 { + query = `delete from sticky where activity_id=$1` + if _, err := config.DB.Exec(query, obj.Id); err != nil { + return util.MakeError(err, "MarkSticky") + } + } else { + query = `insert into sticky (actor_id, activity_id) values ($1, $2)` + if _, err := config.DB.Exec(query, actorID, obj.Id); err != nil { + return util.MakeError(err, "MarkSticky") + } + } + } + + return nil +} + +func (obj ObjectBase) MarkLocked(actorID string) error { + var count int + + var query = `select count(id) from replies where inreplyto='' and id=$1` + if err := config.DB.QueryRow(query, obj.Id).Scan(&count); err != nil { + return util.MakeError(err, "MarkLocked") + } + + if count == 1 { + var nCount int + + query = `select count(activity_id) from locked where activity_id=$1` + if err := config.DB.QueryRow(query, obj.Id).Scan(&nCount); err != nil { + return util.MakeError(err, "MarkLocked") + } + + if nCount > 0 { + query = `delete from locked where activity_id=$1` + if _, err := config.DB.Exec(query, obj.Id); err != nil { + return util.MakeError(err, "MarkLocked") + } + } else { + query = `insert into locked (actor_id, activity_id) values ($1, $2)` + if _, err := config.DB.Exec(query, actorID, obj.Id); err != nil { + return util.MakeError(err, "MarkLocked") + } + } + } + + return nil +} + +func (obj ObjectBase) IsSticky() (bool, error) { + var count int + + query := `select count(activity_id) from sticky where activity_id=$1 ` + if err := config.DB.QueryRow(query, obj.Id).Scan(&count); err != nil { + return false, util.MakeError(err, "IsSticky") + } + + if count != 0 { + return true, nil + } + + return false, nil +} + +func (obj ObjectBase) IsLocked() (bool, error) { + var count int + + query := `select count(activity_id) from locked where activity_id=$1 ` + if err := config.DB.QueryRow(query, obj.Id).Scan(&count); err != nil { + return false, util.MakeError(err, "IsSticky") + } + + if count != 0 { + return true, nil + } + + return false, nil +} |