Skip to content

[$350] Notification preferences API #520

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

Closed
jmgasper opened this issue Apr 1, 2021 · 10 comments
Closed

[$350] Notification preferences API #520

jmgasper opened this issue Apr 1, 2021 · 10 comments

Comments

@jmgasper
Copy link
Collaborator

jmgasper commented Apr 1, 2021

@atelomycterus - We'd like to start planning to integrate forum preferences into the main Topcoder community app at some point in the future.

We'd like to have endpoint(s) to:

  • Get the user's current notification preferences
  • Set the user's current notification preferences

Ideally we wouldn't need the token for these API endpoints - we would use the user's Topcoder JWT instead. That way the community app can just pass along the token that it already has for the logged in user.

Screen Shot 2021-04-02 at 8 57 14 am

@jmgasper
Copy link
Collaborator Author

jmgasper commented Apr 1, 2021

Challenge https://www.topcoder.com/challenges/85e41859-3cfa-4772-8f37-4b3bf4b09475 has been created for this ticket.

This is an automated message for ghostar via Topcoder X

@jmgasper
Copy link
Collaborator Author

jmgasper commented Apr 1, 2021

Challenge https://www.topcoder.com/challenges/85e41859-3cfa-4772-8f37-4b3bf4b09475 has been assigned to obog.

This is an automated message for ghostar via Topcoder X

@atelomycterus
Copy link
Collaborator

@jmgasper What about advanced notification preferences?
The advanced notification preferences include the ability to customize notifications more flexibly.
User can enable only new comment notifications or new discussion notifications for a category,
select how be notified (email or popup). At the moment, users cannot control advanced notification preferences from the UI.

When user turns on the icon, we subscribe the user to both new discussions and new comments,
user will receive popup\email notifications.
image

If user is watching a category, these keys are stored in DB. So the endpoints can set/get the keys. Let me know if advanced notification preferences is in the scope.

Preferences.Email.NewDiscussion.XXX
Preferences.Popup.NewDiscussion.XXX
Preferences.Email.NewComment.XXX
Preferences.Popup.NewComment.XXX

@jmgasper
Copy link
Collaborator Author

@atelomycterus - Ideally, we'd give the user the same control that they would have in the Vanilla UI, so if the API can handle the same level of control, that would be good, thanks.

@jmgasper jmgasper changed the title [$250] Notification preferences API [$350] Notification preferences API Apr 26, 2021
@atelomycterus
Copy link
Collaborator

@jmgasper The current status:

We'd like to have endpoint(s) to:
Get the user's current notification preferences

Implemented for general notification preferences + advanced notification preferences.
TODO: Normalize output for Category Preferences

image

Set the user's current notification preferences

Implemented for general notification preferences.
TODO: patch advanced notification preferences. I'm going to implement and test it tomorrow.

Ideally we wouldn't need the token for these API endpoints - we would use the user's Topcoder JWT instead. That way the >community app can just pass along the token that it already has for the logged in user.

Done. Use the Authorization: Bearer $TOKEN header to access the v2 API.
Topcoder plugin uses a jwt token from a header for /api/v2/users/me-preferences, no changes for other requests

Vanilla Settings

Default preferences in Vanilla. Setting these to 'false' disables them globally.

$Configuration['Preferences']['Email']['BookmarkComment'] = '1';
$Configuration['Preferences']['Email']['ParticipateComment'] = '0';
$Configuration['Preferences']['Email']['DiscussionComment'] = '0';
$Configuration['Preferences']['Email']['Mention'] = '0';
$Configuration['Preferences']['Popup']['BookmarkComment'] = '1';
$Configuration['Preferences']['Popup']['ParticipateComment'] = '0';
$Configuration['Preferences']['Popup']['DiscussionComment'] = '1';
$Configuration['Preferences']['Popup']['Mention'] = '1';

@atelomycterus
Copy link
Collaborator

@jmgasper I pushed code in the branches. Need to test it before deploying it on PROD because there are some changes in Topcoder plugin to support JWT token. I'll create PRs after deploying the current shapeup release on PROD.

https://github.com/topcoder-platform/forums/tree/issues-520
https://github.com/topcoder-platform/forums-plugins/tree/issues-520

New endpoints

/users/me-preferences Get notification preferences for current user.
/users/me-preferences Update notification preferences for current user.

Use the Authorization: Bearer $TOKEN header to access the endpoints.

curl -H 'Accept: application/json' -H "Authorization: Bearer JWT_TOKEN" http://127.0.0.1/api/v2/users/me-preferences

General Preferences:
image

Category Preferences:
1 - User is watching a category
2 - "If user turns off the "watch" feature on any sub-thread, the eyeball icon should be turned off on the parent category"(#577)

Patch Category Preferences:
0 - remove XXX notification
1, 2 - add XXX notification

image

Vanilla REST API

Some methods have already been implemented in Vanilla. Topcoder JWT token can be used for the endpoints:
/discussions/bookmarked - Get a list of the current user's bookmarked discussions.
/discussions/{id}/bookmark - Bookmark a discussion.

Watched discussions
image

Watch a discussion
/discussions/{id}/bookmark - Bookmark a discussion.
example:
Pass true to bookmark or false to remove bookmark.

curl -X PUT http://127.0.0.1/api/v2/discussions/1792/bookmark -H "Content-Type: application/json" -H 'Accept: application/json' -H "Authorization: Bearer JWT_TOKEN" -d '{"bookmarked":1}'
curl -X PUT http://127.0.0.1/api/v2/discussions/1792/bookmark -H "Content-Type: application/json" -H 'Accept: application/json' -H "Authorization: Bearer JWT_TOKEN" -d '{"bookmarked":0}'

Other REST API methods

A few more Vanilla notifications' endpoints that might be useful for users. In this context notifications are email/popup messages sent to the current user. Let me know if the endpoints should support JWT token:

image

@jmgasper
Copy link
Collaborator Author

@atelomycterus - Sounds good, thanks. The next prod push is happening in around 7 hours.

@atelomycterus
Copy link
Collaborator

@jmgasper
Copy link
Collaborator Author

jmgasper commented May 1, 2021

@atelomycterus - Deployed to dev, thanks! Gonna close this now so that we don't have issues with billing.

@jmgasper
Copy link
Collaborator Author

jmgasper commented May 1, 2021

Payment task has been updated: https://www.topcoder.com/challenges/85e41859-3cfa-4772-8f37-4b3bf4b09475
Payments Complete
Winner: obog
Copilot: ghostar
Challenge 85e41859-3cfa-4772-8f37-4b3bf4b09475 has been paid and closed.

This is an automated message for ghostar via Topcoder X

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

No branches or pull requests

2 participants