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
Refactor notifications #199
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
This PR refactors notifications to make them a little easier to interact with. Most of the ideas implemented here come from discussions with @jayeclark in #182. So a huge thank you there!
Most importantly, notifications are now tied to a
User, not aBusinessorDeveloper. This makes queries much more straightforward ascurrent_user.notificationsgets them all at once. No more building custom queries.Second, notification logic now lives on the notification models (not records) themselves.
NewMessageNotificationnow has methods for the conversation and message, notNotification. This is largely thanks to the discovered#to_notificationmethod from noticed that rehydrates the instance from the params initially sent in.Finally, it refactors how notifications are "read" by navigating to
/notifications/:idand then redirecting. The second refactor enabled this to be much simpler, mostly due to the#to_notificationmethod from noticed. If aNotificationinstance doesn't have a url then it is marked as read but you are redirected to/notifications(with a flash message).A backfill was added that addresses a few things. First, it sets the recipient of all
NewMessageNotificationtype records to the user associated with the developer or business. Second, it deletes some dangling notification records from deleted developer profiles. Finally, a separate rake task marks all existing notifications as read.Edit: The backfill now also adds the conversation to the notification records (as params) which allows easy querying for batch updating:
conversation.notifications_as_conversationgrabs all the notifications triggered by sent messages in the convo. Adding this toConversationsControllermeans marking all (unread) notifications as read when viewing a conversation, all with a single query!I'm going to leave this in draft tonight and revisit tomorrow morning as there's a lot going on. Especially with the backfills!
Pull request checklist
bin/check