-
Notifications
You must be signed in to change notification settings - Fork 75
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
[WIP][www] Add notification mechanism #393
Conversation
b1744ec
to
bc29e61
Compare
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.
Thanks for this PR, I see you've done a lot of work on it already. I didn't do a full review, I just looked over about 3/4 of the changes so far and made some comments inline.
It may already be handled in your implementation (I'm not sure), but one general concern I had was how many notifications will we send to the user, and how many will we store in the db? Maybe a maximum of 5-10 at a time?
politeiawww/api/v1/v1.go
Outdated
NotTypeProposalPublished NotificationType = 3 | ||
NotTypeProposalStartedVoting NotificationType = 4 | ||
NotTypeProposalFinishedVoting NotificationType = 5 | ||
NotTypeInvalid NotificationType = 6 |
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.
The invalid type's value should be 0
.
politeiawww/api/v1/v1.go
Outdated
@@ -147,6 +150,15 @@ const ( | |||
PropVoteStatusStarted PropVoteStatusT = 2 // Proposal vote has been started | |||
PropVoteStatusFinished PropVoteStatusT = 3 // Proposal vote has been finished | |||
PropVoteStatusDoesntExist PropVoteStatusT = 4 // Proposal doesn't exist | |||
|
|||
// Notification indentifiers | |||
NotTypeSignupPaywallPaymentConfirmed NotificationType = 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.
I would prefer to prefix these with Notification
instead of NotType
, since NotType
is a little confusing out of context. Also, can you rename the type to NotificationT
to be consistent with the others?
politeiawww/api/v1/v1.go
Outdated
@@ -219,6 +231,17 @@ var ( | |||
PropVoteStatusFinished: "voting finished", | |||
PropVoteStatusDoesntExist: "proposal does not exist", | |||
} | |||
|
|||
// NotificationIdentifier converts a Notification Id to human readable text | |||
NotificationIndentifier = map[NotificationType]string{ |
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.
Typo, should be NotificationIdentifier
politeiawww/api/v1/v1.go
Outdated
|
||
// NotificationIdentifier converts a Notification Id to human readable text | ||
NotificationIndentifier = map[NotificationType]string{ | ||
NotTypeSignupPaywallPaymentConfirmed: "Paywall payment for Politeia access confirmed", |
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.
This is very nitpicky but can you make the strings lowercase to be consistent with the others?
n.Viewed = false | ||
n.Timestamp = time.Now().Unix() | ||
// Check if the user has already a mailbox registered | ||
exists, err = l.userdb.Has(key, nil) |
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.
Couldn't we store the notifications themselves within the user object?
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.
We can actually. The way I did was totally an implementation option in order to have a flatter design but on the other hand, having it within the user object would reduce the number of database queries. Since we plan to move www database to SQL at some point, I think that having them under different keys can simplify the migration. Having the notifications collection inside the user object feels more like a noSQL approach. What do you think?
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.
Yeah that's true, if we migrate to sql then we would use a separate table.
Thanks for your review @sndurkin. I will address your inline comments and I let you know.
|
e8227c3
to
7eb5f44
Compare
Can you change the response so it returns |
The request is returning |
The response for marking a notification as viewed doesn't match the example. See the example below:
Here I marked notification 1 as viewed, works nice. But it messed up with the info for notification 0. I would say we should return the right info or doesn't return anything, just a success message. |
Thanks for the review @tiagoalvesdulce. Both of your comments are addressed and it should be working now. |
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've done some initial testing and this notification system is looking good, nice job! I left a couple comments inline.
politeiawww/database/database.go
Outdated
ID uint64 // Notification Id | ||
NotificationType int // Type of the notification | ||
Timestamp int64 // When the notification was created | ||
URL string // URL associated to the notification |
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.
Instead of constructing a PoliteiaGUI URL (which increases the dependence www has on it), I think we should pass an array of string params, which can change depending on the notification type. And then we let the GUI build the URL using the params.
So for the proposal-related notifications, we can pass the token as the only param., and for the payment received for proposal credits, we can pass the number of proposal credits purchased, and etc.
politeiawww/convert.go
Outdated
func convertNotificationFromDatabase(dbnotif database.Notification) www.Notification { | ||
return www.Notification{ | ||
NotificationID: dbnotif.ID, | ||
NotificationType: convertNotificationTypeFromDatabase(dbnotif.NotificationType), |
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.
Can't you just cast it to a NotificationT
here?
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 think so, good catch.
politeiawww/mailbox.go
Outdated
}, email) | ||
} | ||
|
||
func (m *mailbox) getUserEmailByPubkey(pubkey string) (string, 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.
This is a more general utility function and probably belongs in a new user.go
file or something. It might actually be better to return *database.User
and then have the caller fetch the Email
property. I think there are 1 or 2 places where a getUserByPubkey()
function could be used, I think that logic is already being replicated elsewhere in www.
Thanks for the review @sndurkin! I like your idea about sending a string associated to it notification instead of building the link. |
0f072e4
to
3a1629c
Compare
@tiagoalvesdulce @sndurkin I update this PR, you can see the new data shape in the PR description. |
ac060ad
to
09329b5
Compare
87d29b7
to
fda5001
Compare
Add notification on proposal paywall payment confirmed Notifications reply: set json formatting to “notifications” Fixes from @tiagoalvesdulce review Fix update notifications logic Updates from review rename mailbox.go to notifications.go and turn its functions into backend methods Indicate functions that must be called with the mutex held Add cli commands Add docs
fda5001
to
6aaf724
Compare
This is PR not applicable anymore. |
Fix tests for RECEIVE_LIKE_COMMENT Save page context on login modal and fix LoginSide inputs names fix signup error
This PR implements a notification mechanism for www. So, every relevant action generates a new notification into the user's mailbox.
closes #372
More information about the implementation design and current status can be found here:
https://gist.github.com/fernandoabolafio/0d13902f05294eb83480b1dab11e92c6
note: This PR refers to the stage 1 mentioned on the issue #372.
Handle store notifications on localdb
Add route to fetch user notifications
add handlers to create notifications for the following actions:
Add route to set notification as viewed
Add corresponding CLI commands
Add docs
Add/Fix tests
Update 1: New Routes specs
user/notifications
-> Return all users notifications (user is infered from the session)Example of response:
user/notifications/check
: set one or multiple notifications as viewedExample of request:
Example of response:
Update 2: Context info mapping