Skip to content
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

Merged
merged 13 commits into from
Dec 7, 2017
Merged

Conversation

svarlamov
Copy link
Contributor

Signed-off-by: Sasha Varlamov sasha@sashavarlamov.com

Targeting: #3034

Signed-off-by: Sasha Varlamov <sasha@sashavarlamov.com>
Signed-off-by: Sasha Varlamov <sasha@sashavarlamov.com>
Signed-off-by: Sasha Varlamov <sasha@sashavarlamov.com>
@svarlamov
Copy link
Contributor Author

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?

@tboerger tboerger added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Dec 5, 2017
@lafriks
Copy link
Member

lafriks commented Dec 5, 2017

Try force pushing or squash commits. There is drone bug that it builds wrong commit sometime

@lafriks lafriks added the type/feature Completely new functionality. Can only be merged if feature freeze is not active. label Dec 5, 2017
@lafriks lafriks added this to the 1.4.0 milestone Dec 5, 2017
@@ -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)}}
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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

@lafriks
Copy link
Member

lafriks commented Dec 5, 2017

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) {
Copy link
Member

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])

@@ -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 {
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will refactor accordingly

@lunny
Copy link
Member

lunny commented Dec 6, 2017

drone restarted

@codecov-io
Copy link

codecov-io commented Dec 6, 2017

Codecov Report

Merging #3097 into master will increase coverage by 0.03%.
The diff coverage is 50%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
routers/user/notification.go 45.78% <0%> (-0.89%) ⬇️
models/notification.go 76.68% <100%> (+0.87%) ⬆️
routers/routes/routes.go 87.05% <100%> (+0.02%) ⬆️
modules/process/manager.go 76.81% <0%> (-4.35%) ⬇️
models/repo.go 38.34% <0%> (+0.18%) ⬆️
models/repo_list.go 67.18% <0%> (+1.56%) ⬆️
models/repo_indexer.go 49% <0%> (+3.46%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1ed7f18...332544d. Read the comment docs.

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
// 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()
Copy link
Member

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.

@svarlamov
Copy link
Contributor Author

@lunny - Fixed per your change request on the BeforeUpdate call... My issue before was that I still needed to explicitly specify cols, so in one shot I also called it manually, but now I get the process...

func NotificationPurgePost(c *context.Context) {
err := models.UpdateNotificationStatuses(c.User, models.NotificationStatusUnread, models.NotificationStatusRead)
if err != nil {
c.Handle(500, "ErrPurgeNotificationsForUser", err)
Copy link
Member

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.

Copy link
Member

@sapk sapk left a 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

@lunny
Copy link
Member

lunny commented Dec 7, 2017

LGTM

@lunny
Copy link
Member

lunny commented Dec 7, 2017

make L-G-T-M work

@tboerger tboerger added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Dec 7, 2017
@svarlamov
Copy link
Contributor Author

Dropped gt (len .Notifications) 0 per suggestions from @lafriks @lunny @sapk

Copy link
Member

@ethantkoenig ethantkoenig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one nit

// 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()
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch -- thanks

@ethantkoenig
Copy link
Member

LGTM

1 similar comment
@lafriks
Copy link
Member

lafriks commented Dec 7, 2017

LGTM

@tboerger tboerger added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Dec 7, 2017
@lunny lunny merged commit 7ec6cdd into go-gitea:master Dec 7, 2017
@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants