From 79eb28cc552f00fa04902cda9b6bc38fd32ba707 Mon Sep 17 00:00:00 2001 From: infinite-persistence Date: Wed, 18 May 2022 17:01:25 +0800 Subject: [PATCH] Add 'lastViewedAnnouncement' into wallet. This stores the hash for the last viewed announcement. The intention is so that the announcement won't re-appear when logging into another device. However, this does mean that announcements would need to wait until the first sync to decide whether to appear or not, which can be quite a delay. --- flow-typed/content.js | 1 + ui/constants/action_types.js | 1 + ui/redux/actions/content.js | 9 +++++++++ ui/redux/actions/sync.js | 5 +++++ ui/redux/reducers/content.js | 8 ++++++++ ui/redux/selectors/content.js | 1 + ui/store.js | 4 +++- 7 files changed, 28 insertions(+), 1 deletion(-) diff --git a/flow-typed/content.js b/flow-typed/content.js index bd87e39f9..9f8add307 100644 --- a/flow-typed/content.js +++ b/flow-typed/content.js @@ -15,6 +15,7 @@ declare type ContentState = { // It can/should be '?Array` instead -- set it to null, then clients // can cast it to a boolean. That, or rename the variable to `shuffle` if you // don't care about the URLs. + lastViewedAnnouncement: ?string, // undefined = not seen in wallet. }; declare type WatchHistory = { diff --git a/ui/constants/action_types.js b/ui/constants/action_types.js index 1b1833013..29ed99b32 100644 --- a/ui/constants/action_types.js +++ b/ui/constants/action_types.js @@ -143,6 +143,7 @@ export const CLEAR_CONTENT_POSITION = 'CLEAR_CONTENT_POSITION'; export const SET_CONTENT_LAST_VIEWED = 'SET_CONTENT_LAST_VIEWED'; export const CLEAR_CONTENT_HISTORY_URI = 'CLEAR_CONTENT_HISTORY_URI'; export const CLEAR_CONTENT_HISTORY_ALL = 'CLEAR_CONTENT_HISTORY_ALL'; +export const SET_LAST_VIEWED_ANNOUNCEMENT = 'SET_LAST_VIEWED_ANNOUNCEMENT'; export const RECOMMENDATION_UPDATED = 'RECOMMENDATION_UPDATED'; export const RECOMMENDATION_CLICKED = 'RECOMMENDATION_CLICKED'; export const TOGGLE_LOOP_LIST = 'TOGGLE_LOOP_LIST'; diff --git a/ui/redux/actions/content.js b/ui/redux/actions/content.js index f6b6a755c..eeb991c2d 100644 --- a/ui/redux/actions/content.js +++ b/ui/redux/actions/content.js @@ -374,3 +374,12 @@ export function doToggleShuffleList(currentUri: string, collectionId: string, sh } }; } + +export function doSetLastViewedAnnouncement(hash: string) { + return (dispatch: Dispatch) => { + dispatch({ + type: ACTIONS.SET_LAST_VIEWED_ANNOUNCEMENT, + data: hash, + }); + }; +} diff --git a/ui/redux/actions/sync.js b/ui/redux/actions/sync.js index 7f03bf285..6ff7db68d 100644 --- a/ui/redux/actions/sync.js +++ b/ui/redux/actions/sync.js @@ -421,6 +421,7 @@ type SharedData = { editedCollections: CollectionGroup, builtinCollections: CollectionGroup, savedCollections: Array, + lastViewedAnnouncement: string, }, }; @@ -439,6 +440,7 @@ function extractUserState(rawObj: SharedData) { editedCollections, builtinCollections, savedCollections, + lastViewedAnnouncement, } = rawObj.value; return { @@ -454,6 +456,7 @@ function extractUserState(rawObj: SharedData) { ...(editedCollections ? { editedCollections } : {}), ...(builtinCollections ? { builtinCollections } : {}), ...(savedCollections ? { savedCollections } : {}), + ...(lastViewedAnnouncement ? { lastViewedAnnouncement } : {}), }; } @@ -475,6 +478,7 @@ export function doPopulateSharedUserState(sharedSettings: any) { editedCollections, builtinCollections, savedCollections, + lastViewedAnnouncement, } = extractUserState(sharedSettings); dispatch({ type: ACTIONS.USER_STATE_POPULATE, @@ -491,6 +495,7 @@ export function doPopulateSharedUserState(sharedSettings: any) { editedCollections, builtinCollections, savedCollections, + lastViewedAnnouncement, }, }); }; diff --git a/ui/redux/reducers/content.js b/ui/redux/reducers/content.js index bc11272e4..e241e5f0d 100644 --- a/ui/redux/reducers/content.js +++ b/ui/redux/reducers/content.js @@ -13,6 +13,7 @@ const defaultState: ContentState = { recommendationUrls: {}, recommendationClicks: {}, loopList: undefined, + lastViewedAnnouncement: '', }; reducers[ACTIONS.SET_PRIMARY_URI] = (state, action) => @@ -118,6 +119,8 @@ reducers[ACTIONS.CLEAR_CONTENT_HISTORY_URI] = (state, action) => { reducers[ACTIONS.CLEAR_CONTENT_HISTORY_ALL] = (state) => ({ ...state, history: [] }); +reducers[ACTIONS.SET_LAST_VIEWED_ANNOUNCEMENT] = (state, action) => ({ ...state, lastViewedAnnouncement: action.data }); + // reducers[LBRY_REDUX_ACTIONS.PURCHASE_URI_FAILED] = (state, action) => { // return { // ...state, @@ -125,6 +128,11 @@ reducers[ACTIONS.CLEAR_CONTENT_HISTORY_ALL] = (state) => ({ ...state, history: [ // }; // }; +reducers[ACTIONS.USER_STATE_POPULATE] = (state, action) => { + const { lastViewedAnnouncement } = action.data; + return { ...state, lastViewedAnnouncement }; +}; + export default function reducer(state: ContentState = defaultState, action: any) { const handler = reducers[action.type]; if (handler) return handler(state, action); diff --git a/ui/redux/selectors/content.js b/ui/redux/selectors/content.js index 9e939eeb3..b202b4f30 100644 --- a/ui/redux/selectors/content.js +++ b/ui/redux/selectors/content.js @@ -26,6 +26,7 @@ export const selectPlayingUri = (state: State) => selectState(state).playingUri; export const selectPrimaryUri = (state: State) => selectState(state).primaryUri; export const selectListLoop = (state: State) => selectState(state).loopList; export const selectListShuffle = (state: State) => selectState(state).shuffleList; +export const selectLastViewedAnnouncement = (state: State) => selectState(state).lastViewedAnnouncement; export const makeSelectIsPlaying = (uri: string) => createSelector(selectPrimaryUri, (primaryUri) => primaryUri === uri); diff --git a/ui/store.js b/ui/store.js index 2c5dfd5c3..961b55d9b 100644 --- a/ui/store.js +++ b/ui/store.js @@ -45,7 +45,7 @@ function enableBatching(reducer) { }; } -const contentFilter = createFilter('content', ['positions', 'history']); +const contentFilter = createFilter('content', ['positions', 'history', 'lastViewedAnnouncement']); const fileInfoFilter = createFilter('fileInfo', [ 'fileListPublishedSort', 'fileListDownloadedSort', @@ -141,6 +141,7 @@ const triggerSharedStateActions = [ ACTIONS.COLLECTION_DELETE, ACTIONS.COLLECTION_NEW, ACTIONS.COLLECTION_PENDING, + ACTIONS.SET_LAST_VIEWED_ANNOUNCEMENT, // MAYBE COLLECTOIN SAVE // ACTIONS.SET_WELCOME_VERSION, // ACTIONS.SET_ALLOW_ANALYTICS, @@ -183,6 +184,7 @@ const sharedStateFilters = { editedCollections: { source: 'collections', property: 'edited' }, // savedCollections: { source: 'collections', property: 'saved' }, unpublishedCollections: { source: 'collections', property: 'unpublished' }, + lastViewedAnnouncement: { source: 'content', property: 'lastViewedAnnouncement' }, }; const sharedStateCb = ({ dispatch, getState, syncId }) => {