Message: Fix incorrect update handling (#6266)
This commit is contained in:
parent
10b26966d8
commit
b162650bb6
@ -519,10 +519,10 @@ export function sendApiMessage(
|
||||
}
|
||||
|
||||
sendApiUpdate({
|
||||
'@type': 'updateMessageSendFailed',
|
||||
'@type': localMessage.isScheduled ? 'updateScheduledMessageSendFailed' : 'updateMessageSendFailed',
|
||||
chatId: chat.id,
|
||||
localId: localMessage.id,
|
||||
error: error.message,
|
||||
error: error.errorMessage,
|
||||
});
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
@ -1915,10 +1915,10 @@ export async function forwardApiMessages(params: ForwardMessagesParams) {
|
||||
} catch (error: any) {
|
||||
Object.values(localMessages).forEach((localMessage) => {
|
||||
sendApiUpdate({
|
||||
'@type': 'updateMessageSendFailed',
|
||||
'@type': localMessage.isScheduled ? 'updateScheduledMessageSendFailed' : 'updateMessageSendFailed',
|
||||
chatId: toChat.id,
|
||||
localId: localMessage.id,
|
||||
error: error.message,
|
||||
error: error.errorMessage,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -319,6 +319,13 @@ export type ApiUpdateMessageSendFailed = {
|
||||
error: string;
|
||||
};
|
||||
|
||||
export type ApiUpdateScheduledMessageSendFailed = {
|
||||
'@type': 'updateScheduledMessageSendFailed';
|
||||
chatId: string;
|
||||
localId: number;
|
||||
error: string;
|
||||
};
|
||||
|
||||
export type ApiUpdateCommonBoxMessages = {
|
||||
'@type': 'updateCommonBoxMessages';
|
||||
ids: number[];
|
||||
@ -865,7 +872,7 @@ export type ApiUpdate = (
|
||||
ApiDeleteParticipantHistory | ApiUpdateMessageSendSucceeded | ApiUpdateMessageSendFailed |
|
||||
ApiUpdateServiceNotification | ApiDeleteContact | ApiUpdateUser | ApiUpdateUserStatus |
|
||||
ApiUpdateUserFullInfo | ApiUpdateVideoProcessingPending | ApiUpdatePeerSettings |
|
||||
ApiUpdateAvatar | ApiUpdateMessageImage | ApiUpdateDraftMessage |
|
||||
ApiUpdateAvatar | ApiUpdateMessageImage | ApiUpdateDraftMessage | ApiUpdateScheduledMessageSendFailed |
|
||||
ApiUpdateError | ApiUpdateResetContacts | ApiUpdateStartEmojiInteraction |
|
||||
ApiUpdateFavoriteStickers | ApiUpdateStickerSet | ApiUpdateStickerSets | ApiUpdateStickerSetsOrder |
|
||||
ApiUpdateRecentStickers | ApiUpdateSavedGifs | ApiUpdateNewScheduledMessage | ApiUpdateMoveStickerSetToTop |
|
||||
|
||||
@ -1361,7 +1361,7 @@ addActionHandler('toggleTodoCompleted', (global, actions, payload): ActionReturn
|
||||
content: newContent,
|
||||
};
|
||||
|
||||
global = updateWithLocalMedia(global, chatId, message.id, messageUpdate);
|
||||
global = updateWithLocalMedia(global, chatId, message.id, false, messageUpdate);
|
||||
setGlobal(global);
|
||||
|
||||
callApi('toggleTodoCompleted', { chat, messageId: message.id, completedIds, incompletedIds });
|
||||
|
||||
@ -104,7 +104,7 @@ addActionHandler('apiUpdate', (global, actions, update): ActionReturnType => {
|
||||
const {
|
||||
chatId, id, message, shouldForceReply, wasDrafted, poll, webPage,
|
||||
} = update;
|
||||
global = updateWithLocalMedia(global, chatId, id, message);
|
||||
global = updateWithLocalMedia(global, chatId, id, true, message);
|
||||
global = updateListedAndViewportIds(global, actions, message as ApiMessage);
|
||||
|
||||
const newMessage = selectChatMessage(global, chatId, id)!;
|
||||
@ -236,7 +236,7 @@ addActionHandler('apiUpdate', (global, actions, update): ActionReturnType => {
|
||||
chatId, id, message, poll, webPage,
|
||||
} = update;
|
||||
|
||||
global = updateWithLocalMedia(global, chatId, id, message, true);
|
||||
global = updateWithLocalMedia(global, chatId, id, true, message, true);
|
||||
|
||||
const scheduledIds = selectScheduledIds(global, chatId, MAIN_THREAD_ID) || [];
|
||||
global = replaceThreadParam(global, chatId, MAIN_THREAD_ID, 'scheduledIds', unique([...scheduledIds, id]));
|
||||
@ -284,7 +284,7 @@ addActionHandler('apiUpdate', (global, actions, update): ActionReturnType => {
|
||||
return;
|
||||
}
|
||||
|
||||
global = updateWithLocalMedia(global, chatId, id, message, true);
|
||||
global = updateWithLocalMedia(global, chatId, id, false, message, true);
|
||||
const ids = Object.keys(selectChatScheduledMessages(global, chatId) || {}).map(Number).sort((a, b) => b - a);
|
||||
global = replaceThreadParam(global, chatId, MAIN_THREAD_ID, 'scheduledIds', ids);
|
||||
|
||||
@ -330,7 +330,7 @@ addActionHandler('apiUpdate', (global, actions, update): ActionReturnType => {
|
||||
|
||||
const chat = selectChat(global, chatId);
|
||||
|
||||
global = updateWithLocalMedia(global, chatId, id, message);
|
||||
global = updateWithLocalMedia(global, chatId, id, false, message);
|
||||
|
||||
const newMessage = selectChatMessage(global, chatId, id)!;
|
||||
|
||||
@ -879,6 +879,20 @@ addActionHandler('apiUpdate', (global, actions, update): ActionReturnType => {
|
||||
break;
|
||||
}
|
||||
|
||||
case 'updateScheduledMessageSendFailed': {
|
||||
const { chatId, localId, error } = update;
|
||||
|
||||
if (error.match(/CHAT_SEND_.+?FORBIDDEN/)) {
|
||||
Object.values(global.byTabId).forEach(({ id: tabId }) => {
|
||||
actions.showAllowedMessageTypesNotification({ chatId, tabId });
|
||||
});
|
||||
}
|
||||
|
||||
global = updateScheduledMessage(global, chatId, localId, { sendingState: 'messageSendingStateFailed' });
|
||||
setGlobal(global);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'updateMessageTranslations': {
|
||||
const {
|
||||
chatId, messageIds, toLanguageCode, translations,
|
||||
@ -975,6 +989,7 @@ export function updateWithLocalMedia(
|
||||
global: RequiredGlobalState,
|
||||
chatId: string,
|
||||
id: number,
|
||||
isNew: boolean,
|
||||
messageUpdate: Partial<ApiMessage>,
|
||||
isScheduled = false,
|
||||
) {
|
||||
@ -982,6 +997,8 @@ export function updateWithLocalMedia(
|
||||
? selectScheduledMessage(global, chatId, id)
|
||||
: selectChatMessage(global, chatId, id);
|
||||
|
||||
if (!currentMessage && !isNew) return global;
|
||||
|
||||
// Preserve locally uploaded media.
|
||||
if (currentMessage && messageUpdate.content && !isLocalMessageId(id)) {
|
||||
const {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user