-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add 'mark all read' option to notifications #3097
Conversation
Signed-off-by: Sasha Varlamov <sasha@sashavarlamov.com>
Signed-off-by: Sasha Varlamov <sasha@sashavarlamov.com>
Signed-off-by: Sasha Varlamov <sasha@sashavarlamov.com>
Not sure why CI build is failing... The commands run fine on my local dev box... Any thoughts on what I might be doing wrong? |
Try force pushing or squash commits. There is drone bug that it builds wrong commit sometime |
@@ -14,6 +14,14 @@ | |||
<a href="{{AppSubUrl}}/notifications?q=read" class="{{if eq .Status 2}}active{{end}} item"> | |||
{{.i18n.Tr "notification.read"}} | |||
</a> | |||
{{if and (gt (len .Notifications) 0) (eq .Status 1) (.NotificationUnreadCount)}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is check for gt (len .Notifications) 0
really needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I felt as though it should only show if there are unread notifications -- otherwise, the mark all as read wouldn't do anything as there's nothing to mark
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes but there is NotificationUnreadCount check
Drone build failure does not seems related to your changes |
@@ -31,7 +31,7 @@ func TestNotificationsForUser(t *testing.T) { | |||
statuses := []NotificationStatus{NotificationStatusRead, NotificationStatusUnread} | |||
notfs, err := NotificationsForUser(user, statuses, 1, 10) | |||
assert.NoError(t, err) | |||
if assert.Len(t, notfs, 1) { | |||
if assert.Len(t, notfs, 2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update this test accordingly (i.e. add asserts for notfs[1]
)
models/notification.go
Outdated
@@ -311,3 +311,14 @@ func getNotificationByID(notificationID int64) (*Notification, error) { | |||
|
|||
return notification, nil | |||
} | |||
|
|||
// SwapNotificationStatuses swaps the statuses of all of a user's notifications that are of the currentStatus type | |||
func SwapNotificationStatuses(user *User, currentStatus NotificationStatus, desiredStatus NotificationStatus) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe UpdateNotificationStatuses
is a better name? My first thought when I saw the name was that it replaced all occurrences of status A with status B, and replaced all occurrences of status B with status A.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, will refactor accordingly
drone restarted |
Codecov Report
@@ Coverage Diff @@
## master #3097 +/- ##
==========================================
+ Coverage 34.03% 34.07% +0.03%
==========================================
Files 273 273
Lines 40002 40018 +16
==========================================
+ Hits 13615 13635 +20
Misses 24449 24449
+ Partials 1938 1934 -4
Continue to review full report at Codecov.
|
Signed-off-by: Sasha Varlamov <sasha@sashavarlamov.com> Format method comments Signed-off-by: Sasha Varlamov <sasha@sashavarlamov.com> Tests for reactions (go-gitea#3083) * Unit tests for reactions * Fix import order Signed-off-by: Lauris Bukšis-Haberkorns <lauris@nix.lv> Fix reaction possition when there is attachments (go-gitea#3099) Refactor notifications swap function
models/notification.go
Outdated
// UpdateNotificationStatuses updates the statuses of all of a user's notifications that are of the currentStatus type to the desiredStatus | ||
func UpdateNotificationStatuses(user *User, currentStatus NotificationStatus, desiredStatus NotificationStatus) error { | ||
n := &Notification{Status: desiredStatus, UpdatedBy: user.ID} | ||
n.BeforeUpdate() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BeforeUpdate will be invoked by xorm automatically, it's unnecessary to call it manually.
@lunny - Fixed per your change request on the |
routers/user/notification.go
Outdated
func NotificationPurgePost(c *context.Context) { | ||
err := models.UpdateNotificationStatuses(c.User, models.NotificationStatusUnread, models.NotificationStatusRead) | ||
if err != nil { | ||
c.Handle(500, "ErrPurgeNotificationsForUser", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Please update error message to "UpdateNotificationStatuses", for consistency with existing handlers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Except unneeded gt (len .Notifications) 0
found by @lafriks. LGTM
LGTM |
make L-G-T-M work |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one nit
models/notification.go
Outdated
// UpdateNotificationStatuses updates the statuses of all of a user's notifications that are of the currentStatus type to the desiredStatus | ||
func UpdateNotificationStatuses(user *User, currentStatus NotificationStatus, desiredStatus NotificationStatus) error { | ||
n := &Notification{Status: desiredStatus, UpdatedBy: user.ID} | ||
// n.BeforeUpdate() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: please remove commented-out code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch -- thanks
LGTM |
1 similar comment
LGTM |
Signed-off-by: Sasha Varlamov sasha@sashavarlamov.com
Targeting: #3034