Media Viewer: Fix deleting chat photo (follow-up) (#2194)

This commit is contained in:
Alexander Zinchuk 2022-12-07 17:38:27 +01:00
parent b712f9dcb2
commit e319508414

View File

@ -950,8 +950,13 @@ addActionHandler('deleteChatPhoto', async (global, actions, payload) => {
const { photo, chatId } = payload; const { photo, chatId } = payload;
const chat = selectChat(global, chatId); const chat = selectChat(global, chatId);
if (!chat) return; if (!chat) return;
const photosToDelete = [photo];
if (chat.avatarHash === photo.id) {
// Select next photo to set as avatar // Select next photo to set as avatar
const nextPhoto = chat.photos?.[1]; const nextPhoto = chat.photos?.[1];
if (nextPhoto) {
photosToDelete.push(nextPhoto);
}
setGlobal(updateChat(global, chatId, { setGlobal(updateChat(global, chatId, {
avatarHash: undefined, avatarHash: undefined,
fullInfo: { fullInfo: {
@ -965,8 +970,8 @@ addActionHandler('deleteChatPhoto', async (global, actions, payload) => {
accessHash: chat.accessHash, accessHash: chat.accessHash,
photo: nextPhoto, photo: nextPhoto,
}); });
}
// Delete references to the old photos // Delete references to the old photos
const photosToDelete = [photo, nextPhoto].filter(Boolean);
const result = await callApi('deleteProfilePhotos', photosToDelete); const result = await callApi('deleteProfilePhotos', photosToDelete);
if (!result) return; if (!result) return;
actions.loadFullChat({ chatId }); actions.loadFullChat({ chatId });