From 4033c5b3e635a15f34e48da57aef56c8599ed8bd Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Wed, 26 Jan 2022 23:29:22 +0100 Subject: [PATCH] Seen By: Use config values from the API (#1671) --- src/api/gramjs/apiBuilders/appConfig.ts | 4 ++++ src/api/types/misc.ts | 2 ++ src/components/middle/message/ContextMenuContainer.tsx | 9 ++++++--- src/config.ts | 3 --- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/api/gramjs/apiBuilders/appConfig.ts b/src/api/gramjs/apiBuilders/appConfig.ts index c94973e0..e2a8484b 100644 --- a/src/api/gramjs/apiBuilders/appConfig.ts +++ b/src/api/gramjs/apiBuilders/appConfig.ts @@ -15,6 +15,8 @@ type GramJsAppConfig = { groupcall_video_participants_max: number; reactions_default: string; reactions_uniq_max: number; + chat_read_mark_size_threshold: number; + chat_read_mark_expire_period: number; }; function buildEmojiSounds(appConfig: GramJsAppConfig) { @@ -42,5 +44,7 @@ export function buildApiConfig(json: GramJs.TypeJSONValue): ApiAppConfig { return { emojiSounds: buildEmojiSounds(appConfig), defaultReaction: appConfig.reactions_default, + seenByMaxChatMembers: appConfig.chat_read_mark_size_threshold, + seenByExpiresAt: appConfig.chat_read_mark_expire_period, }; } diff --git a/src/api/types/misc.ts b/src/api/types/misc.ts index 3d0ea81e..a62f4b6b 100644 --- a/src/api/types/misc.ts +++ b/src/api/types/misc.ts @@ -127,6 +127,8 @@ export interface ApiCountryCode extends ApiCountry { export interface ApiAppConfig { emojiSounds: Record; defaultReaction: string; + seenByMaxChatMembers: number; + seenByExpiresAt: number; } export interface GramJsEmojiInteraction { diff --git a/src/components/middle/message/ContextMenuContainer.tsx b/src/components/middle/message/ContextMenuContainer.tsx index 6faa405d..83b07394 100644 --- a/src/components/middle/message/ContextMenuContainer.tsx +++ b/src/components/middle/message/ContextMenuContainer.tsx @@ -17,7 +17,7 @@ import { isActionMessage, isChatChannel, isChatGroup, isOwnMessage, areReactionsEmpty, isUserId, } from '../../../modules/helpers'; -import { SEEN_BY_MEMBERS_EXPIRE, SEEN_BY_MEMBERS_CHAT_MAX, SERVICE_NOTIFICATIONS_USER_ID } from '../../../config'; +import { SERVICE_NOTIFICATIONS_USER_ID } from '../../../config'; import { getDayStartAt } from '../../../util/dateFormat'; import { copyTextToClipboard } from '../../../util/clipboard'; import useShowTransition from '../../../hooks/useShowTransition'; @@ -409,6 +409,7 @@ export default memo(withGlobal( const { threadId } = selectCurrentMessageList(global) || {}; const activeDownloads = selectActiveDownloadIds(global, message.chatId); const chat = selectChat(global, message.chatId); + const { seenByExpiresAt, seenByMaxChatMembers } = global.appConfig || {}; const { noOptions, canReply, @@ -429,12 +430,14 @@ export default memo(withGlobal( const isScheduled = messageListType === 'scheduled'; const isChannel = chat && isChatChannel(chat); const canShowSeenBy = Boolean(chat + && seenByMaxChatMembers + && seenByExpiresAt && isChatGroup(chat) && isOwnMessage(message) && !isScheduled && chat.membersCount - && chat.membersCount < SEEN_BY_MEMBERS_CHAT_MAX - && message.date > Date.now() / 1000 - SEEN_BY_MEMBERS_EXPIRE); + && chat.membersCount < seenByMaxChatMembers + && message.date > Date.now() / 1000 - seenByExpiresAt); const isPrivate = chat && isUserId(chat.id); const isAction = isActionMessage(message); const canShowReactionsCount = !isChannel && !isScheduled && !isAction && !isPrivate && message.reactions diff --git a/src/config.ts b/src/config.ts index 48dab80a..753b64d2 100644 --- a/src/config.ts +++ b/src/config.ts @@ -176,9 +176,6 @@ export const LIGHT_THEME_BG_COLOR = '#A2AF8E'; export const DARK_THEME_BG_COLOR = '#0F0F0F'; export const DARK_THEME_PATTERN_COLOR = '#0a0a0a8c'; export const DEFAULT_PATTERN_COLOR = 'rgba(90, 110, 70, 0.6)'; -// TODO Get values from `getConfig` method once it's available -export const SEEN_BY_MEMBERS_CHAT_MAX = 50; -export const SEEN_BY_MEMBERS_EXPIRE = 604680; // One week - 2 min // Group calls export const GROUP_CALL_VOLUME_MULTIPLIER = 100;