about summary refs log tree commit diff
path: root/app/assets
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-11-21 10:24:50 +0100
committerEugen Rochko <eugen@zeonfederated.com>2016-11-21 10:24:50 +0100
commitfb48cc3b7400f73c01d59a038eaf7fc3020c39f4 (patch)
tree8c438fdf1cfc61a7292115b7787b46b9280a5d1b /app/assets
parente616ffc5d60acafb67dadf90e396226d408d0cda (diff)
Desktop notifications
Diffstat (limited to 'app/assets')
-rw-r--r--app/assets/javascripts/components/actions/notifications.jsx9
-rw-r--r--app/assets/javascripts/components/containers/mastodon.jsx8
2 files changed, 13 insertions, 4 deletions
diff --git a/app/assets/javascripts/components/actions/notifications.jsx b/app/assets/javascripts/components/actions/notifications.jsx
index 7863d9683..b34fc7289 100644
--- a/app/assets/javascripts/components/actions/notifications.jsx
+++ b/app/assets/javascripts/components/actions/notifications.jsx
@@ -1,5 +1,6 @@
 import api, { getLinks } from '../api'
 import Immutable from 'immutable';
+import IntlMessageFormat from 'intl-messageformat';
 
 import { fetchRelationships } from './accounts';
 
@@ -21,7 +22,7 @@ const fetchRelatedRelationships = (dispatch, notifications) => {
   }
 };
 
-export function updateNotifications(notification) {
+export function updateNotifications(notification, intlMessages, intlLocale) {
   return dispatch => {
     dispatch({
       type: NOTIFICATIONS_UPDATE,
@@ -31,6 +32,12 @@ export function updateNotifications(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 });
   };
 };
 
diff --git a/app/assets/javascripts/components/containers/mastodon.jsx b/app/assets/javascripts/components/containers/mastodon.jsx
index cf77c169d..a8a9e365e 100644
--- a/app/assets/javascripts/components/containers/mastodon.jsx
+++ b/app/assets/javascripts/components/containers/mastodon.jsx
@@ -60,8 +60,10 @@ const Mastodon = React.createClass({
   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', {
@@ -78,7 +80,7 @@ const Mastodon = React.createClass({
             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));
           }
         }