Fix removing likes notification

pull/38/head
Noah Petherbridge 2024-01-20 15:08:36 -08:00
parent a9cc758624
commit ef8abec7bf
2 changed files with 11 additions and 1 deletions

View File

@ -178,7 +178,7 @@ func Likes() http.HandlerFunc {
}
// Remove the target's notification about this like.
models.RemoveSpecificNotification(targetUser.ID, models.NotificationLike, req.TableName, tableID)
models.RemoveSpecificNotificationAboutUser(targetUser.ID, currentUser.ID, models.NotificationLike, req.TableName, tableID)
} else {
if err := models.AddLike(currentUser, req.TableName, tableID); err != nil {
SendJSON(w, http.StatusBadRequest, Response{

View File

@ -120,6 +120,16 @@ func RemoveSpecificNotification(userID uint64, t NotificationType, tableName str
return result.Error
}
// RemoveSpecificNotificationAboutUser to remove a specific table_name/id notification about a user,
// e.g. when removing a like on a photo.
func RemoveSpecificNotificationAboutUser(userID, aboutUserID uint64, t NotificationType, tableName string, tableID uint64) error {
result := DB.Where(
"user_id = ? AND about_user_id = ? AND type = ? AND table_name = ? AND table_id = ?",
userID, aboutUserID, t, tableName, tableID,
).Delete(&Notification{})
return result.Error
}
// RemoveSpecificNotificationBulk can remove notifications about several TableIDs of the same type,
// e.g. to bulk remove new private photo upload notifications.
func RemoveSpecificNotificationBulk(users []*User, t NotificationType, tableName string, tableIDs []uint64) error {