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

Notifications Service #696

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open

Notifications Service #696

wants to merge 25 commits into from

Conversation

prabalsingh24
Copy link
Contributor

Problem

Adding a feature to subscribe entities and get notified if and when any changes are made to those entities

Solution

https://community.metabrainz.org/t/gsoc-2021-notification-service-bookbrainz-prabal/526184

Areas of Impact

Copy link
Member

@MonkeyDo MonkeyDo left a comment

Choose a reason for hiding this comment

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

Looking good so far.

My main comments below aim to refactor and consolidate as much code as possible so that we only have to make change in one place if the code is the same or similar enough.

I'll do another round of more thorough review of the SQL bits, since I'm not super well versed in SQL it takes me extra time to make sure I'm not missing anything, although I think there won't be much to change anyway, it looks good already!

);
}
});
await Promise.all(notificationPromiseArray);
Copy link
Member

Choose a reason for hiding this comment

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

We should probably wrap the entirety of this message handler in a try-catch block

.where('collection_id', collectionId)
.fetchAll({
required: false,
withRelated: ['collection']
Copy link
Member

Choose a reason for hiding this comment

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

Does this load the same collection on each CollectionSubscription model?
If so it would probably be better to pass the required collection info (I guess only the collection name is missing?) along in the 'send-notifications-for-collection' message instead.

Comment on lines 19 to 20
const editor = await new Editor({id: editorId}).fetch();
const editorJSON = editor.toJSON();
Copy link
Member

Choose a reason for hiding this comment

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

Same comment here, we have access to req.user.name when we emit the 'send-notifications-for-collection' message, so better to pass it along in the arguments rather than have to re-fetch and serialize the editor just to get the name.

try {
const editorId = req.params.id;
const {Notification} = req.app.locals.orm;
const allNotifications = await new Notification().where('subscriber_id', editorId).fetchAll({requried: false});
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const allNotifications = await new Notification().where('subscriber_id', editorId).fetchAll({requried: false});
const allNotifications = await new Notification().where('subscriber_id', editorId).fetchAll({required: false});

@@ -224,6 +232,59 @@ class CollectionPage extends React.Component {
}, this.pagerElementRef.triggerSearch);
}

handleSubscribe() {
Copy link
Member

Choose a reason for hiding this comment

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

As far as I can tell, all this code (handleSubscribe, handleUnsubscribe, setIsSubscribed and the buttons that go with it) is duplicated for each display page. Instead it would be better if the whole subscription part was a separate component that can then be added to the relevant pages.
You'll probably want to pass the submissionUrl as a prop to make it more flexible.

We might end up with separate CollectionSubscription and an EntitySubscription components if they require very different implementations.

});
}
function handleSubscribe(bbid) {
const submissionUrl = '/subscription/subscribe/entity';
Copy link
Member

Choose a reason for hiding this comment

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

I think this URL structure would be more appropriate and "RESTy":
/${entityType}/${bbid}/subscribe and associated /unsubscribe and /subscribed
I guess that means we don't need to send any information with that request anymore: BBID is in the route and the user needs to be logged in to access the route so we have their info in the route handler.

That would also work for collections: /collection/${collectionId}/subscribe

That means a fair amount of refactoring on the routes, I know, sorry about that :/
I think you'll end up with a middleware or two (one for entities, one for collections) which should be reusable for each entity's routes. In theory, in these routes you should have access to the user information

handleSubscribe() {
const submissionUrl = '/subscription/subscribe/collection';
const collectionId = this.props.collection.id;
const subscriberId = this.props.userId;
Copy link
Member

Choose a reason for hiding this comment

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

Would this not be accessible in the route handler on the server?
How come you don't need to send the userId for the entity subscribe routes but you do send them for the collections subscribe route?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants