aboutsummaryrefslogtreecommitdiff
path: root/database.go
diff options
context:
space:
mode:
authorFChannel <>2021-06-06 00:07:31 -0700
committerFChannel <>2021-06-06 00:07:31 -0700
commit5ca02e417cb5e60b020c0e090ac56d1000aed1cd (patch)
treeed3812e6409be9ebc269ae6c9ef9576c669baa2f /database.go
parent84c008bc27510c63fb22d14c8559e05e12953418 (diff)
correct post ordering when following instance
Diffstat (limited to 'database.go')
-rw-r--r--database.go49
1 files changed, 48 insertions, 1 deletions
diff --git a/database.go b/database.go
index 13cd08f..4a1cb8b 100644
--- a/database.go
+++ b/database.go
@@ -297,6 +297,53 @@ func WriteObjectReplyToDB(db *sql.DB, obj ObjectBase) {
}
}
+func WriteActorObjectReplyToDB(db *sql.DB, obj ObjectBase) {
+ for _, e := range obj.InReplyTo {
+ query := `select id from replies where id=$1 and inreplyto=$2`
+
+ rows, err := db.Query(query, obj.Id, e.Id)
+
+ CheckError(err, "error selecting replies db")
+
+ defer rows.Close()
+
+ var id string
+ rows.Next()
+ rows.Scan(&id)
+
+ if id == "" {
+ query := `insert into replies (id, inreplyto) values ($1, $2)`
+
+ _, err := db.Exec(query, obj.Id, e.Id)
+
+
+ CheckError(err, "error inserting replies db")
+ }
+ }
+
+ if len(obj.InReplyTo) < 1 {
+ query := `select id from replies where id=$1 and inreplyto=$2`
+
+ rows, err := db.Query(query, obj.Id, "")
+
+ CheckError(err, "error selecting replies db")
+
+ defer rows.Close()
+
+ var id string
+ rows.Next()
+ rows.Scan(&id)
+
+ if id == "" {
+ query := `insert into replies (id, inreplyto) values ($1, $2)`
+
+ _, err := db.Exec(query, obj.Id, "")
+
+ CheckError(err, "error inserting replies db")
+ }
+ }
+}
+
func WriteWalletToDB(db *sql.DB, obj ObjectBase) {
for _, e := range obj.Option {
if e == "wallet" {
@@ -459,7 +506,7 @@ func GetObjectFromDB(db *sql.DB, id string) Collection {
var nColl Collection
var result []ObjectBase
- query := `select id, name, content, type, published, updated, attributedto, attachment, preview, actor, tripcode from activitystream where actor=$1 and id in (select id from replies where inreplyto='') and type='Note' order by updated asc`
+ query := `select id, name, content, type, published, updated, attributedto, attachment, preview, actor, tripcode from activitystream where actor=$1 and id in (select id from replies where inreplyto='') and type='Note' order by updated desc`
rows, err := db.Query(query, id)