Message: Potential fix for missing messages after a long sleep (#5869)
This commit is contained in:
parent
5ceb7a340c
commit
c5b8c0bd73
@ -85,8 +85,6 @@ import { processMessageAndUpdateThreadInfo } from './entityProcessor';
|
||||
import LocalUpdatePremiumFloodWait from './UpdatePremiumFloodWait';
|
||||
import { LocalUpdateChannelPts, LocalUpdatePts } from './UpdatePts';
|
||||
|
||||
const sentMessageIds = new Set();
|
||||
|
||||
export function updater(update: Update) {
|
||||
if (update instanceof UpdateServerTimeOffset) {
|
||||
setServerTimeOffset(update.timeOffset);
|
||||
@ -159,23 +157,22 @@ export function updater(update: Update) {
|
||||
|
||||
if (update instanceof GramJs.UpdateNewScheduledMessage) {
|
||||
sendApiUpdate({
|
||||
'@type': sentMessageIds.has(message.id) ? 'updateScheduledMessage' : 'newScheduledMessage',
|
||||
'@type': 'updateScheduledMessage',
|
||||
id: message.id,
|
||||
chatId: message.chatId,
|
||||
message,
|
||||
poll,
|
||||
isFromNew: true,
|
||||
});
|
||||
} else {
|
||||
// We don't have preview for action or 'via bot' messages, so `newMessage` update here is required
|
||||
const hasLocalCopy = sentMessageIds.has(message.id) && !message.viaBotId && !message.content.action;
|
||||
sendApiUpdate({
|
||||
'@type': hasLocalCopy ? 'updateMessage' : 'newMessage',
|
||||
'@type': 'updateMessage',
|
||||
id: message.id,
|
||||
chatId: message.chatId,
|
||||
message,
|
||||
shouldForceReply,
|
||||
poll,
|
||||
shouldCreateMessageIfNeeded: true,
|
||||
isFromNew: true,
|
||||
});
|
||||
}
|
||||
|
||||
@ -414,8 +411,6 @@ export function updater(update: Update) {
|
||||
message,
|
||||
});
|
||||
}
|
||||
} else if (update instanceof GramJs.UpdateMessageID || update instanceof GramJs.UpdateShortSentMessage) {
|
||||
sentMessageIds.add(update.id);
|
||||
} else if (update instanceof GramJs.UpdateReadMessagesContents) {
|
||||
sendApiUpdate({
|
||||
'@type': 'updateCommonBoxMessages',
|
||||
|
||||
@ -234,7 +234,7 @@ export type ApiUpdateMessage = {
|
||||
message: Partial<ApiMessage>;
|
||||
poll?: ApiPoll;
|
||||
shouldForceReply?: boolean;
|
||||
shouldCreateMessageIfNeeded?: true;
|
||||
isFromNew?: true;
|
||||
};
|
||||
|
||||
export type ApiUpdateScheduledMessage = {
|
||||
@ -243,6 +243,7 @@ export type ApiUpdateScheduledMessage = {
|
||||
id: number;
|
||||
message: Partial<ApiMessage>;
|
||||
poll?: ApiPoll;
|
||||
isFromNew?: true;
|
||||
};
|
||||
|
||||
export type ApiUpdateQuickReplyMessage = {
|
||||
|
||||
@ -254,22 +254,61 @@ addActionHandler('apiUpdate', (global, actions, update): ActionReturnType => {
|
||||
break;
|
||||
}
|
||||
|
||||
case 'updateScheduledMessage': {
|
||||
const {
|
||||
chatId, id, message, poll, isFromNew,
|
||||
} = update;
|
||||
|
||||
const currentMessage = selectScheduledMessage(global, chatId, id);
|
||||
if (!currentMessage) {
|
||||
if (isFromNew) {
|
||||
actions.apiUpdate({
|
||||
'@type': 'newScheduledMessage',
|
||||
id: update.id,
|
||||
chatId: update.chatId,
|
||||
message: update.message as ApiMessage,
|
||||
poll: update.poll,
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
global = updateWithLocalMedia(global, chatId, id, 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);
|
||||
|
||||
const threadId = selectThreadIdFromMessage(global, currentMessage);
|
||||
if (threadId !== MAIN_THREAD_ID) {
|
||||
const threadScheduledIds = selectScheduledIds(global, chatId, threadId) || [];
|
||||
global = replaceThreadParam(global, chatId, threadId, 'scheduledIds', threadScheduledIds.sort((a, b) => b - a));
|
||||
}
|
||||
if (poll) {
|
||||
global = updatePoll(global, poll.id, poll);
|
||||
}
|
||||
|
||||
setGlobal(global);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 'updateMessage': {
|
||||
const {
|
||||
chatId, id, message, poll, shouldCreateMessageIfNeeded, shouldForceReply,
|
||||
chatId, id, message, poll, isFromNew, shouldForceReply,
|
||||
} = update;
|
||||
|
||||
const currentMessage = selectChatMessage(global, chatId, id);
|
||||
|
||||
if (shouldCreateMessageIfNeeded && !currentMessage) {
|
||||
actions.apiUpdate({
|
||||
'@type': 'newMessage',
|
||||
id: update.id,
|
||||
chatId: update.chatId,
|
||||
message: update.message,
|
||||
poll: update.poll,
|
||||
shouldForceReply,
|
||||
});
|
||||
if (!currentMessage) {
|
||||
if (isFromNew) {
|
||||
actions.apiUpdate({
|
||||
'@type': 'newMessage',
|
||||
id: update.id,
|
||||
chatId: update.chatId,
|
||||
message: update.message,
|
||||
poll: update.poll,
|
||||
shouldForceReply,
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -298,34 +337,6 @@ addActionHandler('apiUpdate', (global, actions, update): ActionReturnType => {
|
||||
break;
|
||||
}
|
||||
|
||||
case 'updateScheduledMessage': {
|
||||
const {
|
||||
chatId, id, message, poll,
|
||||
} = update;
|
||||
|
||||
const currentMessage = selectScheduledMessage(global, chatId, id);
|
||||
if (!currentMessage) {
|
||||
return;
|
||||
}
|
||||
|
||||
global = updateWithLocalMedia(global, chatId, id, 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);
|
||||
|
||||
const threadId = selectThreadIdFromMessage(global, currentMessage);
|
||||
if (threadId !== MAIN_THREAD_ID) {
|
||||
const threadScheduledIds = selectScheduledIds(global, chatId, threadId) || [];
|
||||
global = replaceThreadParam(global, chatId, threadId, 'scheduledIds', threadScheduledIds.sort((a, b) => b - a));
|
||||
}
|
||||
if (poll) {
|
||||
global = updatePoll(global, poll.id, poll);
|
||||
}
|
||||
|
||||
setGlobal(global);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 'updateQuickReplyMessage': {
|
||||
const { id, message, poll } = update;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user