Audio Player & Media Viewer: Save last set playback rate (#2508)

This commit is contained in:
Alexander Zinchuk 2023-02-08 00:47:47 +01:00
parent 43082f271b
commit 0f1a523c2f
6 changed files with 54 additions and 3 deletions

View File

@ -22,7 +22,7 @@ addActionHandler('openMediaViewer', (global, actions, payload): ActionReturnType
origin, origin,
isHidden: false, isHidden: false,
volume: volume ?? tabState.mediaViewer.volume, volume: volume ?? tabState.mediaViewer.volume,
playbackRate: playbackRate || tabState.mediaViewer.playbackRate, playbackRate: playbackRate || tabState.mediaViewer.playbackRate || global.mediaViewer.lastPlaybackRate,
isMuted: isMuted || tabState.mediaViewer.isMuted, isMuted: isMuted || tabState.mediaViewer.isMuted,
}, },
forwardMessages: {}, forwardMessages: {},
@ -66,6 +66,14 @@ addActionHandler('setMediaViewerPlaybackRate', (global, actions, payload): Actio
tabId = getCurrentTabId(), tabId = getCurrentTabId(),
} = payload; } = payload;
global = {
...global,
mediaViewer: {
...global.mediaViewer,
lastPlaybackRate: playbackRate,
},
};
return updateTabState(global, { return updateTabState(global, {
mediaViewer: { mediaViewer: {
...selectTabState(global, tabId).mediaViewer, ...selectTabState(global, tabId).mediaViewer,

View File

@ -190,7 +190,10 @@ addActionHandler('openAudioPlayer', (global, actions, payload): ActionReturnType
messageId, messageId,
origin: origin ?? tabState.audioPlayer.origin, origin: origin ?? tabState.audioPlayer.origin,
volume: volume ?? tabState.audioPlayer.volume, volume: volume ?? tabState.audioPlayer.volume,
playbackRate: playbackRate || tabState.audioPlayer.playbackRate, playbackRate: playbackRate || tabState.audioPlayer.playbackRate || global.audioPlayer.lastPlaybackRate,
isPlaybackRateActive: (tabState.audioPlayer.isPlaybackRateActive === undefined
? global.audioPlayer.isLastPlaybackRateActive
: tabState.audioPlayer.isPlaybackRateActive),
isMuted: isMuted || tabState.audioPlayer.isMuted, isMuted: isMuted || tabState.audioPlayer.isMuted,
}, },
}, tabId); }, tabId);
@ -215,6 +218,15 @@ addActionHandler('setAudioPlayerPlaybackRate', (global, actions, payload): Actio
playbackRate, isPlaybackRateActive, tabId = getCurrentTabId(), playbackRate, isPlaybackRateActive, tabId = getCurrentTabId(),
} = payload; } = payload;
global = {
...global,
audioPlayer: {
...global.audioPlayer,
lastPlaybackRate: playbackRate,
isLastPlaybackRateActive: isPlaybackRateActive,
},
};
return updateTabState(global, { return updateTabState(global, {
audioPlayer: { audioPlayer: {
...selectTabState(global, tabId).audioPlayer, ...selectTabState(global, tabId).audioPlayer,
@ -257,7 +269,7 @@ addActionHandler('closeAudioPlayer', (global, actions, payload): ActionReturnTyp
audioPlayer: { audioPlayer: {
volume: tabState.audioPlayer.volume, volume: tabState.audioPlayer.volume,
playbackRate: tabState.audioPlayer.playbackRate, playbackRate: tabState.audioPlayer.playbackRate,
isPlaybackRateActive: undefined, isPlaybackRateActive: tabState.audioPlayer.isPlaybackRateActive,
isMuted: tabState.audioPlayer.isMuted, isMuted: tabState.audioPlayer.isMuted,
}, },
}, tabId); }, tabId);

View File

@ -270,6 +270,14 @@ function unsafeMigrateCache(cached: GlobalState, initialState: GlobalState) {
cached.customEmojis.forEmoji = {}; cached.customEmojis.forEmoji = {};
} }
if (!cached.audioPlayer) {
cached.audioPlayer = initialState.audioPlayer;
}
if (!cached.mediaViewer) {
cached.mediaViewer = initialState.mediaViewer;
}
// TODO Remove in Jan 2023 (this was re-designed but can be hardcoded in cache) // TODO Remove in Jan 2023 (this was re-designed but can be hardcoded in cache)
const { light: lightTheme } = cached.settings.themes; const { light: lightTheme } = cached.settings.themes;
if (lightTheme?.patternColor === 'rgba(90, 110, 70, 0.6)' || !lightTheme?.patternColor) { if (lightTheme?.patternColor === 'rgba(90, 110, 70, 0.6)' || !lightTheme?.patternColor) {
@ -386,6 +394,8 @@ export function serializeGlobal<T extends GlobalState>(global: T) {
'leftColumnWidth', 'leftColumnWidth',
'lastIsChatInfoShown', 'lastIsChatInfoShown',
]), ]),
audioPlayer: global.audioPlayer,
mediaViewer: global.mediaViewer,
customEmojis: reduceCustomEmojis(global), customEmojis: reduceCustomEmojis(global),
users: reduceUsers(global), users: reduceUsers(global),
chats: reduceChats(global), chats: reduceChats(global),

View File

@ -50,6 +50,10 @@ addActionHandler('init', (global, actions, payload): ActionReturnType => {
const initialTabState = cloneDeep(INITIAL_TAB_STATE); const initialTabState = cloneDeep(INITIAL_TAB_STATE);
initialTabState.id = tabId; initialTabState.id = tabId;
initialTabState.isChatInfoShown = Boolean(global.lastIsChatInfoShown); initialTabState.isChatInfoShown = Boolean(global.lastIsChatInfoShown);
initialTabState.audioPlayer.playbackRate = global.audioPlayer.lastPlaybackRate;
initialTabState.audioPlayer.isPlaybackRateActive = global.audioPlayer.isLastPlaybackRateActive;
initialTabState.mediaViewer.playbackRate = global.mediaViewer.lastPlaybackRate;
global = { global = {
...global, ...global,
byTabId: { byTabId: {

View File

@ -17,6 +17,14 @@ export const INITIAL_GLOBAL_STATE: GlobalState = {
serverTimeOffset: 0, serverTimeOffset: 0,
isUpdateAvailable: false, isUpdateAvailable: false,
audioPlayer: {
lastPlaybackRate: DEFAULT_PLAYBACK_RATE,
},
mediaViewer: {
lastPlaybackRate: DEFAULT_PLAYBACK_RATE,
},
authRememberMe: true, authRememberMe: true,
countryList: { countryList: {
phoneCodes: [], phoneCodes: [],

View File

@ -540,6 +540,15 @@ export type GlobalState = {
notificationIndex?: number; notificationIndex?: number;
allNotificationsCount?: number; allNotificationsCount?: number;
audioPlayer: {
lastPlaybackRate: number;
isLastPlaybackRateActive?: boolean;
};
mediaViewer: {
lastPlaybackRate: number;
};
recentlyFoundChatIds?: string[]; recentlyFoundChatIds?: string[];
twoFaSettings: { twoFaSettings: {