diff --git a/common/topic.go b/common/topic.go index 8979dcea..f16c3ee9 100644 --- a/common/topic.go +++ b/common/topic.go @@ -328,12 +328,33 @@ func (t *Topic) Unlike(uid int) error { return nil } +func handleLikedTopicReplies(tid int) error { + rows, err := userStmts.getLikedRepliesOfTopic.Query(tid) + if err != nil { + return err + } + defer rows.Close() + + for rows.Next() { + var rid int + err := rows.Scan(&rid) + if err != nil { + return err + } + _, err = replyStmts.deleteLikesForReply.Exec(rid) + if err != nil { + return err + } + } + + return rows.Err() +} + // TODO: Use a transaction here func (t *Topic) Delete() error { creator, err := Users.Get(t.CreatedBy) if err == nil { - wcount := WordCount(t.Content) - err = creator.DecreasePostStats(wcount, true) + err = creator.DecreasePostStats(WordCount(t.Content), true) if err != nil { return err } @@ -355,6 +376,10 @@ func (t *Topic) Delete() error { if err != nil { return err } + err = handleLikedTopicReplies(t.ID) + if err != nil { + return err + } _, err = topicStmts.deleteActivitySubs.Exec(t.ID) if err != nil { return err diff --git a/common/user.go b/common/user.go index f8e955b3..5915f24f 100644 --- a/common/user.go +++ b/common/user.go @@ -330,28 +330,6 @@ func (u *User) DeletePosts() error { defer TopicListThaw.Thaw() defer u.CacheRemove() - handleLikedTopicReplies := func(tid int) error { - rows, err := userStmts.getLikedRepliesOfTopic.Query(tid) - if err != nil { - return err - } - defer rows.Close() - - for rows.Next() { - var rid int - err := rows.Scan(&rid) - if err != nil { - return err - } - _, err = replyStmts.deleteLikesForReply.Exec(rid) - if err != nil { - return err - } - } - - return rows.Err() - } - updatedForums := make(map[int]int) // forum[count] tc := Topics.GetCache() for rows.Next() {