aboutsummaryrefslogtreecommitdiff
path: root/database.go
diff options
context:
space:
mode:
authorFChannel <>2021-07-28 15:31:37 -0700
committerFChannel <>2021-07-28 15:31:37 -0700
commit98d72c9b94b5dda9a987dfe41552f00512d43574 (patch)
treeef75468766c6c5e2d4392cfc567eb29cb90d0c9d /database.go
parentea12d0f741455c542accf24a003a62ab85bfbfa3 (diff)
parent87fc54c9d41bdbe7eaa8769386776a3723580b34 (diff)
v0.0.13-release
Diffstat (limited to 'database.go')
-rw-r--r--database.go62
1 files changed, 58 insertions, 4 deletions
diff --git a/database.go b/database.go
index 1b2ec3d..db6a3d1 100644
--- a/database.go
+++ b/database.go
@@ -6,6 +6,7 @@ import (
"os"
"sort"
"strings"
+ "regexp"
"time"
"html/template"
@@ -554,6 +555,57 @@ func GetObjectFromDB(db *sql.DB, id string) Collection {
return nColl
}
+func GetObjectFromDBFromID(db *sql.DB, id string) Collection {
+ var nColl Collection
+ var result []ObjectBase
+
+ query := `select x.id, x.name, x.content, x.type, x.published, x.updated, x.attributedto, x.attachment, x.preview, x.actor, x.tripcode, x.sensitive from (select id, name, content, type, published, updated, attributedto, attachment, preview, actor, tripcode, sensitive from activitystream where id like $1 and type='Note' union select id, name, content, type, published, updated, attributedto, attachment, preview, actor, tripcode, sensitive from cacheactivitystream where id like $1 and type='Note') as x order by x.updated`
+
+ re := regexp.MustCompile(`f(\w+)\-`)
+ match := re.FindStringSubmatch(id)
+
+ if len(match) > 0 {
+ re := regexp.MustCompile(`(.+)\-`)
+ id = re.ReplaceAllString(id, "")
+ id = "%" + match[1] + "/" + id
+ }
+
+ rows, err := db.Query(query, id)
+
+ CheckError(err, "error query object from db")
+
+ defer rows.Close()
+ for rows.Next(){
+ var post ObjectBase
+ var actor Actor
+ var attachID string
+ var previewID string
+
+ err = rows.Scan(&post.Id, &post.Name, &post.Content, &post.Type, &post.Published, &post.Updated, &post.AttributedTo, &attachID, &previewID, &actor.Id, &post.TripCode, &post.Sensitive)
+
+ CheckError(err, "error scan object into post struct")
+
+ post.Actor = actor.Id
+
+ var postCnt int
+ var imgCnt int
+ post.Replies, postCnt, imgCnt = GetObjectRepliesDB(db, post)
+
+ post.Replies.TotalItems = postCnt
+ post.Replies.TotalImgs = imgCnt
+
+ post.Attachment = GetObjectAttachment(db, attachID)
+
+ post.Preview = GetObjectPreview(db, previewID)
+
+ result = append(result, post)
+ }
+
+ nColl.OrderedItems = result
+
+ return nColl
+}
+
func GetObjectFromDBCatalog(db *sql.DB, id string) Collection {
var nColl Collection
var result []ObjectBase
@@ -671,7 +723,7 @@ func GetObjectRepliesDBLimit(db *sql.DB, parent ObjectBase, limit int) (*Collect
rows, err := db.Query(query, parent.Id, limit)
- CheckError(err, "error with replies db query")
+ CheckError(err, "error with replies db query")
var postCount int
var attachCount int
@@ -692,7 +744,8 @@ func GetObjectRepliesDBLimit(db *sql.DB, parent ObjectBase, limit int) (*Collect
post.Actor = actor.Id
var postCnt int
- var imgCnt int
+ var imgCnt int
+
post.Replies, postCnt, imgCnt = GetObjectRepliesRepliesDB(db, post)
post.Replies.TotalItems = postCnt
@@ -742,7 +795,8 @@ func GetObjectRepliesDB(db *sql.DB, parent ObjectBase) (*CollectionBase, int, in
post.Actor = actor.Id
var postCnt int
- var imgCnt int
+ var imgCnt int
+
post.Replies, postCnt, imgCnt = GetObjectRepliesRepliesDB(db, post)
post.Replies.TotalItems = postCnt
@@ -805,7 +859,7 @@ func GetObjectRepliesRepliesDB(db *sql.DB, parent ObjectBase) (*CollectionBase,
query := `select count(x.id) over(), sum(case when RTRIM(x.attachment) = '' then 0 else 1 end) over(), x.id, x.name, x.content, x.type, x.published, x.attributedto, x.attachment, x.preview, x.actor, x.tripcode, x.sensitive from (select * from activitystream where id in (select id from replies where inreplyto=$1) and type='Note' union select * from cacheactivitystream where id in (select id from replies where inreplyto=$1) and type='Note') as x order by x.published asc`
- rows, err := db.Query(query, parent.Id)
+ rows, err := db.Query(query, parent.Id)
CheckError(err, "error with replies replies db query")