[Perf] Message List: Delay Chat List animation while animating message sending
This commit is contained in:
parent
eeaec02398
commit
d2647df1e6
@ -18,7 +18,6 @@ import {
|
|||||||
} from '../../reducers';
|
} from '../../reducers';
|
||||||
import { GlobalActions, GlobalState } from '../../../global/types';
|
import { GlobalActions, GlobalState } from '../../../global/types';
|
||||||
import {
|
import {
|
||||||
selectChat,
|
|
||||||
selectChatMessage,
|
selectChatMessage,
|
||||||
selectChatMessages,
|
selectChatMessages,
|
||||||
selectIsViewportNewest,
|
selectIsViewportNewest,
|
||||||
@ -33,6 +32,7 @@ import {
|
|||||||
selectScheduledMessages,
|
selectScheduledMessages,
|
||||||
isMessageInCurrentMessageList,
|
isMessageInCurrentMessageList,
|
||||||
selectScheduledIds,
|
selectScheduledIds,
|
||||||
|
selectCurrentMessageList,
|
||||||
} from '../../selectors';
|
} from '../../selectors';
|
||||||
import { getMessageContent, isChatPrivate, isMessageLocal } from '../../helpers';
|
import { getMessageContent, isChatPrivate, isMessageLocal } from '../../helpers';
|
||||||
|
|
||||||
@ -45,12 +45,6 @@ addReducer('apiUpdate', (global, actions, update: ApiUpdate) => {
|
|||||||
global = updateWithLocalMedia(global, chatId, id, message);
|
global = updateWithLocalMedia(global, chatId, id, message);
|
||||||
global = updateListedAndViewportIds(global, message as ApiMessage);
|
global = updateListedAndViewportIds(global, message as ApiMessage);
|
||||||
|
|
||||||
const chat = selectChat(global, chatId);
|
|
||||||
if (chat) {
|
|
||||||
const newMessage = selectChatMessage(global, chatId, id)!;
|
|
||||||
global = updateChatLastMessage(global, chatId, newMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (message.threadInfo) {
|
if (message.threadInfo) {
|
||||||
global = updateThreadInfo(
|
global = updateThreadInfo(
|
||||||
global,
|
global,
|
||||||
@ -62,16 +56,35 @@ addReducer('apiUpdate', (global, actions, update: ApiUpdate) => {
|
|||||||
|
|
||||||
setGlobal(global);
|
setGlobal(global);
|
||||||
|
|
||||||
|
const newMessage = selectChatMessage(global, chatId, id)!;
|
||||||
|
|
||||||
if (isMessageInCurrentMessageList(global, chatId, message as ApiMessage)) {
|
if (isMessageInCurrentMessageList(global, chatId, message as ApiMessage)) {
|
||||||
if (message.isOutgoing && !(message.content && message.content.action)) {
|
if (message.isOutgoing && !(message.content && message.content.action)) {
|
||||||
// TODO Avoid duplicated focusing for the same message when content has not changed
|
const currentMessageList = selectCurrentMessageList(global);
|
||||||
actions.focusLastMessage();
|
if (currentMessageList) {
|
||||||
|
// We do not use `actions.focusLastMessage` as it may be set with a delay (see below)
|
||||||
|
actions.focusMessage({
|
||||||
|
chatId,
|
||||||
|
threadId: currentMessageList.threadId,
|
||||||
|
messageId: message.id,
|
||||||
|
noHighlight: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const { threadInfo } = selectThreadByMessage(global, chatId, message as ApiMessage) || {};
|
const { threadInfo } = selectThreadByMessage(global, chatId, message as ApiMessage) || {};
|
||||||
if (threadInfo) {
|
if (threadInfo) {
|
||||||
actions.requestThreadInfoUpdate({ chatId, threadId: threadInfo.threadId });
|
actions.requestThreadInfoUpdate({ chatId, threadId: threadInfo.threadId });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @perf Wait until scroll animation finishes or simply rely on delivery status update (which is itself delayed)
|
||||||
|
if (!message.isOutgoing) {
|
||||||
|
setTimeout(() => {
|
||||||
|
setGlobal(updateChatLastMessage(getGlobal(), chatId, newMessage));
|
||||||
|
}, ANIMATION_DELAY);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setGlobal(updateChatLastMessage(getGlobal(), chatId, newMessage));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Edge case: New message in an old (not loaded) chat.
|
// Edge case: New message in an old (not loaded) chat.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user