import api, { getLinks } from '../api'
import Immutable from 'immutable';
+import IntlMessageFormat from 'intl-messageformat';
import { fetchRelationships } from './accounts';
}
};
-export function updateNotifications(notification) {
+export function updateNotifications(notification, intlMessages, intlLocale) {
return dispatch => {
dispatch({
type: NOTIFICATIONS_UPDATE,
});
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 });
};
};
mixins: [PureRenderMixin],
componentWillMount() {
- store.dispatch(setAccessToken(this.props.token));
- store.dispatch(setAccountSelf(JSON.parse(this.props.account)));
+ const { token, account, locale } = this.props;
+
+ store.dispatch(setAccessToken(token));
+ store.dispatch(setAccountSelf(JSON.parse(account)));
if (typeof App !== 'undefined') {
this.subscription = App.cable.subscriptions.create('TimelineChannel', {
case 'block':
return store.dispatch(refreshTimeline('mentions', true));
case 'notification':
- return store.dispatch(updateNotifications(JSON.parse(data.message)));
+ return store.dispatch(updateNotifications(JSON.parse(data.message), getMessagesForLocale(locale), locale));
}
}
rescue_from ActiveRecord::RecordNotFound, with: :not_found
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
raise ActionController::RoutingError, "No route matches #{params[:unmatched_route]}"
end
def set_locale
- I18n.locale = current_user.locale || I18n.default_locale
+ I18n.locale = current_user.try(:locale) || I18n.default_locale
rescue I18n::InvalidLocale
I18n.locale = I18n.default_locale
end