diff --git a/pkg/controller/api/likes.go b/pkg/controller/api/likes.go index 6b11835..3e626f4 100644 --- a/pkg/controller/api/likes.go +++ b/pkg/controller/api/likes.go @@ -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{ diff --git a/pkg/models/notification.go b/pkg/models/notification.go index 47af9d4..1fa7f4b 100644 --- a/pkg/models/notification.go +++ b/pkg/models/notification.go @@ -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 {