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