Audio Player & Media Viewer: Save last set playback rate (#2508)
This commit is contained in:
parent
43082f271b
commit
0f1a523c2f
@ -22,7 +22,7 @@ addActionHandler('openMediaViewer', (global, actions, payload): ActionReturnType
|
||||
origin,
|
||||
isHidden: false,
|
||||
volume: volume ?? tabState.mediaViewer.volume,
|
||||
playbackRate: playbackRate || tabState.mediaViewer.playbackRate,
|
||||
playbackRate: playbackRate || tabState.mediaViewer.playbackRate || global.mediaViewer.lastPlaybackRate,
|
||||
isMuted: isMuted || tabState.mediaViewer.isMuted,
|
||||
},
|
||||
forwardMessages: {},
|
||||
@ -66,6 +66,14 @@ addActionHandler('setMediaViewerPlaybackRate', (global, actions, payload): Actio
|
||||
tabId = getCurrentTabId(),
|
||||
} = payload;
|
||||
|
||||
global = {
|
||||
...global,
|
||||
mediaViewer: {
|
||||
...global.mediaViewer,
|
||||
lastPlaybackRate: playbackRate,
|
||||
},
|
||||
};
|
||||
|
||||
return updateTabState(global, {
|
||||
mediaViewer: {
|
||||
...selectTabState(global, tabId).mediaViewer,
|
||||
|
||||
@ -190,7 +190,10 @@ addActionHandler('openAudioPlayer', (global, actions, payload): ActionReturnType
|
||||
messageId,
|
||||
origin: origin ?? tabState.audioPlayer.origin,
|
||||
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,
|
||||
},
|
||||
}, tabId);
|
||||
@ -215,6 +218,15 @@ addActionHandler('setAudioPlayerPlaybackRate', (global, actions, payload): Actio
|
||||
playbackRate, isPlaybackRateActive, tabId = getCurrentTabId(),
|
||||
} = payload;
|
||||
|
||||
global = {
|
||||
...global,
|
||||
audioPlayer: {
|
||||
...global.audioPlayer,
|
||||
lastPlaybackRate: playbackRate,
|
||||
isLastPlaybackRateActive: isPlaybackRateActive,
|
||||
},
|
||||
};
|
||||
|
||||
return updateTabState(global, {
|
||||
audioPlayer: {
|
||||
...selectTabState(global, tabId).audioPlayer,
|
||||
@ -257,7 +269,7 @@ addActionHandler('closeAudioPlayer', (global, actions, payload): ActionReturnTyp
|
||||
audioPlayer: {
|
||||
volume: tabState.audioPlayer.volume,
|
||||
playbackRate: tabState.audioPlayer.playbackRate,
|
||||
isPlaybackRateActive: undefined,
|
||||
isPlaybackRateActive: tabState.audioPlayer.isPlaybackRateActive,
|
||||
isMuted: tabState.audioPlayer.isMuted,
|
||||
},
|
||||
}, tabId);
|
||||
|
||||
@ -270,6 +270,14 @@ function unsafeMigrateCache(cached: GlobalState, initialState: GlobalState) {
|
||||
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)
|
||||
const { light: lightTheme } = cached.settings.themes;
|
||||
if (lightTheme?.patternColor === 'rgba(90, 110, 70, 0.6)' || !lightTheme?.patternColor) {
|
||||
@ -386,6 +394,8 @@ export function serializeGlobal<T extends GlobalState>(global: T) {
|
||||
'leftColumnWidth',
|
||||
'lastIsChatInfoShown',
|
||||
]),
|
||||
audioPlayer: global.audioPlayer,
|
||||
mediaViewer: global.mediaViewer,
|
||||
customEmojis: reduceCustomEmojis(global),
|
||||
users: reduceUsers(global),
|
||||
chats: reduceChats(global),
|
||||
|
||||
@ -50,6 +50,10 @@ addActionHandler('init', (global, actions, payload): ActionReturnType => {
|
||||
const initialTabState = cloneDeep(INITIAL_TAB_STATE);
|
||||
initialTabState.id = tabId;
|
||||
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,
|
||||
byTabId: {
|
||||
|
||||
@ -17,6 +17,14 @@ export const INITIAL_GLOBAL_STATE: GlobalState = {
|
||||
serverTimeOffset: 0,
|
||||
isUpdateAvailable: false,
|
||||
|
||||
audioPlayer: {
|
||||
lastPlaybackRate: DEFAULT_PLAYBACK_RATE,
|
||||
},
|
||||
|
||||
mediaViewer: {
|
||||
lastPlaybackRate: DEFAULT_PLAYBACK_RATE,
|
||||
},
|
||||
|
||||
authRememberMe: true,
|
||||
countryList: {
|
||||
phoneCodes: [],
|
||||
|
||||
@ -540,6 +540,15 @@ export type GlobalState = {
|
||||
notificationIndex?: number;
|
||||
allNotificationsCount?: number;
|
||||
|
||||
audioPlayer: {
|
||||
lastPlaybackRate: number;
|
||||
isLastPlaybackRateActive?: boolean;
|
||||
};
|
||||
|
||||
mediaViewer: {
|
||||
lastPlaybackRate: number;
|
||||
};
|
||||
|
||||
recentlyFoundChatIds?: string[];
|
||||
|
||||
twoFaSettings: {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user