Bugfix when counting deleted messages

This commit is contained in:
Noah 2025-07-12 11:44:38 -07:00
parent eb458a11ba
commit 30d5d7ed28

View File

@ -112,12 +112,18 @@ func (dm DirectMessage) ClearMessages(username string) (int, error) {
return 0, ErrNotInitialized return 0, ErrNotInitialized
} }
var placeholders = []interface{}{ var (
time.Now(), likes = []string{
fmt.Sprintf("@%s:%%", username), // `@alice:%` fmt.Sprintf("@%s:%%", username), // `@alice:%`
fmt.Sprintf("%%:@%s", username), // `%:@alice` fmt.Sprintf("%%:@%s", username), // `%:@alice`
username, }
} placeholders = []interface{}{
time.Now(),
likes[0],
likes[1],
username,
}
)
// Count all the messages we'll delete. // Count all the messages we'll delete.
var ( var (
@ -125,9 +131,11 @@ func (dm DirectMessage) ClearMessages(username string) (int, error) {
row = DB.Raw(` row = DB.Raw(`
SELECT COUNT(message_id) SELECT COUNT(message_id)
FROM direct_messages FROM direct_messages
WHERE (channel_id LIKE ? OR channel_id LIKE ?) WHERE (
OR username = ? (channel_id LIKE ? OR channel_id LIKE ?)
`, placeholders...) OR username = ?
) AND deleted_at IS NULL
`, likes[0], likes[1], username)
) )
if res := row.Scan(&count); res.Error != nil && false { if res := row.Scan(&count); res.Error != nil && false {
return 0, res.Error return 0, res.Error