diff options
author | ThibG <thib@sitedethib.com> | 2020-09-26 20:57:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-26 20:57:07 +0200 |
commit | ff89025979abf3dae40b8e0745b2584cc3feb744 (patch) | |
tree | fd7650bee5e553a42b5160ecf5e645587c41e4dc /app/javascript/mastodon/actions/markers.js | |
parent | 03b6b034b95b9ee2ce4a80c3b9c724273dcb0072 (diff) |
Add unread notification markers (#14818)
* Add unread notification markers Fixes #14804 * Allow IntersectionObserverArticle's children to be updated
Diffstat (limited to 'app/javascript/mastodon/actions/markers.js')
-rw-r--r-- | app/javascript/mastodon/actions/markers.js | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/app/javascript/mastodon/actions/markers.js b/app/javascript/mastodon/actions/markers.js index 6cb09fe96..41a95503e 100644 --- a/app/javascript/mastodon/actions/markers.js +++ b/app/javascript/mastodon/actions/markers.js @@ -3,6 +3,9 @@ import { debounce } from 'lodash'; import compareId from '../compare_id'; import { showAlertForError } from './alerts'; +export const MARKERS_FETCH_REQUEST = 'MARKERS_FETCH_REQUEST'; +export const MARKERS_FETCH_SUCCESS = 'MARKERS_FETCH_SUCCESS'; +export const MARKERS_FETCH_FAIL = 'MARKERS_FETCH_FAIL'; export const MARKERS_SUBMIT_SUCCESS = 'MARKERS_SUBMIT_SUCCESS'; export const synchronouslySubmitMarkers = () => (dispatch, getState) => { @@ -58,7 +61,7 @@ const _buildParams = (state) => { const params = {}; const lastHomeId = state.getIn(['timelines', 'home', 'items']).find(item => item !== null); - const lastNotificationId = state.getIn(['notifications', 'items', 0, 'id']); + const lastNotificationId = state.getIn(['notifications', 'lastReadId']); if (lastHomeId && compareId(lastHomeId, state.getIn(['markers', 'home'])) > 0) { params.home = { @@ -100,3 +103,39 @@ export function submitMarkersSuccess({ home, notifications }) { export function submitMarkers() { return (dispatch, getState) => debouncedSubmitMarkers(dispatch, getState); }; + +export const fetchMarkers = () => (dispatch, getState) => { + const params = { timeline: ['notifications'] }; + + dispatch(fetchMarkersRequest()); + + api(getState).get('/api/v1/markers', { params }).then(response => { + dispatch(fetchMarkersSuccess(response.data)); + }).catch(error => { + dispatch(fetchMarkersFail(error)); + }); +}; + +export function fetchMarkersRequest() { + return { + type: MARKERS_FETCH_REQUEST, + skipLoading: true, + }; +}; + +export function fetchMarkersSuccess(markers) { + return { + type: MARKERS_FETCH_SUCCESS, + markers, + skipLoading: true, + }; +}; + +export function fetchMarkersFail(error) { + return { + type: MARKERS_FETCH_FAIL, + error, + skipLoading: true, + skipAlert: true, + }; +}; |