diff options
-rw-r--r-- | CacheDatabase.go | 2 | ||||
-rw-r--r-- | Database.go | 34 | ||||
-rw-r--r-- | OutboxPost.go | 8 | ||||
-rw-r--r-- | main.go | 18 |
4 files changed, 49 insertions, 13 deletions
diff --git a/CacheDatabase.go b/CacheDatabase.go index e6a447b..d5f9c97 100644 --- a/CacheDatabase.go +++ b/CacheDatabase.go @@ -632,6 +632,8 @@ func DeleteActorCache(db *sql.DB, actorID string) { rows, err := db.Query(query, actorID) + + CheckError(err, "error selecting actors activity from cache") defer rows.Close() diff --git a/Database.go b/Database.go index 80f62fe..640b941 100644 --- a/Database.go +++ b/Database.go @@ -651,10 +651,30 @@ func GetObjectRepliesRepliesDB(db *sql.DB, parent ObjectBase) (*CollectionBase, return &nColl, 0, 0 } +func CheckIfObjectOP(db *sql.DB, id string) bool { + + var count int + + query := `select count(id) from replies where inreplyto='' and id=$1 ` + + rows, err := db.Query(query, id) + CheckError(err, "error checking if ID is OP") + + defer rows.Close() + rows.Next() + rows.Scan(&count) + + if count > 0 { + return true + } + + return false +} + func GetObjectRepliesDBCount(db *sql.DB, parent ObjectBase) (int, int) { var countId int - var countImg int + var countImg int query := `select count(id) from replies where inreplyto=$1 and id in (select id from activitystream where type='Note')` @@ -889,8 +909,6 @@ func DeleteObjectFromDB(db *sql.DB, id string) { _, err := db.Exec(query, datetime, datetime, id) CheckError(err, "error with delete object") - DeleteObjectsInReplyTo(db, id) - DeleteObjectRepliedTo(db, id) } func DeleteObjectsInReplyTo(db *sql.DB, id string) { @@ -908,6 +926,7 @@ func DeleteObjectRepliesFromDB(db *sql.DB, id string) { _, err := db.Exec(query, datetime, datetime, id) CheckError(err, "error with delete object replies") + } func DeleteObject(db *sql.DB, id string) { @@ -917,11 +936,12 @@ func DeleteObject(db *sql.DB, id string) { } + DeleteObjectRequest(db, id) DeleteReportActivity(db, id) DeleteAttachmentFromFile(db, id) DeletePreviewFromFile(db, id) DeleteObjectFromDB(db, id) - DeleteObjectRequest(db, id) + DeleteObjectRepliedTo(db, id) } func DeleteObjectAndReplies(db *sql.DB, id string) { @@ -930,14 +950,16 @@ func DeleteObjectAndReplies(db *sql.DB, id string) { return } + DeleteObjectAndRepliesRequest(db, id) DeleteReportActivity(db, id) DeleteAttachmentFromFile(db, id) - DeletePreviewFromFile(db, id) + DeletePreviewFromFile(db, id) + DeleteObjectRepliedTo(db, id) + DeleteObjectsInReplyTo(db, id) DeleteObjectRepliesFromDB(db, id) DeleteAttachmentRepliesFromDB(db, id) DeletePreviewRepliesFromDB(db, id) DeleteObjectFromDB(db, id) - DeleteObjectAndRepliesRequest(db, id) } func GetRandomCaptcha(db *sql.DB) string{ diff --git a/OutboxPost.go b/OutboxPost.go index 9910761..7349b16 100644 --- a/OutboxPost.go +++ b/OutboxPost.go @@ -554,8 +554,12 @@ func ParseInboxRequest(w http.ResponseWriter, r *http.Request, db *sql.DB) { for _, e := range activity.To { actor := GetActorFromDB(db, e) if actor.Id != "" { - TombstoneObjectFromCache(db, activity.Object.Id) - return + for _, e := range activity.Object.Replies.OrderedItems { + TombstoneObjectFromCache(db, e.Id) + DeleteObject(db, e.Id) + } + TombstoneObjectFromCache(db, activity.Object.Id) + break } } break @@ -700,9 +700,9 @@ func main() { obj.Id = id obj.Actor = &actor - count, _ := GetObjectRepliesDBCount(db, obj) + isOP := CheckIfObjectOP(db, obj.Id) - if count == 0 { + if !isOP { DeleteObject(db, obj.Id) http.Redirect(w, r, r.Header.Get("Referer"), http.StatusSeeOther) return @@ -1771,14 +1771,22 @@ func DeleteObjectAndRepliesRequest(db *sql.DB, id string) { activity := CreateActivity("Delete", nObj) - obj := GetObjectFromPath(db, id) + obj := GetObjectByIDFromDB(db, id) + + activity.Actor.Id = obj.OrderedItems[0].Actor.Id - nObj.Actor = obj.Actor - followers := GetActorFollowDB(db, obj.Actor.Id) + activity.Object = &obj.OrderedItems[0] + + followers := GetActorFollowDB(db, obj.OrderedItems[0].Actor.Id) for _, e := range followers { activity.To = append(activity.To, e.Id) } + following := GetActorFollowingDB(db, obj.OrderedItems[0].Actor.Id) + for _, e := range following { + activity.To = append(activity.To, e.Id) + } + MakeActivityRequest(db, activity) } |