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
Changes from 10 commits
444cab6
a6ca631
76fe7b4
3346171
09763c7
460f734
e2c9ef4
ae09d6a
4af53c0
ac7ec11
70d0dee
8ccaa43
332544d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,9 +31,11 @@ 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 commentThe reason will be displayed to describe this comment to others. Learn more. Please update this test accordingly (i.e. add asserts for |
||
assert.EqualValues(t, 2, notfs[0].ID) | ||
assert.EqualValues(t, user.ID, notfs[0].UserID) | ||
assert.EqualValues(t, 4, notfs[1].ID) | ||
assert.EqualValues(t, user.ID, notfs[1].UserID) | ||
} | ||
} | ||
|
||
|
@@ -57,12 +59,12 @@ func TestNotification_GetIssue(t *testing.T) { | |
|
||
func TestGetNotificationCount(t *testing.T) { | ||
assert.NoError(t, PrepareTestDatabase()) | ||
user := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) | ||
cnt, err := GetNotificationCount(user, NotificationStatusUnread) | ||
user := AssertExistsAndLoadBean(t, &User{ID: 1}).(*User) | ||
cnt, err := GetNotificationCount(user, NotificationStatusRead) | ||
assert.NoError(t, err) | ||
assert.EqualValues(t, 0, cnt) | ||
|
||
cnt, err = GetNotificationCount(user, NotificationStatusRead) | ||
cnt, err = GetNotificationCount(user, NotificationStatusUnread) | ||
assert.NoError(t, err) | ||
assert.EqualValues(t, 1, cnt) | ||
} | ||
|
@@ -79,3 +81,21 @@ func TestSetNotificationStatus(t *testing.T) { | |
assert.Error(t, SetNotificationStatus(1, user, NotificationStatusRead)) | ||
assert.Error(t, SetNotificationStatus(NonexistentID, user, NotificationStatusRead)) | ||
} | ||
|
||
func TestUpdateNotificationStatuses(t *testing.T) { | ||
assert.NoError(t, PrepareTestDatabase()) | ||
user := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) | ||
notfUnread := AssertExistsAndLoadBean(t, | ||
&Notification{UserID: user.ID, Status: NotificationStatusUnread}).(*Notification) | ||
notfRead := AssertExistsAndLoadBean(t, | ||
&Notification{UserID: user.ID, Status: NotificationStatusRead}).(*Notification) | ||
notfPinned := AssertExistsAndLoadBean(t, | ||
&Notification{UserID: user.ID, Status: NotificationStatusPinned}).(*Notification) | ||
assert.NoError(t, UpdateNotificationStatuses(user, NotificationStatusUnread, NotificationStatusRead)) | ||
AssertExistsAndLoadBean(t, | ||
&Notification{ID: notfUnread.ID, Status: NotificationStatusRead}) | ||
AssertExistsAndLoadBean(t, | ||
&Notification{ID: notfRead.ID, Status: NotificationStatusRead}) | ||
AssertExistsAndLoadBean(t, | ||
&Notification{ID: notfPinned.ID, Status: NotificationStatusPinned}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Is check for There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Yes but there is NotificationUnreadCount check |
||
<form action="{{AppSubUrl}}/notifications/purge" method="POST" style="margin-left: auto;"> | ||
{{$.CsrfTokenHtml}} | ||
<button class="ui mini button primary" title='{{$.i18n.Tr "notification.mark_all_as_read"}}'> | ||
<i class="octicon octicon-checklist"></i> | ||
</button> | ||
</form> | ||
{{end}} | ||
</div> | ||
<div class="ui bottom attached active tab segment"> | ||
{{if eq (len .Notifications) 0}} | ||
|
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