mirror of
https://github.com/danog/telegram-tt.git
synced 2024-12-03 10:07:55 +01:00
Chat List: Prioritize chats with drafts when ordering
This commit is contained in:
parent
79550a47bd
commit
3590cf6f5c
@ -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),
|
||||
};
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ export interface ApiChat {
|
||||
joinDate?: number;
|
||||
isSupport?: boolean;
|
||||
photos?: ApiPhoto[];
|
||||
hasDraft?: boolean;
|
||||
|
||||
// Calls
|
||||
isCallActive?: boolean;
|
||||
|
@ -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) => {
|
||||
|
@ -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) => {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user