mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-11-27 08:11:37 +01:00
Desktop notifications
This commit is contained in:
parent
e616ffc5d6
commit
fb48cc3b74
3 changed files with 15 additions and 6 deletions
|
@ -1,5 +1,6 @@
|
||||||
import api, { getLinks } from '../api'
|
import api, { getLinks } from '../api'
|
||||||
import Immutable from 'immutable';
|
import Immutable from 'immutable';
|
||||||
|
import IntlMessageFormat from 'intl-messageformat';
|
||||||
|
|
||||||
import { fetchRelationships } from './accounts';
|
import { fetchRelationships } from './accounts';
|
||||||
|
|
||||||
|
@ -21,7 +22,7 @@ const fetchRelatedRelationships = (dispatch, notifications) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export function updateNotifications(notification) {
|
export function updateNotifications(notification, intlMessages, intlLocale) {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: NOTIFICATIONS_UPDATE,
|
type: NOTIFICATIONS_UPDATE,
|
||||||
|
@ -31,6 +32,12 @@ export function updateNotifications(notification) {
|
||||||
});
|
});
|
||||||
|
|
||||||
fetchRelatedRelationships(dispatch, [notification]);
|
fetchRelatedRelationships(dispatch, [notification]);
|
||||||
|
|
||||||
|
// Desktop notifications
|
||||||
|
const title = new IntlMessageFormat(intlMessages[`notification.${notification.type}`], intlLocale).format({ name: notification.account.display_name.length > 0 ? notification.account.display_name : notification.account.username });
|
||||||
|
const body = $('<p>').html(notification.status ? notification.status.content : '').text();
|
||||||
|
|
||||||
|
new Notification(title, { body });
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -60,8 +60,10 @@ const Mastodon = React.createClass({
|
||||||
mixins: [PureRenderMixin],
|
mixins: [PureRenderMixin],
|
||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
store.dispatch(setAccessToken(this.props.token));
|
const { token, account, locale } = this.props;
|
||||||
store.dispatch(setAccountSelf(JSON.parse(this.props.account)));
|
|
||||||
|
store.dispatch(setAccessToken(token));
|
||||||
|
store.dispatch(setAccountSelf(JSON.parse(account)));
|
||||||
|
|
||||||
if (typeof App !== 'undefined') {
|
if (typeof App !== 'undefined') {
|
||||||
this.subscription = App.cable.subscriptions.create('TimelineChannel', {
|
this.subscription = App.cable.subscriptions.create('TimelineChannel', {
|
||||||
|
@ -78,7 +80,7 @@ const Mastodon = React.createClass({
|
||||||
case 'block':
|
case 'block':
|
||||||
return store.dispatch(refreshTimeline('mentions', true));
|
return store.dispatch(refreshTimeline('mentions', true));
|
||||||
case 'notification':
|
case 'notification':
|
||||||
return store.dispatch(updateNotifications(JSON.parse(data.message)));
|
return store.dispatch(updateNotifications(JSON.parse(data.message), getMessagesForLocale(locale), locale));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ class ApplicationController < ActionController::Base
|
||||||
rescue_from ActiveRecord::RecordNotFound, with: :not_found
|
rescue_from ActiveRecord::RecordNotFound, with: :not_found
|
||||||
|
|
||||||
before_action :store_current_location, except: :raise_not_found, unless: :devise_controller?
|
before_action :store_current_location, except: :raise_not_found, unless: :devise_controller?
|
||||||
before_action :set_locale, if: 'user_signed_in?'
|
before_action :set_locale
|
||||||
|
|
||||||
def raise_not_found
|
def raise_not_found
|
||||||
raise ActionController::RoutingError, "No route matches #{params[:unmatched_route]}"
|
raise ActionController::RoutingError, "No route matches #{params[:unmatched_route]}"
|
||||||
|
@ -26,7 +26,7 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_locale
|
def set_locale
|
||||||
I18n.locale = current_user.locale || I18n.default_locale
|
I18n.locale = current_user.try(:locale) || I18n.default_locale
|
||||||
rescue I18n::InvalidLocale
|
rescue I18n::InvalidLocale
|
||||||
I18n.locale = I18n.default_locale
|
I18n.locale = I18n.default_locale
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue