mirror of
https://github.com/danog/telegram-tt.git
synced 2024-11-27 04:45:08 +01:00
Group Chat Info: Fix online members count
This commit is contained in:
parent
ca65c04884
commit
79cde7292b
@ -163,25 +163,6 @@ export function fetchFullChat(chat: ApiChat) {
|
||||
: getFullChatInfo(input as number);
|
||||
}
|
||||
|
||||
export async function fetchSuperGroupOnlines(chat: ApiChat) {
|
||||
const { id, accessHash } = chat;
|
||||
|
||||
const peer = buildInputPeer(id, accessHash);
|
||||
const result = await invokeRequest(new GramJs.messages.GetOnlines({ peer }));
|
||||
|
||||
if (!result) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { onlines } = result;
|
||||
|
||||
onUpdate({
|
||||
'@type': 'updateChat',
|
||||
id,
|
||||
chat: { onlineCount: onlines },
|
||||
});
|
||||
}
|
||||
|
||||
export async function searchChats({ query, limit }: { query: string; limit?: number }) {
|
||||
const result = await invokeRequest(new GramJs.contacts.Search({ q: query, limit }));
|
||||
if (!result) {
|
||||
@ -358,6 +339,7 @@ async function getFullChannelInfo(
|
||||
|
||||
const {
|
||||
about,
|
||||
onlineCount,
|
||||
exportedInvite,
|
||||
slowmodeSeconds,
|
||||
slowmodeNextSendDate,
|
||||
@ -383,6 +365,7 @@ async function getFullChannelInfo(
|
||||
return {
|
||||
fullInfo: {
|
||||
about,
|
||||
onlineCount,
|
||||
inviteLink,
|
||||
slowMode: slowmodeSeconds ? {
|
||||
seconds: slowmodeSeconds,
|
||||
|
@ -7,7 +7,7 @@ export {
|
||||
} from './auth';
|
||||
|
||||
export {
|
||||
fetchChats, fetchFullChat, fetchSuperGroupOnlines, searchChats, requestChatUpdate,
|
||||
fetchChats, fetchFullChat, searchChats, requestChatUpdate,
|
||||
saveDraft, clearDraft, fetchChat, updateChatMutedState,
|
||||
createChannel, joinChannel, leaveChannel, deleteChannel, createGroupChat, editChatPhoto,
|
||||
toggleChatPinned, toggleChatArchived, toggleDialogUnread,
|
||||
|
@ -46,8 +46,6 @@ export interface ApiChat {
|
||||
|
||||
// Obtained from GetFullChat / GetFullChannel
|
||||
fullInfo?: ApiChatFullInfo;
|
||||
// Obtained from GetOnlines
|
||||
onlineCount?: number;
|
||||
// Obtained with UpdateUserTyping or UpdateChatUserTyping updates
|
||||
typingStatus?: ApiTypingStatus;
|
||||
}
|
||||
@ -60,6 +58,7 @@ export interface ApiTypingStatus {
|
||||
|
||||
export interface ApiChatFullInfo {
|
||||
about?: string;
|
||||
onlineCount?: number;
|
||||
members?: ApiChatMember[];
|
||||
kickedMembers?: ApiChatMember[];
|
||||
adminMembers?: ApiChatMember[];
|
||||
|
@ -39,7 +39,7 @@ type StateProps = {
|
||||
areMessagesLoaded: boolean;
|
||||
} & Pick<GlobalState, 'lastSyncTime'>;
|
||||
|
||||
type DispatchProps = Pick<GlobalActions, 'loadFullChat' | 'loadSuperGroupOnlines' | 'openMediaViewer'>;
|
||||
type DispatchProps = Pick<GlobalActions, 'loadFullChat' | 'openMediaViewer'>;
|
||||
|
||||
const GroupChatInfo: FC<OwnProps & StateProps & DispatchProps> = ({
|
||||
typingStatus,
|
||||
@ -54,7 +54,6 @@ const GroupChatInfo: FC<OwnProps & StateProps & DispatchProps> = ({
|
||||
areMessagesLoaded,
|
||||
lastSyncTime,
|
||||
loadFullChat,
|
||||
loadSuperGroupOnlines,
|
||||
openMediaViewer,
|
||||
}) => {
|
||||
const isSuperGroup = chat && isChatSuperGroup(chat);
|
||||
@ -63,12 +62,8 @@ const GroupChatInfo: FC<OwnProps & StateProps & DispatchProps> = ({
|
||||
useEffect(() => {
|
||||
if (chatId && !isMin && withFullInfo && lastSyncTime) {
|
||||
loadFullChat({ chatId });
|
||||
|
||||
if (isSuperGroup) {
|
||||
loadSuperGroupOnlines({ chatId });
|
||||
}
|
||||
}
|
||||
}, [chatId, isMin, lastSyncTime, withFullInfo, loadFullChat, isSuperGroup, loadSuperGroupOnlines]);
|
||||
}, [chatId, isMin, lastSyncTime, withFullInfo, loadFullChat, isSuperGroup]);
|
||||
|
||||
const handleAvatarViewerOpen = useCallback((e: ReactMouseEvent<HTMLDivElement, MouseEvent>, hasPhoto: boolean) => {
|
||||
if (chat && hasPhoto) {
|
||||
@ -167,5 +162,5 @@ export default memo(withGlobal<OwnProps>(
|
||||
lastSyncTime, chat, onlineCount, areMessagesLoaded,
|
||||
};
|
||||
},
|
||||
(setGlobal, actions): DispatchProps => pick(actions, ['loadFullChat', 'loadSuperGroupOnlines', 'openMediaViewer']),
|
||||
(setGlobal, actions): DispatchProps => pick(actions, ['loadFullChat', 'openMediaViewer']),
|
||||
)(GroupChatInfo));
|
||||
|
@ -393,7 +393,7 @@ export type ActionTypes = (
|
||||
// chats
|
||||
'preloadTopChatMessages' | 'loadChats' | 'loadMoreChats' | 'openChat' | 'openChatWithInfo' |
|
||||
'openSupportChat' | 'openTipsChat' |
|
||||
'loadFullChat' | 'loadSuperGroupOnlines' | 'loadTopChats' | 'requestChatUpdate' | 'updateChatMutedState' |
|
||||
'loadFullChat' | 'loadTopChats' | 'requestChatUpdate' | 'updateChatMutedState' |
|
||||
'joinChannel' | 'leaveChannel' | 'deleteChannel' | 'toggleChatPinned' | 'toggleChatArchived' | 'toggleChatUnread' |
|
||||
'loadChatFolders' | 'loadRecommendedChatFolders' | 'editChatFolder' | 'addChatFolder' | 'deleteChatFolder' |
|
||||
'updateChat' | 'toggleSignatures' | 'loadGroupsForDiscussion' | 'linkDiscussionGroup' | 'unlinkDiscussionGroup' |
|
||||
|
@ -53,7 +53,6 @@ const TMP_CHAT_ID = -1;
|
||||
const runThrottledForLoadChats = throttle((cb) => cb(), 1000, true);
|
||||
const runThrottledForLoadTopChats = throttle((cb) => cb(), 3000, true);
|
||||
const runDebouncedForFetchFullChat = debounce((cb) => cb(), 500, false, true);
|
||||
const runDebouncedForFetchOnlines = debounce((cb) => cb(), 500, false, true);
|
||||
|
||||
addReducer('preloadTopChatMessages', (global, actions) => {
|
||||
(async () => {
|
||||
@ -178,16 +177,6 @@ addReducer('loadFullChat', (global, actions, payload) => {
|
||||
}
|
||||
});
|
||||
|
||||
addReducer('loadSuperGroupOnlines', (global, actions, payload) => {
|
||||
const { chatId } = payload!;
|
||||
const chat = selectChat(global, chatId);
|
||||
if (!chat) {
|
||||
return;
|
||||
}
|
||||
|
||||
runDebouncedForFetchOnlines(() => callApi('fetchSuperGroupOnlines', chat));
|
||||
});
|
||||
|
||||
addReducer('loadTopChats', () => {
|
||||
runThrottledForLoadTopChats(() => loadChats('active'));
|
||||
});
|
||||
|
@ -2,10 +2,10 @@ import { ApiChat, MAIN_THREAD_ID } from '../../api/types';
|
||||
import { GlobalState } from '../../global/types';
|
||||
|
||||
import {
|
||||
getPrivateChatUserId, isChatChannel, isChatPrivate, isChatSuperGroup, isHistoryClearMessage, isUserBot, isUserOnline,
|
||||
getPrivateChatUserId, isChatChannel, isChatPrivate, isHistoryClearMessage, isUserBot, isUserOnline,
|
||||
} from '../helpers';
|
||||
import { selectUser } from './users';
|
||||
import { ALL_FOLDER_ID, ARCHIVED_FOLDER_ID } from '../../config';
|
||||
import { ALL_FOLDER_ID, ARCHIVED_FOLDER_ID, CHANNEL_MEMBERS_LIMIT } from '../../config';
|
||||
|
||||
export function selectChat(global: GlobalState, chatId: number): ApiChat | undefined {
|
||||
return global.chats.byId[chatId];
|
||||
@ -34,21 +34,16 @@ export function selectSupportChat(global: GlobalState) {
|
||||
}
|
||||
|
||||
export function selectChatOnlineCount(global: GlobalState, chat: ApiChat) {
|
||||
if (isChatPrivate(chat.id) || isChatChannel(chat)) {
|
||||
if (isChatPrivate(chat.id) || isChatChannel(chat) || !chat.fullInfo) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (isChatSuperGroup(chat)) {
|
||||
return chat.onlineCount;
|
||||
if (!chat.fullInfo.members || chat.fullInfo.members.length === CHANNEL_MEMBERS_LIMIT) {
|
||||
return chat.fullInfo.onlineCount;
|
||||
}
|
||||
|
||||
if (!chat.fullInfo || !chat.fullInfo.members) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const memberIds = chat.fullInfo.members.map((m) => m.userId);
|
||||
return memberIds.reduce((onlineCount, memberId) => {
|
||||
if (global.users.byId[memberId] && isUserOnline(global.users.byId[memberId])) {
|
||||
return chat.fullInfo.members.reduce((onlineCount, { userId }) => {
|
||||
if (global.users.byId[userId] && isUserOnline(global.users.byId[userId]) && userId !== global.currentUserId) {
|
||||
return onlineCount + 1;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user