about summary refs log tree commit diff
path: root/app/javascript/mastodon/actions/notifications.js
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-05-04 23:41:34 +0200
committerGitHub <noreply@github.com>2017-05-04 23:41:34 +0200
commiteddb95b0126e523faeafbde544ff5df3a64e5b25 (patch)
treebc24f9595b33c9b621886a7d6ab1a3233ac69b3e /app/javascript/mastodon/actions/notifications.js
parent84eb425f385c5fc66dc67973b2869b9f31e9a2bb (diff)
When streaming API is disconnected, poll home/notifications (#2776)
* When streaming API is disconnected, poll home/notifications
Display slightly different empty home timeline message if user is following others
Cull notifications to 20 items when over 40 get added in real-time
Run manage:translations

* Optimize <HomeTimeline /> a little
Diffstat (limited to 'app/javascript/mastodon/actions/notifications.js')
-rw-r--r--app/javascript/mastodon/actions/notifications.js35
1 files changed, 24 insertions, 11 deletions
diff --git a/app/javascript/mastodon/actions/notifications.js b/app/javascript/mastodon/actions/notifications.js
index b09ca0854..8bae411c1 100644
--- a/app/javascript/mastodon/actions/notifications.js
+++ b/app/javascript/mastodon/actions/notifications.js
@@ -54,54 +54,64 @@ const excludeTypesFromSettings = state => state.getIn(['settings', 'notification
 
 export function refreshNotifications() {
   return (dispatch, getState) => {
-    dispatch(refreshNotificationsRequest());
-
     const params = {};
     const ids    = getState().getIn(['notifications', 'items']);
 
+    let skipLoading = false;
+
     if (ids.size > 0) {
       params.since_id = ids.first().get('id');
     }
 
+    if (getState().getIn(['notifications', 'loaded'])) {
+      skipLoading = true;
+    }
+
     params.exclude_types = excludeTypesFromSettings(getState());
 
+    dispatch(refreshNotificationsRequest(skipLoading));
+
     api(getState).get('/api/v1/notifications', { params }).then(response => {
       const next = getLinks(response).refs.find(link => link.rel === 'next');
 
-      dispatch(refreshNotificationsSuccess(response.data, next ? next.uri : null));
+      dispatch(refreshNotificationsSuccess(response.data, skipLoading, next ? next.uri : null));
       fetchRelatedRelationships(dispatch, response.data);
     }).catch(error => {
-      dispatch(refreshNotificationsFail(error));
+      dispatch(refreshNotificationsFail(error, skipLoading));
     });
   };
 };
 
-export function refreshNotificationsRequest() {
+export function refreshNotificationsRequest(skipLoading) {
   return {
-    type: NOTIFICATIONS_REFRESH_REQUEST
+    type: NOTIFICATIONS_REFRESH_REQUEST,
+    skipLoading
   };
 };
 
-export function refreshNotificationsSuccess(notifications, next) {
+export function refreshNotificationsSuccess(notifications, skipLoading, next) {
   return {
     type: NOTIFICATIONS_REFRESH_SUCCESS,
     notifications,
     accounts: notifications.map(item => item.account),
     statuses: notifications.map(item => item.status).filter(status => !!status),
+    skipLoading,
     next
   };
 };
 
-export function refreshNotificationsFail(error) {
+export function refreshNotificationsFail(error, skipLoading) {
   return {
     type: NOTIFICATIONS_REFRESH_FAIL,
-    error
+    error,
+    skipLoading
   };
 };
 
 export function expandNotifications() {
   return (dispatch, getState) => {
-    const url = getState().getIn(['notifications', 'next'], null);
+    const url    = getState().getIn(['notifications', 'next'], null);
+    const lastId = getState().getIn(['notifications', 'items']).last();
 
     if (url === null || getState().getIn(['notifications', 'isLoading'])) {
       return;
@@ -109,7 +119,10 @@ export function expandNotifications() {
 
     dispatch(expandNotificationsRequest());
 
-    const params = {};
+    const params = {
+      max_id: lastId,
+      limit: 20
+    };
 
     params.exclude_types = excludeTypesFromSettings(getState());