[Refactoring] ApiMessage: Rename threadInfo → repliesThreadInfo
This commit is contained in:
parent
1fef97b82e
commit
5ac9eb9c16
@ -217,7 +217,7 @@ export function buildApiMessageWithChatId(
|
|||||||
...(keyboardButtons && { keyboardButtons, keyboardPlaceholder, isKeyboardSingleUse }),
|
...(keyboardButtons && { keyboardButtons, keyboardPlaceholder, isKeyboardSingleUse }),
|
||||||
...(shouldHideKeyboardButtons && { shouldHideKeyboardButtons }),
|
...(shouldHideKeyboardButtons && { shouldHideKeyboardButtons }),
|
||||||
...(mtpMessage.viaBotId && { viaBotId: buildApiPeerId(mtpMessage.viaBotId, 'user') }),
|
...(mtpMessage.viaBotId && { viaBotId: buildApiPeerId(mtpMessage.viaBotId, 'user') }),
|
||||||
...(replies?.comments && { threadInfo: buildThreadInfo(replies, mtpMessage.id, chatId) }),
|
...(replies?.comments && { repliesThreadInfo: buildThreadInfo(replies, mtpMessage.id, chatId) }),
|
||||||
...(postAuthor && { postAuthorTitle: postAuthor }),
|
...(postAuthor && { postAuthorTitle: postAuthor }),
|
||||||
isProtected,
|
isProtected,
|
||||||
isForwardingAllowed,
|
isForwardingAllowed,
|
||||||
|
|||||||
@ -126,13 +126,13 @@ export async function fetchMessages({
|
|||||||
const messages = result.messages.map(buildApiMessage).filter(Boolean);
|
const messages = result.messages.map(buildApiMessage).filter(Boolean);
|
||||||
const users = result.users.map(buildApiUser).filter(Boolean);
|
const users = result.users.map(buildApiUser).filter(Boolean);
|
||||||
const chats = result.chats.map((c) => buildApiChatFromPreview(c)).filter(Boolean);
|
const chats = result.chats.map((c) => buildApiChatFromPreview(c)).filter(Boolean);
|
||||||
const threadInfos = messages.map(({ threadInfo }) => threadInfo).filter(Boolean);
|
const repliesThreadInfos = messages.map(({ repliesThreadInfo }) => repliesThreadInfo).filter(Boolean);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
messages,
|
messages,
|
||||||
users,
|
users,
|
||||||
chats,
|
chats,
|
||||||
threadInfos,
|
repliesThreadInfos,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -409,7 +409,7 @@ export interface ApiMessage {
|
|||||||
keyboardPlaceholder?: string;
|
keyboardPlaceholder?: string;
|
||||||
isKeyboardSingleUse?: boolean;
|
isKeyboardSingleUse?: boolean;
|
||||||
viaBotId?: string;
|
viaBotId?: string;
|
||||||
threadInfo?: ApiThreadInfo;
|
repliesThreadInfo?: ApiThreadInfo;
|
||||||
postAuthorTitle?: string;
|
postAuthorTitle?: string;
|
||||||
isScheduled?: boolean;
|
isScheduled?: boolean;
|
||||||
shouldHideKeyboardButtons?: boolean;
|
shouldHideKeyboardButtons?: boolean;
|
||||||
|
|||||||
@ -216,7 +216,7 @@ type StateProps = {
|
|||||||
canAutoPlayMedia?: boolean;
|
canAutoPlayMedia?: boolean;
|
||||||
shouldLoopStickers?: boolean;
|
shouldLoopStickers?: boolean;
|
||||||
autoLoadFileMaxSizeMb: number;
|
autoLoadFileMaxSizeMb: number;
|
||||||
threadInfo?: ApiThreadInfo;
|
repliesThreadInfo?: ApiThreadInfo;
|
||||||
reactionMessage?: ApiMessage;
|
reactionMessage?: ApiMessage;
|
||||||
availableReactions?: ApiAvailableReaction[];
|
availableReactions?: ApiAvailableReaction[];
|
||||||
defaultReaction?: ApiReaction;
|
defaultReaction?: ApiReaction;
|
||||||
@ -318,7 +318,7 @@ const Message: FC<OwnProps & StateProps> = ({
|
|||||||
canAutoPlayMedia,
|
canAutoPlayMedia,
|
||||||
shouldLoopStickers,
|
shouldLoopStickers,
|
||||||
autoLoadFileMaxSizeMb,
|
autoLoadFileMaxSizeMb,
|
||||||
threadInfo,
|
repliesThreadInfo,
|
||||||
hasUnreadReaction,
|
hasUnreadReaction,
|
||||||
memoFirstUnreadIdRef,
|
memoFirstUnreadIdRef,
|
||||||
animationLevel,
|
animationLevel,
|
||||||
@ -379,7 +379,7 @@ const Message: FC<OwnProps & StateProps> = ({
|
|||||||
const isOwn = isOwnMessage(message);
|
const isOwn = isOwnMessage(message);
|
||||||
const isScheduled = messageListType === 'scheduled' || message.isScheduled;
|
const isScheduled = messageListType === 'scheduled' || message.isScheduled;
|
||||||
const hasReply = isReplyMessage(message) && !shouldHideReply;
|
const hasReply = isReplyMessage(message) && !shouldHideReply;
|
||||||
const hasThread = Boolean(threadInfo) && messageListType === 'thread';
|
const hasThread = Boolean(repliesThreadInfo) && messageListType === 'thread';
|
||||||
const isCustomShape = getMessageCustomShape(message);
|
const isCustomShape = getMessageCustomShape(message);
|
||||||
const hasAnimatedEmoji = isCustomShape && (animatedEmoji || animatedCustomEmoji);
|
const hasAnimatedEmoji = isCustomShape && (animatedEmoji || animatedCustomEmoji);
|
||||||
const hasReactions = reactionMessage?.reactions && !areReactionsEmpty(reactionMessage.reactions);
|
const hasReactions = reactionMessage?.reactions && !areReactionsEmpty(reactionMessage.reactions);
|
||||||
@ -531,7 +531,8 @@ const Message: FC<OwnProps & StateProps> = ({
|
|||||||
|
|
||||||
const { phoneCall } = action || {};
|
const { phoneCall } = action || {};
|
||||||
|
|
||||||
const withCommentButton = threadInfo && !isInDocumentGroupNotLast && messageListType === 'thread' && !noComments;
|
const withCommentButton = repliesThreadInfo && !isInDocumentGroupNotLast && messageListType === 'thread'
|
||||||
|
&& !noComments;
|
||||||
const withQuickReactionButton = !IS_TOUCH_ENV && !phoneCall && !isInSelectMode && defaultReaction
|
const withQuickReactionButton = !IS_TOUCH_ENV && !phoneCall && !isInSelectMode && defaultReaction
|
||||||
&& !isInDocumentGroupNotLast;
|
&& !isInDocumentGroupNotLast;
|
||||||
|
|
||||||
@ -542,7 +543,7 @@ const Message: FC<OwnProps & StateProps> = ({
|
|||||||
asForwarded,
|
asForwarded,
|
||||||
hasThread,
|
hasThread,
|
||||||
forceSenderName,
|
forceSenderName,
|
||||||
hasComments: threadInfo && threadInfo?.messagesCount > 0,
|
hasComments: repliesThreadInfo && repliesThreadInfo.messagesCount > 0,
|
||||||
hasActionButton: canForward || canFocus,
|
hasActionButton: canForward || canFocus,
|
||||||
hasReactions,
|
hasReactions,
|
||||||
isGeoLiveActive: location?.type === 'geoLive' && !isGeoLiveExpired(message, getServerTime(serverTimeOffset)),
|
isGeoLiveActive: location?.type === 'geoLive' && !isGeoLiveExpired(message, getServerTime(serverTimeOffset)),
|
||||||
@ -1122,7 +1123,7 @@ const Message: FC<OwnProps & StateProps> = ({
|
|||||||
<i className="icon-arrow-right" />
|
<i className="icon-arrow-right" />
|
||||||
</Button>
|
</Button>
|
||||||
) : undefined}
|
) : undefined}
|
||||||
{withCommentButton && <CommentButton threadInfo={threadInfo!} disabled={noComments} />}
|
{withCommentButton && <CommentButton threadInfo={repliesThreadInfo!} disabled={noComments} />}
|
||||||
{withAppendix && (
|
{withAppendix && (
|
||||||
<div className="svg-appendix" dangerouslySetInnerHTML={isOwn ? APPENDIX_OWN : APPENDIX_NOT_OWN} />
|
<div className="svg-appendix" dangerouslySetInnerHTML={isOwn ? APPENDIX_OWN : APPENDIX_NOT_OWN} />
|
||||||
)}
|
)}
|
||||||
@ -1179,7 +1180,8 @@ export default memo(withGlobal<OwnProps>(
|
|||||||
message, album, withSenderName, withAvatar, threadId, messageListType, isLastInDocumentGroup, isFirstInGroup,
|
message, album, withSenderName, withAvatar, threadId, messageListType, isLastInDocumentGroup, isFirstInGroup,
|
||||||
} = ownProps;
|
} = ownProps;
|
||||||
const {
|
const {
|
||||||
id, chatId, viaBotId, replyToChatId, replyToMessageId, isOutgoing, threadInfo, forwardInfo, transcriptionId,
|
id, chatId, viaBotId, replyToChatId, replyToMessageId, isOutgoing, repliesThreadInfo, forwardInfo,
|
||||||
|
transcriptionId,
|
||||||
} = message;
|
} = message;
|
||||||
|
|
||||||
const chat = selectChat(global, chatId);
|
const chat = selectChat(global, chatId);
|
||||||
@ -1237,8 +1239,8 @@ export default memo(withGlobal<OwnProps>(
|
|||||||
|
|
||||||
const { canReply } = (messageListType === 'thread' && selectAllowedMessageActions(global, message, threadId)) || {};
|
const { canReply } = (messageListType === 'thread' && selectAllowedMessageActions(global, message, threadId)) || {};
|
||||||
const isDownloading = selectIsDownloading(global, message);
|
const isDownloading = selectIsDownloading(global, message);
|
||||||
const actualThreadInfo = threadInfo
|
const actualRepliesThreadInfo = repliesThreadInfo
|
||||||
? selectThreadInfo(global, threadInfo.chatId, threadInfo.threadId) || threadInfo
|
? selectThreadInfo(global, repliesThreadInfo.chatId, repliesThreadInfo.threadId) || repliesThreadInfo
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
const isInDocumentGroup = Boolean(message.groupedId) && !message.isInAlbum;
|
const isInDocumentGroup = Boolean(message.groupedId) && !message.isInAlbum;
|
||||||
@ -1296,7 +1298,7 @@ export default memo(withGlobal<OwnProps>(
|
|||||||
canAutoPlayMedia: selectCanAutoPlayMedia(global, message),
|
canAutoPlayMedia: selectCanAutoPlayMedia(global, message),
|
||||||
autoLoadFileMaxSizeMb: global.settings.byKey.autoLoadFileMaxSizeMb,
|
autoLoadFileMaxSizeMb: global.settings.byKey.autoLoadFileMaxSizeMb,
|
||||||
shouldLoopStickers: selectShouldLoopStickers(global),
|
shouldLoopStickers: selectShouldLoopStickers(global),
|
||||||
threadInfo: actualThreadInfo,
|
repliesThreadInfo: actualRepliesThreadInfo,
|
||||||
availableReactions: global.availableReactions,
|
availableReactions: global.availableReactions,
|
||||||
defaultReaction: isMessageLocal(message) ? undefined : selectDefaultReaction(global, chatId),
|
defaultReaction: isMessageLocal(message) ? undefined : selectDefaultReaction(global, chatId),
|
||||||
activeReactions: reactionMessage && global.activeReactions[reactionMessage.id],
|
activeReactions: reactionMessage && global.activeReactions[reactionMessage.id],
|
||||||
|
|||||||
@ -113,10 +113,10 @@ addActionHandler('openChat', (global, actions, payload) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Please telegram send us some updates about linked chat 🙏
|
// Please telegram send us some updates about linked chat 🙏
|
||||||
if (chat?.lastMessage?.threadInfo) {
|
if (chat?.lastMessage?.repliesThreadInfo) {
|
||||||
actions.requestThreadInfoUpdate({
|
actions.requestThreadInfoUpdate({
|
||||||
chatId: chat.lastMessage.threadInfo.chatId,
|
chatId: chat.lastMessage.repliesThreadInfo.chatId,
|
||||||
threadId: chat.lastMessage.threadInfo.threadId,
|
threadId: chat.lastMessage.repliesThreadInfo.threadId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -851,7 +851,7 @@ async function loadViewportMessages(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const {
|
const {
|
||||||
messages, users, chats, threadInfos,
|
messages, users, chats, repliesThreadInfos,
|
||||||
} = result;
|
} = result;
|
||||||
|
|
||||||
let global = getGlobal();
|
let global = getGlobal();
|
||||||
@ -870,7 +870,7 @@ async function loadViewportMessages(
|
|||||||
|
|
||||||
global = addUsers(global, buildCollectionByKey(users, 'id'));
|
global = addUsers(global, buildCollectionByKey(users, 'id'));
|
||||||
global = addChats(global, buildCollectionByKey(chats, 'id'));
|
global = addChats(global, buildCollectionByKey(chats, 'id'));
|
||||||
global = updateThreadInfos(global, chatId, threadInfos);
|
global = updateThreadInfos(global, chatId, repliesThreadInfos);
|
||||||
|
|
||||||
let listedIds = selectListedIds(global, chatId, threadId);
|
let listedIds = selectListedIds(global, chatId, threadId);
|
||||||
const outlyingIds = selectOutlyingIds(global, chatId, threadId);
|
const outlyingIds = selectOutlyingIds(global, chatId, threadId);
|
||||||
|
|||||||
@ -139,7 +139,7 @@ async function loadAndReplaceMessages() {
|
|||||||
global = safeReplaceViewportIds(global, activeCurrentChatId, activeThreadId, listedIds);
|
global = safeReplaceViewportIds(global, activeCurrentChatId, activeThreadId, listedIds);
|
||||||
global = updateChats(global, buildCollectionByKey(result.chats, 'id'));
|
global = updateChats(global, buildCollectionByKey(result.chats, 'id'));
|
||||||
global = updateUsers(global, buildCollectionByKey(result.users, 'id'));
|
global = updateUsers(global, buildCollectionByKey(result.users, 'id'));
|
||||||
global = updateThreadInfos(global, activeCurrentChatId, result.threadInfos);
|
global = updateThreadInfos(global, activeCurrentChatId, result.repliesThreadInfos);
|
||||||
|
|
||||||
areMessagesLoaded = true;
|
areMessagesLoaded = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -67,12 +67,12 @@ addActionHandler('apiUpdate', (global, actions, update) => {
|
|||||||
global = updateWithLocalMedia(global, chatId, id, message);
|
global = updateWithLocalMedia(global, chatId, id, message);
|
||||||
global = updateListedAndViewportIds(global, actions, message as ApiMessage);
|
global = updateListedAndViewportIds(global, actions, message as ApiMessage);
|
||||||
|
|
||||||
if (message.threadInfo) {
|
if (message.repliesThreadInfo) {
|
||||||
global = updateThreadInfo(
|
global = updateThreadInfo(
|
||||||
global,
|
global,
|
||||||
message.threadInfo.chatId,
|
message.repliesThreadInfo.chatId,
|
||||||
message.threadInfo.threadId,
|
message.repliesThreadInfo.threadId,
|
||||||
message.threadInfo,
|
message.repliesThreadInfo,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,12 +185,12 @@ addActionHandler('apiUpdate', (global, actions, update) => {
|
|||||||
global = updateWithLocalMedia(global, chatId, id, message);
|
global = updateWithLocalMedia(global, chatId, id, message);
|
||||||
|
|
||||||
const newMessage = selectChatMessage(global, chatId, id)!;
|
const newMessage = selectChatMessage(global, chatId, id)!;
|
||||||
if (message.threadInfo) {
|
if (message.repliesThreadInfo) {
|
||||||
global = updateThreadInfo(
|
global = updateThreadInfo(
|
||||||
global,
|
global,
|
||||||
message.threadInfo.chatId,
|
message.repliesThreadInfo.chatId,
|
||||||
message.threadInfo.threadId,
|
message.repliesThreadInfo.threadId,
|
||||||
message.threadInfo,
|
message.repliesThreadInfo,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,7 +213,7 @@ addActionHandler('apiUpdate', (global, actions, update) => {
|
|||||||
&& chat.lastMessage?.id === message.id
|
&& chat.lastMessage?.id === message.id
|
||||||
&& selectIsChatWithBot(global, chat)
|
&& selectIsChatWithBot(global, chat)
|
||||||
&& selectIsMessageInCurrentMessageList(global, chatId, message as ApiMessage)
|
&& selectIsMessageInCurrentMessageList(global, chatId, message as ApiMessage)
|
||||||
&& selectIsViewportNewest(global, chatId, message.threadInfo?.threadId || MAIN_THREAD_ID)
|
&& selectIsViewportNewest(global, chatId, message.repliesThreadInfo?.threadId || MAIN_THREAD_ID)
|
||||||
) {
|
) {
|
||||||
actions.focusLastMessage();
|
actions.focusLastMessage();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -271,7 +271,7 @@ export function deleteChatMessages(
|
|||||||
global = updateCurrentMessageList(global, chatId);
|
global = updateCurrentMessageList(global, chatId);
|
||||||
}
|
}
|
||||||
if (originalPost) {
|
if (originalPost) {
|
||||||
global = updateChatMessage(global, fromChatId!, fromMessageId!, { threadInfo: undefined });
|
global = updateChatMessage(global, fromChatId!, fromMessageId!, { repliesThreadInfo: undefined });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user