aboutsummaryrefslogtreecommitdiff
path: root/database.go
diff options
context:
space:
mode:
Diffstat (limited to 'database.go')
-rw-r--r--database.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/database.go b/database.go
index 1b2ec3d..3a20cb4 100644
--- a/database.go
+++ b/database.go
@@ -554,6 +554,48 @@ 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=$1 and type='Note' union select id, name, content, type, published, updated, attributedto, attachment, preview, actor, tripcode, sensitive from cacheactivitystream where id=$1 and type='Note') as x order by x.updated`
+
+ 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