Fix syncing after editing draft on another device (again) (#2113)
This commit is contained in:
parent
ee85cb4441
commit
6fb1f87b17
@ -30,7 +30,7 @@ import {
|
|||||||
selectChat, selectUser, selectChatListType, selectIsChatPinned,
|
selectChat, selectUser, selectChatListType, selectIsChatPinned,
|
||||||
selectChatFolder, selectSupportChat, selectChatByUsername, selectThreadTopMessageId,
|
selectChatFolder, selectSupportChat, selectChatByUsername, selectThreadTopMessageId,
|
||||||
selectCurrentMessageList, selectThreadInfo, selectCurrentChat, selectLastServiceNotification,
|
selectCurrentMessageList, selectThreadInfo, selectCurrentChat, selectLastServiceNotification,
|
||||||
selectVisibleUsers, selectUserByPhoneNumber,
|
selectVisibleUsers, selectUserByPhoneNumber, selectDraft,
|
||||||
} from '../../selectors';
|
} from '../../selectors';
|
||||||
import { buildCollectionByKey, omit } from '../../../util/iteratees';
|
import { buildCollectionByKey, omit } from '../../../util/iteratees';
|
||||||
import { debounce, pause, throttle } from '../../../util/schedulers';
|
import { debounce, pause, throttle } from '../../../util/schedulers';
|
||||||
@ -209,7 +209,7 @@ addActionHandler('loadAllChats', async (global, actions, payload) => {
|
|||||||
.sort((chat1, chat2) => getOrderDate(chat1)! - getOrderDate(chat2)!)[0]
|
.sort((chat1, chat2) => getOrderDate(chat1)! - getOrderDate(chat2)!)[0]
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
await loadChats(listType, oldestChat?.id, oldestChat ? getOrderDate(oldestChat) : undefined, shouldReplace);
|
await loadChats(listType, oldestChat?.id, oldestChat ? getOrderDate(oldestChat) : undefined, shouldReplace, true);
|
||||||
|
|
||||||
if (shouldReplace) {
|
if (shouldReplace) {
|
||||||
onReplace?.();
|
onReplace?.();
|
||||||
@ -1174,7 +1174,11 @@ addActionHandler('processAttachBotParameters', async (global, actions, payload)
|
|||||||
});
|
});
|
||||||
|
|
||||||
async function loadChats(
|
async function loadChats(
|
||||||
listType: 'active' | 'archived', offsetId?: string, offsetDate?: number, shouldReplace = false,
|
listType: 'active' | 'archived',
|
||||||
|
offsetId?: string,
|
||||||
|
offsetDate?: number,
|
||||||
|
shouldReplace = false,
|
||||||
|
isFullDraftSync?: boolean,
|
||||||
) {
|
) {
|
||||||
let global = getGlobal();
|
let global = getGlobal();
|
||||||
const lastLocalServiceMessage = selectLastServiceNotification(global)?.message;
|
const lastLocalServiceMessage = selectLastServiceNotification(global)?.message;
|
||||||
@ -1245,13 +1249,17 @@ async function loadChats(
|
|||||||
|
|
||||||
global = updateChatListSecondaryInfo(global, listType, result);
|
global = updateChatListSecondaryInfo(global, listType, result);
|
||||||
|
|
||||||
Object.keys(result.draftsById).forEach((chatId) => {
|
const idsToUpdateDraft = isFullDraftSync ? result.chatIds : Object.keys(result.draftsById);
|
||||||
global = replaceThreadParam(
|
idsToUpdateDraft.forEach((chatId) => {
|
||||||
global, chatId, MAIN_THREAD_ID, 'draft', result.draftsById[chatId],
|
if (!selectDraft(global, chatId, MAIN_THREAD_ID)?.isLocal) {
|
||||||
);
|
global = replaceThreadParam(
|
||||||
|
global, chatId, MAIN_THREAD_ID, 'draft', result.draftsById[chatId],
|
||||||
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Object.keys(result.replyingToById).forEach((chatId) => {
|
const idsToUpdateReplyingToId = isFullDraftSync ? result.chatIds : Object.keys(result.replyingToById);
|
||||||
|
idsToUpdateReplyingToId.forEach((chatId) => {
|
||||||
global = replaceThreadParam(
|
global = replaceThreadParam(
|
||||||
global, chatId, MAIN_THREAD_ID, 'replyingToId', result.replyingToById[chatId],
|
global, chatId, MAIN_THREAD_ID, 'replyingToId', result.replyingToById[chatId],
|
||||||
);
|
);
|
||||||
|
|||||||
@ -326,30 +326,35 @@ addActionHandler('cancelSendingMessage', (global, actions, payload) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
addActionHandler('saveDraft', (global, actions, payload) => {
|
addActionHandler('saveDraft', async (global, actions, payload) => {
|
||||||
const { chatId, threadId, draft } = payload!;
|
const { chatId, threadId, draft } = payload!;
|
||||||
if (!draft) {
|
if (!draft) {
|
||||||
return undefined;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { text, entities } = draft;
|
const { text, entities } = draft;
|
||||||
const chat = selectChat(global, chatId)!;
|
const chat = selectChat(global, chatId)!;
|
||||||
const user = selectUser(global, chatId)!;
|
const user = selectUser(global, chatId)!;
|
||||||
if (user && isDeletedUser(user)) return undefined;
|
if (user && isDeletedUser(user)) return;
|
||||||
|
|
||||||
if (threadId === MAIN_THREAD_ID) {
|
if (threadId === MAIN_THREAD_ID) {
|
||||||
void callApi('saveDraft', {
|
const result = await callApi('saveDraft', {
|
||||||
chat,
|
chat,
|
||||||
text,
|
text,
|
||||||
entities,
|
entities,
|
||||||
replyToMsgId: selectReplyingToId(global, chatId, threadId),
|
replyToMsgId: selectReplyingToId(global, chatId, threadId),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
|
draft.isLocal = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
global = getGlobal();
|
||||||
|
|
||||||
global = replaceThreadParam(global, chatId, threadId, 'draft', draft);
|
global = replaceThreadParam(global, chatId, threadId, 'draft', draft);
|
||||||
global = updateChat(global, chatId, { draftDate: Math.round(Date.now() / 1000) });
|
global = updateChat(global, chatId, { draftDate: Math.round(Date.now() / 1000) });
|
||||||
|
|
||||||
return global;
|
setGlobal(global);
|
||||||
});
|
});
|
||||||
|
|
||||||
addActionHandler('clearDraft', (global, actions, payload) => {
|
addActionHandler('clearDraft', (global, actions, payload) => {
|
||||||
|
|||||||
@ -113,7 +113,7 @@ export interface Thread {
|
|||||||
editingScheduledId?: number;
|
editingScheduledId?: number;
|
||||||
editingDraft?: ApiFormattedText;
|
editingDraft?: ApiFormattedText;
|
||||||
editingScheduledDraft?: ApiFormattedText;
|
editingScheduledDraft?: ApiFormattedText;
|
||||||
draft?: ApiFormattedText;
|
draft?: ApiFormattedText & { isLocal?: boolean };
|
||||||
noWebPage?: boolean;
|
noWebPage?: boolean;
|
||||||
threadInfo?: ApiThreadInfo;
|
threadInfo?: ApiThreadInfo;
|
||||||
firstMessageId?: number;
|
firstMessageId?: number;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user