Media Viewer: Fix deleting chat photo (follow-up) (#2194)
This commit is contained in:
parent
b712f9dcb2
commit
e319508414
@ -950,23 +950,28 @@ 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;
|
||||||
// Select next photo to set as avatar
|
const photosToDelete = [photo];
|
||||||
const nextPhoto = chat.photos?.[1];
|
if (chat.avatarHash === photo.id) {
|
||||||
setGlobal(updateChat(global, chatId, {
|
// Select next photo to set as avatar
|
||||||
avatarHash: undefined,
|
const nextPhoto = chat.photos?.[1];
|
||||||
fullInfo: {
|
if (nextPhoto) {
|
||||||
...chat.fullInfo,
|
photosToDelete.push(nextPhoto);
|
||||||
profilePhoto: undefined,
|
}
|
||||||
},
|
setGlobal(updateChat(global, chatId, {
|
||||||
}));
|
avatarHash: undefined,
|
||||||
// Set next photo as avatar
|
fullInfo: {
|
||||||
await callApi('editChatPhoto', {
|
...chat.fullInfo,
|
||||||
chatId,
|
profilePhoto: undefined,
|
||||||
accessHash: chat.accessHash,
|
},
|
||||||
photo: nextPhoto,
|
}));
|
||||||
});
|
// Set next photo as avatar
|
||||||
|
await callApi('editChatPhoto', {
|
||||||
|
chatId,
|
||||||
|
accessHash: chat.accessHash,
|
||||||
|
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 });
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user