Chat List: Consider draft date in ordering
This commit is contained in:
parent
7c860f27b3
commit
86053cefaf
@ -76,7 +76,7 @@ export function buildApiChatFromDialog(
|
|||||||
unreadMentionsCount,
|
unreadMentionsCount,
|
||||||
isMuted,
|
isMuted,
|
||||||
...(unreadMark && { hasUnreadMark: true }),
|
...(unreadMark && { hasUnreadMark: true }),
|
||||||
...(draft instanceof GramJs.DraftMessage && { hasDraft: true }),
|
...(draft instanceof GramJs.DraftMessage && { draftDate: draft.date }),
|
||||||
...buildApiChatFieldsFromPeerEntity(peerEntity),
|
...buildApiChatFieldsFromPeerEntity(peerEntity),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -188,9 +188,14 @@ export function buildMessageDraft(draft: GramJs.TypeDraftMessage) {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const {
|
||||||
|
message, entities, replyToMsgId, date,
|
||||||
|
} = draft;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
formattedText: draft.message ? buildMessageTextContent(draft.message, draft.entities) : undefined,
|
formattedText: message ? buildMessageTextContent(message, entities) : undefined,
|
||||||
replyingToId: draft.replyToMsgId,
|
replyingToId: replyToMsgId,
|
||||||
|
date,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -982,7 +982,7 @@ function updateLocalDb(result: (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function importChatInvite({ hash }: {hash: string}) {
|
export async function importChatInvite({ hash }: { hash: string }) {
|
||||||
const updates = await invokeRequest(new GramJs.messages.ImportChatInvite({ hash }), true);
|
const updates = await invokeRequest(new GramJs.messages.ImportChatInvite({ hash }), true);
|
||||||
if (!(updates instanceof GramJs.Updates) || !updates.chats.length) {
|
if (!(updates instanceof GramJs.Updates) || !updates.chats.length) {
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|||||||
@ -771,12 +771,10 @@ export function updater(update: Update, originRequest?: GramJs.AnyRequest) {
|
|||||||
|
|
||||||
// Misc
|
// Misc
|
||||||
} else if (update instanceof GramJs.UpdateDraftMessage) {
|
} else if (update instanceof GramJs.UpdateDraftMessage) {
|
||||||
const { replyingToId, formattedText } = buildMessageDraft(update.draft) || {};
|
|
||||||
onUpdate({
|
onUpdate({
|
||||||
'@type': 'draftMessage',
|
'@type': 'draftMessage',
|
||||||
chatId: getApiChatIdFromMtpPeer(update.peer),
|
chatId: getApiChatIdFromMtpPeer(update.peer),
|
||||||
formattedText,
|
...buildMessageDraft(update.draft),
|
||||||
replyingToId,
|
|
||||||
});
|
});
|
||||||
} else if (update instanceof GramJs.UpdateContactsReset) {
|
} else if (update instanceof GramJs.UpdateContactsReset) {
|
||||||
onUpdate({ '@type': 'updateResetContactList' });
|
onUpdate({ '@type': 'updateResetContactList' });
|
||||||
|
|||||||
@ -29,7 +29,7 @@ export interface ApiChat {
|
|||||||
joinDate?: number;
|
joinDate?: number;
|
||||||
isSupport?: boolean;
|
isSupport?: boolean;
|
||||||
photos?: ApiPhoto[];
|
photos?: ApiPhoto[];
|
||||||
hasDraft?: boolean;
|
draftDate?: number;
|
||||||
|
|
||||||
// Calls
|
// Calls
|
||||||
isCallActive?: boolean;
|
isCallActive?: boolean;
|
||||||
|
|||||||
@ -268,6 +268,7 @@ export type ApiUpdateDraftMessage = {
|
|||||||
'@type': 'draftMessage';
|
'@type': 'draftMessage';
|
||||||
chatId: number;
|
chatId: number;
|
||||||
formattedText?: ApiFormattedText;
|
formattedText?: ApiFormattedText;
|
||||||
|
date?: number;
|
||||||
replyingToId?: number;
|
replyingToId?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -300,7 +300,7 @@ addReducer('saveDraft', (global, actions, payload) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
global = replaceThreadParam(global, chatId, threadId, 'draft', draft);
|
global = replaceThreadParam(global, chatId, threadId, 'draft', draft);
|
||||||
global = updateChat(global, chatId, { hasDraft: true });
|
global = updateChat(global, chatId, { draftDate: Math.round(Date.now() / 1000) });
|
||||||
|
|
||||||
return global;
|
return global;
|
||||||
});
|
});
|
||||||
@ -318,7 +318,7 @@ addReducer('clearDraft', (global, actions, payload) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
global = replaceThreadParam(global, chatId, threadId, 'draft', undefined);
|
global = replaceThreadParam(global, chatId, threadId, 'draft', undefined);
|
||||||
global = updateChat(global, chatId, { hasDraft: false });
|
global = updateChat(global, chatId, { draftDate: undefined });
|
||||||
|
|
||||||
return global;
|
return global;
|
||||||
});
|
});
|
||||||
|
|||||||
@ -21,7 +21,6 @@ import {
|
|||||||
updateChatListSecondaryInfo,
|
updateChatListSecondaryInfo,
|
||||||
updateThreadInfos,
|
updateThreadInfos,
|
||||||
replaceThreadParam,
|
replaceThreadParam,
|
||||||
updateChat,
|
|
||||||
} from '../../reducers';
|
} from '../../reducers';
|
||||||
import {
|
import {
|
||||||
selectUser, selectChat, selectCurrentMessageList, selectDraft, selectChatMessage, selectThreadInfo,
|
selectUser, selectChat, selectCurrentMessageList, selectDraft, selectChatMessage, selectThreadInfo,
|
||||||
@ -143,10 +142,7 @@ async function loadAndReplaceChats() {
|
|||||||
global = updateChatListSecondaryInfo(global, 'active', result);
|
global = updateChatListSecondaryInfo(global, 'active', result);
|
||||||
|
|
||||||
Object.keys(result.draftsById).map(Number).forEach((chatId) => {
|
Object.keys(result.draftsById).map(Number).forEach((chatId) => {
|
||||||
global = replaceThreadParam(
|
global = replaceThreadParam(global, chatId, MAIN_THREAD_ID, 'draft', result.draftsById[chatId]);
|
||||||
global, chatId, MAIN_THREAD_ID, 'draft', result.draftsById[chatId],
|
|
||||||
);
|
|
||||||
global = updateChat(global, chatId, { hasDraft: Boolean(result.draftsById[chatId]) });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Object.keys(result.replyingToById).map(Number).forEach((chatId) => {
|
Object.keys(result.replyingToById).map(Number).forEach((chatId) => {
|
||||||
|
|||||||
@ -363,13 +363,15 @@ addReducer('apiUpdate', (global, actions, update: ApiUpdate) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case 'draftMessage': {
|
case 'draftMessage': {
|
||||||
const { chatId, formattedText, replyingToId } = update;
|
const {
|
||||||
|
chatId, formattedText, date, replyingToId,
|
||||||
|
} = update;
|
||||||
const chat = global.chats.byId[chatId];
|
const chat = global.chats.byId[chatId];
|
||||||
|
|
||||||
if (chat) {
|
if (chat) {
|
||||||
global = replaceThreadParam(global, chatId, MAIN_THREAD_ID, 'draft', formattedText);
|
global = replaceThreadParam(global, chatId, MAIN_THREAD_ID, 'draft', formattedText);
|
||||||
global = replaceThreadParam(global, chatId, MAIN_THREAD_ID, 'replyingToId', replyingToId);
|
global = replaceThreadParam(global, chatId, MAIN_THREAD_ID, 'replyingToId', replyingToId);
|
||||||
global = updateChat(global, chatId, { hasDraft: Boolean(formattedText) });
|
global = updateChat(global, chatId, { draftDate: date });
|
||||||
|
|
||||||
setGlobal(global);
|
setGlobal(global);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -196,9 +196,8 @@ export function getChatSlowModeOptions(chat?: ApiChat) {
|
|||||||
export function getChatOrder(chat: ApiChat) {
|
export function getChatOrder(chat: ApiChat) {
|
||||||
return Math.max(
|
return Math.max(
|
||||||
chat.joinDate || 0,
|
chat.joinDate || 0,
|
||||||
|
chat.draftDate || 0,
|
||||||
chat.lastMessage ? chat.lastMessage.date : 0,
|
chat.lastMessage ? chat.lastMessage.date : 0,
|
||||||
) + (
|
|
||||||
chat.hasDraft ? Date.now() / 1000 : 0
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user