about summary refs log tree commit diff
path: root/app/javascript/mastodon/reducers
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2020-02-03 01:53:09 +0100
committerGitHub <noreply@github.com>2020-02-03 01:53:09 +0100
commit3adc722d1cdd28d87d2724b8952d7ec52d241b52 (patch)
treef8b08e38d3fba35c92b21b14c99ec2c3d21dd3c6 /app/javascript/mastodon/reducers
parent61a7390b666dc40beda291da426436a9d36f4288 (diff)
Change how unread announcements are handled (#13020)
* Change meaning of /api/v1/announcements/:id/dismiss to mark an announcement as read

* Change how unread announcements are counted in UI

* Add unread marker to announcements and mark announcements as unread as they are displayed

* Fixups
Diffstat (limited to 'app/javascript/mastodon/reducers')
-rw-r--r--app/javascript/mastodon/reducers/announcements.js26
1 files changed, 5 insertions, 21 deletions
diff --git a/app/javascript/mastodon/reducers/announcements.js b/app/javascript/mastodon/reducers/announcements.js
index 1653318ce..34e08eac8 100644
--- a/app/javascript/mastodon/reducers/announcements.js
+++ b/app/javascript/mastodon/reducers/announcements.js
@@ -10,14 +10,14 @@ import {
   ANNOUNCEMENTS_REACTION_REMOVE_FAIL,
   ANNOUNCEMENTS_TOGGLE_SHOW,
   ANNOUNCEMENTS_DELETE,
+  ANNOUNCEMENTS_DISMISS_SUCCESS,
 } from '../actions/announcements';
-import { Map as ImmutableMap, List as ImmutableList, Set as ImmutableSet, fromJS } from 'immutable';
+import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
 
 const initialState = ImmutableMap({
   items: ImmutableList(),
   isLoading: false,
   show: false,
-  unread: ImmutableSet(),
 });
 
 const updateReaction = (state, id, name, updater) => state.update('items', list => list.map(announcement => {
@@ -42,24 +42,11 @@ const addReaction = (state, id, name) => updateReaction(state, id, name, x => x.
 
 const removeReaction = (state, id, name) => updateReaction(state, id, name, x => x.set('me', false).update('count', y => y - 1));
 
-const addUnread = (state, items) => {
-  if (state.get('show')) {
-    return state;
-  }
-
-  const newIds = ImmutableSet(items.map(x => x.get('id')));
-  const oldIds = ImmutableSet(state.get('items').map(x => x.get('id')));
-
-  return state.update('unread', unread => unread.union(newIds.subtract(oldIds)));
-};
-
 const sortAnnouncements = list => list.sortBy(x => x.get('starts_at') || x.get('published_at'));
 
 const updateAnnouncement = (state, announcement) => {
   const idx = state.get('items').findIndex(x => x.get('id') === announcement.get('id'));
 
-  state = addUnread(state, [announcement]);
-
   if (idx > -1) {
     // Deep merge is used because announcements from the streaming API do not contain
     // personalized data about which reactions have been selected by the given user,
@@ -74,7 +61,6 @@ export default function announcementsReducer(state = initialState, action) {
   switch(action.type) {
   case ANNOUNCEMENTS_TOGGLE_SHOW:
     return state.withMutations(map => {
-      if (!map.get('show')) map.set('unread', ImmutableSet());
       map.set('show', !map.get('show'));
     });
   case ANNOUNCEMENTS_FETCH_REQUEST:
@@ -83,10 +69,6 @@ export default function announcementsReducer(state = initialState, action) {
     return state.withMutations(map => {
       const items = fromJS(action.announcements);
 
-      map.set('unread', ImmutableSet());
-
-      addUnread(map, items);
-
       map.set('items', items);
       map.set('isLoading', false);
     });
@@ -102,8 +84,10 @@ export default function announcementsReducer(state = initialState, action) {
   case ANNOUNCEMENTS_REACTION_REMOVE_REQUEST:
   case ANNOUNCEMENTS_REACTION_ADD_FAIL:
     return removeReaction(state, action.id, action.name);
+  case ANNOUNCEMENTS_DISMISS_SUCCESS:
+    return updateAnnouncement(state, fromJS({ 'id': action.id, 'read': true }));
   case ANNOUNCEMENTS_DELETE:
-    return state.update('unread', set => set.delete(action.id)).update('items', list => {
+    return state.update('items', list => {
       const idx = list.findIndex(x => x.get('id') === action.id);
 
       if (idx > -1) {