-
Notifications
You must be signed in to change notification settings - Fork 0
Chat push notifications #23
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4e98835
Test page
wgrzeszczak cdc014f
Chat push notifications
wgrzeszczak e34a546
Merge branch 'master' into chat-push-notifications
wgrzeszczak ece36b8
Cleanup
wgrzeszczak 2f77aa2
Delayed notifications
wgrzeszczak 2e35dfe
Do not display read messages
wgrzeszczak 78972af
Send unread
wgrzeszczak b4fea6a
Fix read notifications check
wgrzeszczak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
2 changes: 1 addition & 1 deletion
2
...-chat/modules/chat/public/lib/consumers/chat_message_created/notify_of_new_message.liquid
This file contains hidden or 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
52 changes: 52 additions & 0 deletions
52
...ules/chat/public/lib/consumers/message_notification_to_send/send_push_notification.liquid
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| {% comment %} | ||
| Consumer for the `message_notification_to_send` event. | ||
|
|
||
| This event is only published by notify_of_new_message once a message has | ||
| sat unsuperseded as the last message in its conversation for the debounce | ||
| window, so a burst of messages results in a single push notification (for | ||
| the final message) rather than one per message. | ||
|
|
||
| Sends a Web Push notification (via pos-module-push-notifications) to every | ||
| other conversation participant who has not already read the message (i.e. | ||
| is not in conversation.participant_read_ids — see mark_read/mark_unread), | ||
| so a participant who was actively viewing the conversation during the | ||
| debounce window is not paged for something they've already seen. | ||
| Participant ids on a conversation are profile ids, but push_notifications' | ||
| broadcast command is keyed by platformOS user id, so each participant | ||
| profile is resolved to its `user_id` before calling broadcast. Runs as a | ||
| background job with retries, matching broadcast_new_message.liquid. | ||
| {% endcomment %} | ||
| {% background message_id: event.message_id, app_host: event.app_host, max_attempts: 5 %} | ||
| {% liquid | ||
| graphql messages = 'modules/chat/messages/search', id: message_id | ||
| assign message = messages.messages.results.first | ||
|
|
||
| if message | ||
| function sender = 'modules/user/queries/profiles/find', id: message.autor_id, user_id: null, uuid: null, first_name: null, last_name: null | ||
| assign sender_name = sender.name | default: sender.first_name | ||
|
|
||
| assign recipient_user_ids = [] | ||
| for participant_id in message.conversation.participant_ids | ||
| unless participant_id == message.autor_id | ||
| unless message.conversation.participant_read_ids contains participant_id | ||
| function recipient = 'modules/user/queries/profiles/find', id: participant_id, user_id: null, uuid: null, first_name: null, last_name: null | ||
| if recipient.user_id | ||
| assign recipient_user_ids << recipient.user_id | ||
| endif | ||
| endunless | ||
| endunless | ||
| endfor | ||
|
|
||
| if recipient_user_ids.size > 0 | ||
| assign title = 'New message from ' | append: sender_name | ||
| assign body = message.message | truncate: 120 | ||
| assign url = 'https://' | append: app_host | append: '/inbox?conversation_id=' | append: message.conversation_id | ||
| assign payload = { "title": title, "body": body, "url": url } | ||
|
|
||
| function _result = 'modules/push_notifications/commands/notifications/broadcast', user_ids: recipient_user_ids, payload: payload, ttl: null, urgency: null | ||
| endif | ||
| endif | ||
| %} | ||
| {% endbackground %} | ||
|
|
||
| {% return 'scheduled' %} |
This file contains hidden or 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
This file contains hidden or 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
4 changes: 2 additions & 2 deletions
4
pos-module-chat/modules/chat/public/views/partials/search.liquid
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
2 changes: 1 addition & 1 deletion
2
pos-module-push-notifications/modules/push_notifications/pos-module.json
This file contains hidden or 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
67 changes: 67 additions & 0 deletions
67
...ifications/modules/push_notifications/public/views/pages/_push_notifications/index.liquid
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| --- | ||
| slug: _push_notifications | ||
| method: get | ||
| layout: '' | ||
| --- | ||
| {% doc %} | ||
| Dev/staging-only page to send a real test push notification to the current | ||
| user's own active subscriptions. Mirrors the `/_tests` convention used by | ||
| pos-module-tests (same env gate, same "blank outside dev/staging" behavior) | ||
| as its own independent namespace — this module has no dependency on the | ||
| tests module. | ||
| {% enddoc %} | ||
| {% if context.environment == 'staging' or context.environment == 'development' %} | ||
| {% assign queued = context.params.queued %} | ||
| {% if context.current_user != blank %} | ||
| {% function subs = 'modules/push_notifications/queries/subscriptions/search', user_id: context.current_user.id, active: true, limit: 1, page: 1 %} | ||
| {% endif %} | ||
| <!DOCTYPE html> | ||
| <html lang="{{ context.language }}"> | ||
| <head> | ||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | ||
| <title>Push Notifications — Test</title> | ||
| <style> | ||
| body { font-family: ui-sans-serif, system-ui, sans-serif; max-width: 40rem; margin: 2rem auto; color: #374151; } | ||
| h1 { font-size: 1.25rem; } | ||
| .notice { padding: .75rem 1rem; border-radius: .25rem; margin-bottom: 1rem; } | ||
| .notice-info { background: #eff6ff; border: 1px solid #bfdbfe; } | ||
| .notice-success { background: #ecfdf5; border: 1px solid #a7f3d0; } | ||
| label { display: block; margin-top: .75rem; font-weight: 600; } | ||
| input[type="text"] { width: 100%; padding: .5rem; margin-top: .25rem; border: 1px solid #d1d5db; border-radius: .25rem; } | ||
| button { margin-top: 1rem; padding: .5rem 1rem; border: 0; border-radius: .25rem; background: #111827; color: #fff; cursor: pointer; } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <h1>Push Notifications — Test</h1> | ||
|
|
||
| {% if context.current_user == blank %} | ||
| <p class="notice notice-info">Log in to send a test push notification.</p> | ||
| {% else %} | ||
| {% if queued != blank %} | ||
| <p class="notice notice-success">Queued for {{ queued }} subscription(s).</p> | ||
| {% endif %} | ||
|
|
||
| {% if subs.total_entries == 0 %} | ||
| <p class="notice notice-info">You have no active subscriptions yet — subscribe first, then come back here.</p> | ||
| {% else %} | ||
| <p>You have {{ subs.total_entries }} active subscription(s).</p> | ||
| {% endif %} | ||
|
|
||
| <form method="post" action="/_push_notifications"> | ||
| <input type="hidden" name="authenticity_token" value="{{ context.authenticity_token }}"> | ||
|
|
||
| <label for="pos-push-test-title">Title</label> | ||
| <input type="text" id="pos-push-test-title" name="title" value="Test notification"> | ||
|
|
||
| <label for="pos-push-test-body">Body</label> | ||
| <input type="text" id="pos-push-test-body" name="body" value="This is a test push notification."> | ||
|
|
||
| <label for="pos-push-test-url">URL</label> | ||
| <input type="text" id="pos-push-test-url" name="url" value="/"> | ||
|
|
||
| <button type="submit">Send test notification</button> | ||
| </form> | ||
| {% endif %} | ||
| </body> | ||
| </html> | ||
| {% endif %} |
29 changes: 29 additions & 0 deletions
29
...tifications/modules/push_notifications/public/views/pages/_push_notifications/send.liquid
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| --- | ||
| slug: _push_notifications | ||
| method: post | ||
| --- | ||
| {% doc %} | ||
| Handles the test-notification form from `_push_notifications/index.liquid`: | ||
| broadcasts a test push to the current user's own active subscriptions and | ||
| redirects back with the queued count. | ||
| {% enddoc %} | ||
| {% liquid | ||
| unless context.environment == 'staging' or context.environment == 'development' | ||
| return | ||
| endunless | ||
|
|
||
| if context.current_user == blank | ||
| redirect_to '/sessions/new' | ||
| return | ||
| endif | ||
|
|
||
| assign title = context.params.title | default: 'Test notification' | ||
| assign body = context.params.body | default: 'This is a test push notification.' | ||
| assign url = context.params.url | default: '/' | ||
| assign payload = { "title": title, "body": body, "url": url } | ||
|
|
||
| function result = 'modules/push_notifications/commands/notifications/broadcast', user_ids: [context.current_user.id], payload: payload, ttl: null, urgency: null | ||
|
|
||
| assign redirect_url = '/_push_notifications?queued=' | append: result.queued | ||
| redirect_to redirect_url | ||
| %} |
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
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.
Suggestion cannot be applied right now. Please check back later.
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.
Any idea why the linter requires this? I've marked the
classas optional incommon-stylingso I wouldn't have to do this, but still...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.
Let me check, must be a bug