This repository has been archived by the owner on Dec 21, 2023. It is now read-only.
forked from mastodon/mastodon
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Web Push Notifications (mastodon#3243)
* feat: Register push subscription * feat: Notify when mentioned * feat: Boost, favourite, reply, follow, follow request * feat: Notification interaction * feat: Handle change of public key * feat: Unsubscribe if things go wrong * feat: Do not send normal notifications if push is enabled * feat: Focus client if open * refactor: Move push logic to WebPushSubscription * feat: Better title and body * feat: Localize messages * chore: Fix lint errors * feat: Settings * refactor: Lazy load * fix: Check if push settings exist * feat: Device-based preferences * refactor: Simplify logic * refactor: Pull request feedback * refactor: Pull request feedback * refactor: Create /api/web/push_subscriptions endpoint * feat: Spec PushSubscriptionController * refactor: WebPushSubscription => Web::PushSubscription * feat: Spec Web::PushSubscription * feat: Display first media attachment * feat: Support direction * fix: Stuff broken while rebasing * refactor: Integration with session activations * refactor: Cleanup * refactor: Simplify implementation * feat: Set VAPID keys via environment * chore: Comments * fix: Crash when no alerts * fix: Set VAPID keys in testing environment * fix: Follow link * feat: Notification actions * fix: Delete previous subscription * chore: Temporary logs * refactor: Move migration to a later date * fix: Fetch the correct session activation and misc bugs * refactor: Move migration to a later date * fix: Remove follow request (no notifications) * feat: Send administrator contact to push service * feat: Set time-to-live * fix: Do not show sensitive images * fix: Reducer crash in error handling * feat: Add badge * chore: Fix lint error * fix: Checkbox label overlap * fix: Check for payload support * fix: Rename action "type" (crash in latest Chrome) * feat: Action to expand notification * fix: Lint errors * fix: Unescape notification body * fix: Do not allow boosting if the status is hidden * feat: Add VAPID keys to the production sample environment * fix: Strip HTML tags from status * refactor: Better error messages * refactor: Handle browser not implementing the VAPID protocol (Samsung Internet) * fix: Error when target_status is nil * fix: Handle lack of image * fix: Delete reference to invalid subscriptions * feat: Better error handling * fix: Unescape HTML characters after tags are striped * refactor: Simpify code * fix: Modify to work with mastodon#4091 * Sort strings alphabetically * i18n: Updated Polish translation it annoys me that it's not fully localized :P * refactor: Use current_session in PushSubscriptionController * fix: Rebase mistake * fix: Set cacheName to mastodon * refactor: Pull request feedback * refactor: Remove logging statements * chore(yarn): Fix conflicts with master * chore(yarn): Copy latest from master * chore(yarn): Readd offline-plugin * refactor: Use save! and update! * refactor: Send notifications async * fix: Allow retry when push fails * fix: Save track for failed pushes * fix: Minify sw.js * fix: Remove account_id from fabricator
- Loading branch information
1 parent
c2753fd
commit 0c7c188
Showing
42 changed files
with
890 additions
and
14 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# frozen_string_literal: true | ||
|
||
class Api::Web::PushSubscriptionsController < Api::BaseController | ||
respond_to :json | ||
|
||
before_action :require_user! | ||
|
||
def create | ||
params.require(:data).require(:endpoint) | ||
params.require(:data).require(:keys).require([:auth, :p256dh]) | ||
|
||
active_session = current_session | ||
|
||
unless active_session.web_push_subscription.nil? | ||
active_session.web_push_subscription.destroy! | ||
active_session.update!(web_push_subscription: nil) | ||
end | ||
|
||
web_subscription = ::Web::PushSubscription.create!( | ||
endpoint: params[:data][:endpoint], | ||
key_p256dh: params[:data][:keys][:p256dh], | ||
key_auth: params[:data][:keys][:auth] | ||
) | ||
|
||
active_session.update!(web_push_subscription: web_subscription) | ||
|
||
render json: web_subscription.as_payload | ||
end | ||
|
||
def update | ||
params.require([:id, :data]) | ||
|
||
web_subscription = ::Web::PushSubscription.find(params[:id]) | ||
|
||
web_subscription.update!(data: params[:data]) | ||
|
||
render json: web_subscription.as_payload | ||
end | ||
end |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import axios from 'axios'; | ||
|
||
export const SET_BROWSER_SUPPORT = 'PUSH_NOTIFICATIONS_SET_BROWSER_SUPPORT'; | ||
export const SET_SUBSCRIPTION = 'PUSH_NOTIFICATIONS_SET_SUBSCRIPTION'; | ||
export const CLEAR_SUBSCRIPTION = 'PUSH_NOTIFICATIONS_CLEAR_SUBSCRIPTION'; | ||
export const ALERTS_CHANGE = 'PUSH_NOTIFICATIONS_ALERTS_CHANGE'; | ||
|
||
export function setBrowserSupport (value) { | ||
return { | ||
type: SET_BROWSER_SUPPORT, | ||
value, | ||
}; | ||
} | ||
|
||
export function setSubscription (subscription) { | ||
return { | ||
type: SET_SUBSCRIPTION, | ||
subscription, | ||
}; | ||
} | ||
|
||
export function clearSubscription () { | ||
return { | ||
type: CLEAR_SUBSCRIPTION, | ||
}; | ||
} | ||
|
||
export function changeAlerts(key, value) { | ||
return dispatch => { | ||
dispatch({ | ||
type: ALERTS_CHANGE, | ||
key, | ||
value, | ||
}); | ||
|
||
dispatch(saveSettings()); | ||
}; | ||
} | ||
|
||
export function saveSettings() { | ||
return (_, getState) => { | ||
const state = getState().get('push_notifications'); | ||
const subscription = state.get('subscription'); | ||
const alerts = state.get('alerts'); | ||
|
||
axios.put(`/api/web/push_subscriptions/${subscription.get('id')}`, { | ||
data: { | ||
alerts, | ||
}, | ||
}); | ||
}; | ||
} |
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { STORE_HYDRATE } from '../actions/store'; | ||
import { SET_BROWSER_SUPPORT, SET_SUBSCRIPTION, CLEAR_SUBSCRIPTION, ALERTS_CHANGE } from '../actions/push_notifications'; | ||
import Immutable from 'immutable'; | ||
|
||
const initialState = Immutable.Map({ | ||
subscription: null, | ||
alerts: new Immutable.Map({ | ||
follow: false, | ||
favourite: false, | ||
reblog: false, | ||
mention: false, | ||
}), | ||
isSubscribed: false, | ||
browserSupport: false, | ||
}); | ||
|
||
export default function push_subscriptions(state = initialState, action) { | ||
switch(action.type) { | ||
case STORE_HYDRATE: { | ||
const push_subscription = action.state.get('push_subscription'); | ||
|
||
if (push_subscription) { | ||
return state | ||
.set('subscription', new Immutable.Map({ | ||
id: push_subscription.get('id'), | ||
endpoint: push_subscription.get('endpoint'), | ||
})) | ||
.set('alerts', push_subscription.get('alerts') || initialState.get('alerts')) | ||
.set('isSubscribed', true); | ||
} | ||
|
||
return state; | ||
} | ||
case SET_SUBSCRIPTION: | ||
return state | ||
.set('subscription', new Immutable.Map({ | ||
id: action.subscription.id, | ||
endpoint: action.subscription.endpoint, | ||
})) | ||
.set('alerts', new Immutable.Map(action.subscription.alerts)) | ||
.set('isSubscribed', true); | ||
case SET_BROWSER_SUPPORT: | ||
return state.set('browserSupport', action.value); | ||
case CLEAR_SUBSCRIPTION: | ||
return initialState; | ||
case ALERTS_CHANGE: | ||
return state.setIn(action.key, action.value); | ||
default: | ||
return state; | ||
} | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import './web_push_notifications'; |
Oops, something went wrong.