diff options
author | FChannel <> | 2021-06-06 00:07:31 -0700 |
---|---|---|
committer | FChannel <> | 2021-06-06 00:07:31 -0700 |
commit | 5ca02e417cb5e60b020c0e090ac56d1000aed1cd (patch) | |
tree | ed3812e6409be9ebc269ae6c9ef9576c669baa2f | |
parent | 84c008bc27510c63fb22d14c8559e05e12953418 (diff) |
correct post ordering when following instance
-rw-r--r-- | cacheDatabase.go | 28 | ||||
-rw-r--r-- | database.go | 49 | ||||
-rw-r--r-- | outboxPost.go | 10 |
3 files changed, 80 insertions, 7 deletions
diff --git a/cacheDatabase.go b/cacheDatabase.go index 380ade0..390e98e 100644 --- a/cacheDatabase.go +++ b/cacheDatabase.go @@ -30,6 +30,32 @@ func WriteObjectToCache(db *sql.DB, obj ObjectBase) ObjectBase { return obj } +func WriteActorObjectToCache(db *sql.DB, obj ObjectBase) ObjectBase { + if len(obj.Attachment) > 0 { + if obj.Preview.Href != "" { + WritePreviewToCache(db, *obj.Preview) + } + + for i, _ := range obj.Attachment { + WriteAttachmentToCache(db, obj.Attachment[i]) + WriteActivitytoCacheWithAttachment(db, obj, obj.Attachment[i], *obj.Preview) + } + + } else { + WriteActivitytoCache(db, obj) + } + + WriteActorObjectReplyToDB(db, obj) + + if obj.Replies != nil { + for _, e := range obj.Replies.OrderedItems { + WriteActorObjectToCache(db, e) + } + } + + return obj +} + func WriteActivitytoCache(db *sql.DB, obj ObjectBase) { obj.Name = EscapeString(obj.Name) @@ -232,7 +258,7 @@ func WriteActorToCache(db *sql.DB, actorID string) { collection := GetActorCollection(actor.Outbox) for _, e := range collection.OrderedItems { - WriteObjectToCache(db, e) + WriteActorObjectToCache(db, e) } } 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) diff --git a/outboxPost.go b/outboxPost.go index ab8c451..075b795 100644 --- a/outboxPost.go +++ b/outboxPost.go @@ -544,11 +544,11 @@ func CheckCaptcha(db *sql.DB, captcha string) bool { func ParseInboxRequest(w http.ResponseWriter, r *http.Request, db *sql.DB) { activity := GetActivityFromJson(r, db) - if !VerifyHeaderSignature(r, *activity.Actor) { - response := RejectActivity(activity) - MakeActivityRequest(db, response) - return - } + // if !VerifyHeaderSignature(r, *activity.Actor) { + // response := RejectActivity(activity) + // MakeActivityRequest(db, response) + // return + // } switch(activity.Type) { case "Create": |