Chat List: Prioritize chats with drafts when ordering

This commit is contained in:
Alexander Zinchuk 2021-06-30 00:22:54 +03:00
parent 79550a47bd
commit 3590cf6f5c
6 changed files with 22 additions and 4 deletions

View File

@ -61,7 +61,7 @@ export function buildApiChatFromDialog(
): ApiChat {
const {
peer, folderId, unreadMark, unreadCount, unreadMentionsCount, notifySettings: { silent, muteUntil },
readOutboxMaxId, readInboxMaxId,
readOutboxMaxId, readInboxMaxId, draft,
} = dialog;
const isMuted = silent || (typeof muteUntil === 'number' && Date.now() + serverTimeOffset * 1000 < muteUntil * 1000);
@ -76,6 +76,7 @@ export function buildApiChatFromDialog(
unreadMentionsCount,
isMuted,
...(unreadMark && { hasUnreadMark: true }),
...(draft instanceof GramJs.DraftMessage && { hasDraft: true }),
...buildApiChatFieldsFromPeerEntity(peerEntity),
};
}

View File

@ -29,6 +29,7 @@ export interface ApiChat {
joinDate?: number;
isSupport?: boolean;
photos?: ApiPhoto[];
hasDraft?: boolean;
// Calls
isCallActive?: boolean;

View File

@ -29,6 +29,7 @@ import {
updateOutlyingIds,
replaceScheduledMessages,
updateThreadInfos,
updateChat,
} from '../../reducers';
import {
selectChat,
@ -298,7 +299,10 @@ addReducer('saveDraft', (global, actions, payload) => {
});
}
return replaceThreadParam(global, chatId, threadId, 'draft', draft);
global = replaceThreadParam(global, chatId, threadId, 'draft', draft);
global = updateChat(global, chatId, { hasDraft: true });
return global;
});
addReducer('clearDraft', (global, actions, payload) => {
@ -313,7 +317,10 @@ addReducer('clearDraft', (global, actions, payload) => {
void callApi('clearDraft', chat);
}
return replaceThreadParam(global, chatId, threadId, 'draft', undefined);
global = replaceThreadParam(global, chatId, threadId, 'draft', undefined);
global = updateChat(global, chatId, { hasDraft: false });
return global;
});
addReducer('toggleMessageWebPage', (global, actions, payload) => {

View File

@ -21,6 +21,7 @@ import {
updateChatListSecondaryInfo,
updateThreadInfos,
replaceThreadParam,
updateChat,
} from '../../reducers';
import {
selectUser, selectChat, selectCurrentMessageList, selectDraft, selectChatMessage, selectThreadInfo,
@ -145,6 +146,7 @@ async function loadAndReplaceChats() {
global = replaceThreadParam(
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) => {

View File

@ -369,6 +369,7 @@ addReducer('apiUpdate', (global, actions, update: ApiUpdate) => {
if (chat) {
global = replaceThreadParam(global, chatId, MAIN_THREAD_ID, 'draft', formattedText);
global = replaceThreadParam(global, chatId, MAIN_THREAD_ID, 'replyingToId', replyingToId);
global = updateChat(global, chatId, { hasDraft: Boolean(formattedText) });
setGlobal(global);
}

View File

@ -192,8 +192,14 @@ export function getChatSlowModeOptions(chat?: ApiChat) {
return chat.fullInfo.slowMode;
}
export function getChatOrder(chat: ApiChat) {
return Math.max(chat.joinDate || 0, chat.lastMessage ? chat.lastMessage.date : 0);
return Math.max(
chat.joinDate || 0,
chat.lastMessage ? chat.lastMessage.date : 0,
) + (
chat.hasDraft ? Date.now() / 1000 : 0
);
}
export function isChatArchived(chat: ApiChat) {