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.
This commit is contained in:
infinite-persistence 2022-05-18 17:01:25 +08:00
parent 245eb39892
commit 79eb28cc55
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
7 changed files with 28 additions and 1 deletions

View file

@ -15,6 +15,7 @@ declare type ContentState = {
// It can/should be '?Array<string>` 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 = {

View file

@ -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';

View file

@ -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,
});
};
}

View file

@ -421,6 +421,7 @@ type SharedData = {
editedCollections: CollectionGroup,
builtinCollections: CollectionGroup,
savedCollections: Array<string>,
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,
},
});
};

View file

@ -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);

View file

@ -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);

View file

@ -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 }) => {