Topics: Show messages count in topic title (#4344)

This commit is contained in:
Alexander Zinchuk 2024-03-08 12:48:48 +01:00
parent 6054151969
commit c96d05bd9f
4 changed files with 22 additions and 2 deletions

View File

@ -165,12 +165,14 @@ export async function fetchMessages({
const messages = result.messages.map(buildApiMessage).filter(Boolean);
const users = result.users.map(buildApiUser).filter(Boolean);
const chats = result.chats.map((c) => buildApiChatFromPreview(c)).filter(Boolean);
const count = !(result instanceof GramJs.messages.Messages) && result.count;
dispatchThreadInfoUpdates(result.messages);
return {
messages,
users,
chats,
count,
};
}

View File

@ -29,6 +29,7 @@ import renderText from './helpers/renderText';
import useLang from '../../hooks/useLang';
import useLastCallback from '../../hooks/useLastCallback';
import Transition from '../ui/Transition';
import Avatar from './Avatar';
import DotAnimation from './DotAnimation';
import FullNameTitle from './FullNameTitle';
@ -172,7 +173,14 @@ const GroupChatInfo: FC<OwnProps & StateProps> = ({
if (isTopic) {
return (
<span className="status" dir="auto">
{messagesCount ? lang('messages', messagesCount, 'i') : renderText(chat.title)}
<Transition
name="fade"
shouldRestoreHeight
activeKey={messagesCount !== undefined ? 1 : 2}
className="message-count-transition"
>
{messagesCount !== undefined && lang('messages', messagesCount, 'i')}
</Transition>
</span>
);
}

View File

@ -275,6 +275,10 @@
max-width: 2.625rem !important;
max-height: 2.625rem !important;
}
.message-count-transition {
height: 1.125rem;
}
}
.Avatar, .topic-header-icon {

View File

@ -1237,7 +1237,7 @@ async function loadViewportMessages<T extends GlobalState>(
}
const {
messages, users, chats,
messages, users, chats, count,
} = result;
global = getGlobal();
@ -1284,6 +1284,12 @@ async function loadViewportMessages<T extends GlobalState>(
}
}
if (count) {
global = updateThreadInfo(global, chat.id, threadId, {
messagesCount: count,
});
}
setGlobal(global);
onLoaded?.();
}