mirror of
https://github.com/danog/telegram-tt.git
synced 2024-12-04 02:28:03 +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 {
|
): ApiChat {
|
||||||
const {
|
const {
|
||||||
peer, folderId, unreadMark, unreadCount, unreadMentionsCount, notifySettings: { silent, muteUntil },
|
peer, folderId, unreadMark, unreadCount, unreadMentionsCount, notifySettings: { silent, muteUntil },
|
||||||
readOutboxMaxId, readInboxMaxId,
|
readOutboxMaxId, readInboxMaxId, draft,
|
||||||
} = dialog;
|
} = dialog;
|
||||||
const isMuted = silent || (typeof muteUntil === 'number' && Date.now() + serverTimeOffset * 1000 < muteUntil * 1000);
|
const isMuted = silent || (typeof muteUntil === 'number' && Date.now() + serverTimeOffset * 1000 < muteUntil * 1000);
|
||||||
|
|
||||||
@ -76,6 +76,7 @@ export function buildApiChatFromDialog(
|
|||||||
unreadMentionsCount,
|
unreadMentionsCount,
|
||||||
isMuted,
|
isMuted,
|
||||||
...(unreadMark && { hasUnreadMark: true }),
|
...(unreadMark && { hasUnreadMark: true }),
|
||||||
|
...(draft instanceof GramJs.DraftMessage && { hasDraft: true }),
|
||||||
...buildApiChatFieldsFromPeerEntity(peerEntity),
|
...buildApiChatFieldsFromPeerEntity(peerEntity),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ export interface ApiChat {
|
|||||||
joinDate?: number;
|
joinDate?: number;
|
||||||
isSupport?: boolean;
|
isSupport?: boolean;
|
||||||
photos?: ApiPhoto[];
|
photos?: ApiPhoto[];
|
||||||
|
hasDraft?: boolean;
|
||||||
|
|
||||||
// Calls
|
// Calls
|
||||||
isCallActive?: boolean;
|
isCallActive?: boolean;
|
||||||
|
@ -29,6 +29,7 @@ import {
|
|||||||
updateOutlyingIds,
|
updateOutlyingIds,
|
||||||
replaceScheduledMessages,
|
replaceScheduledMessages,
|
||||||
updateThreadInfos,
|
updateThreadInfos,
|
||||||
|
updateChat,
|
||||||
} from '../../reducers';
|
} from '../../reducers';
|
||||||
import {
|
import {
|
||||||
selectChat,
|
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) => {
|
addReducer('clearDraft', (global, actions, payload) => {
|
||||||
@ -313,7 +317,10 @@ addReducer('clearDraft', (global, actions, payload) => {
|
|||||||
void callApi('clearDraft', chat);
|
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) => {
|
addReducer('toggleMessageWebPage', (global, actions, payload) => {
|
||||||
|
@ -21,6 +21,7 @@ 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,
|
||||||
@ -145,6 +146,7 @@ async function loadAndReplaceChats() {
|
|||||||
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) => {
|
||||||
|
@ -369,6 +369,7 @@ addReducer('apiUpdate', (global, actions, update: ApiUpdate) => {
|
|||||||
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) });
|
||||||
|
|
||||||
setGlobal(global);
|
setGlobal(global);
|
||||||
}
|
}
|
||||||
|
@ -192,8 +192,14 @@ export function getChatSlowModeOptions(chat?: ApiChat) {
|
|||||||
return chat.fullInfo.slowMode;
|
return chat.fullInfo.slowMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function getChatOrder(chat: ApiChat) {
|
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) {
|
export function isChatArchived(chat: ApiChat) {
|
||||||
|
Loading…
Reference in New Issue
Block a user