Skip to content

Commit 428d7bb

Browse files
zubidenAjaxy
authored andcommitted
[Refactoring] Unify AppConfig and limits (#6139)
1 parent 66fa05a commit 428d7bb

File tree

70 files changed

+374
-292
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+374
-292
lines changed

src/api/gramjs/apiBuilders/appConfig.ts

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,11 @@ import { Api as GramJs } from '../../../lib/gramjs';
33

44
import type { ApiAppConfig, ApiLimitType, ApiPremiumSection } from '../../types';
55

6+
import { omitUndefined } from '../../../util/iteratees';
67
import {
8+
DEFAULT_APP_CONFIG,
79
DEFAULT_LIMITS,
8-
MAX_UNIQUE_REACTIONS,
9-
SERVICE_NOTIFICATIONS_USER_ID,
10-
STORY_EXPIRE_PERIOD,
11-
STORY_VIEWERS_EXPIRE_PERIOD,
12-
TODO_ITEM_LENGTH_LIMIT,
13-
TODO_ITEMS_LIMIT,
14-
TODO_TITLE_LENGTH_LIMIT,
15-
TON_SUGGESTED_POST_AMOUNT_MAX,
16-
TON_SUGGESTED_POST_AMOUNT_MIN,
17-
TON_TOPUP_URL_DEFAULT,
18-
TON_USD_RATE_DEFAULT,
19-
} from '../../../config';
10+
} from '../../../limits';
2011
import localDb from '../localDb';
2112
import { buildJson } from './misc';
2213

@@ -36,7 +27,8 @@ type Limit =
3627
| 'chatlist_invites_limit'
3728
| 'chatlist_joined_limit'
3829
| 'recommended_channels_limit'
39-
| 'saved_dialogs_pinned_limit';
30+
| 'saved_dialogs_pinned_limit'
31+
| 'reactions_user_max';
4032
type LimitKey = `${Limit}_${LimitType}`;
4133
type LimitsConfig = Record<LimitKey, number>;
4234

@@ -57,6 +49,7 @@ export interface GramJsAppConfig extends LimitsConfig {
5749
autologin_domains: string[];
5850
autologin_token: string;
5951
url_auth_domains: string[];
52+
whitelisted_domains: string[];
6053
premium_purchase_blocked: boolean;
6154
giveaway_gifts_purchase_available: boolean;
6255
giveaway_add_peers_max: number;
@@ -74,11 +67,9 @@ export interface GramJsAppConfig extends LimitsConfig {
7467
// Forums
7568
topics_pinned_limit: number;
7669
// Stories
77-
stories_all_hidden?: boolean;
78-
story_expire_period: number;
7970
story_viewers_expire_period: number;
80-
stories_changelog_user_id?: number;
81-
stories_pinned_to_top_count_max?: number;
71+
stories_changelog_user_id: number;
72+
stories_pinned_to_top_count_max: number;
8273
// Boosts
8374
group_transcribe_level_min?: number;
8475
new_noncontact_peers_require_premium_without_ownpremium?: boolean;
@@ -157,23 +148,22 @@ function getLimit(appConfig: GramJsAppConfig, key: Limit, fallbackKey: ApiLimitT
157148
export function buildAppConfig(json: GramJs.TypeJSONValue, hash: number): ApiAppConfig {
158149
const appConfig = buildJson(json) as GramJsAppConfig;
159150

160-
return {
151+
const config: Partial<ApiAppConfig> = {
161152
emojiSounds: buildEmojiSounds(appConfig),
162153
seenByMaxChatMembers: appConfig.chat_read_mark_size_threshold,
163154
seenByExpiresAt: appConfig.chat_read_mark_expire_period,
164155
readDateExpiresAt: appConfig.pm_read_date_expire_period,
165156
autologinDomains: appConfig.autologin_domains || [],
166157
urlAuthDomains: appConfig.url_auth_domains || [],
167-
maxUniqueReactions: appConfig.reactions_uniq_max ?? MAX_UNIQUE_REACTIONS,
158+
whitelistedDomains: appConfig.whitelisted_domains || [],
159+
maxUniqueReactions: appConfig.reactions_uniq_max,
168160
premiumBotUsername: appConfig.premium_bot_username,
169161
premiumInvoiceSlug: appConfig.premium_invoice_slug,
170162
premiumPromoOrder: appConfig.premium_promo_order as ApiPremiumSection[],
171163
isPremiumPurchaseBlocked: appConfig.premium_purchase_blocked,
172164
isGiveawayGiftsPurchaseAvailable: appConfig.giveaway_gifts_purchase_available,
173165
defaultEmojiStatusesStickerSetId: appConfig.default_emoji_statuses_stickerset_id,
174166
topicsPinnedLimit: appConfig.topics_pinned_limit,
175-
maxUserReactionsDefault: appConfig.reactions_user_max_default,
176-
maxUserReactionsPremium: appConfig.reactions_user_max_premium,
177167
hiddenMembersMinCount: appConfig.hidden_members_group_size_min,
178168
giveawayAddPeersMax: appConfig.giveaway_add_peers_max,
179169
giveawayBoostsPerPremium: appConfig.giveaway_boosts_per_premium,
@@ -195,13 +185,12 @@ export function buildAppConfig(json: GramJs.TypeJSONValue, hash: number): ApiApp
195185
chatlistJoined: getLimit(appConfig, 'chatlist_joined_limit', 'chatlistJoined'),
196186
recommendedChannels: getLimit(appConfig, 'recommended_channels_limit', 'recommendedChannels'),
197187
savedDialogsPinned: getLimit(appConfig, 'saved_dialogs_pinned_limit', 'savedDialogsPinned'),
188+
maxReactions: getLimit(appConfig, 'reactions_user_max', 'maxReactions'),
198189
moreAccounts: DEFAULT_LIMITS.moreAccounts,
199190
},
200191
hash,
201-
areStoriesHidden: appConfig.stories_all_hidden,
202-
storyExpirePeriod: appConfig.story_expire_period ?? STORY_EXPIRE_PERIOD,
203-
storyViewersExpirePeriod: appConfig.story_viewers_expire_period ?? STORY_VIEWERS_EXPIRE_PERIOD,
204-
storyChangelogUserId: appConfig.stories_changelog_user_id?.toString() ?? SERVICE_NOTIFICATIONS_USER_ID,
192+
storyViewersExpirePeriod: appConfig.story_viewers_expire_period,
193+
storyChangelogUserId: appConfig.stories_changelog_user_id?.toString(),
205194
maxPinnedStoriesCount: appConfig.stories_pinned_to_top_count_max,
206195
groupTranscribeLevelMin: appConfig.group_transcribe_level_min,
207196
canLimitNewMessagesWithoutPremium: appConfig.new_noncontact_peers_require_premium_without_ownpremium,
@@ -238,18 +227,23 @@ export function buildAppConfig(json: GramJs.TypeJSONValue, hash: number): ApiApp
238227
starsSuggestedPostFutureMax: appConfig.stars_suggested_post_future_max,
239228
starsSuggestedPostFutureMin: appConfig.stars_suggested_post_future_min,
240229
tonSuggestedPostCommissionPermille: appConfig.ton_suggested_post_commission_permille,
241-
tonSuggestedPostAmountMax: appConfig.ton_suggested_post_amount_max ?? TON_SUGGESTED_POST_AMOUNT_MAX,
242-
tonSuggestedPostAmountMin: appConfig.ton_suggested_post_amount_min ?? TON_SUGGESTED_POST_AMOUNT_MIN,
243-
tonUsdRate: appConfig.ton_usd_rate ?? TON_USD_RATE_DEFAULT,
244-
tonTopupUrl: appConfig.ton_topup_url ?? TON_TOPUP_URL_DEFAULT,
230+
tonSuggestedPostAmountMax: appConfig.ton_suggested_post_amount_max,
231+
tonSuggestedPostAmountMin: appConfig.ton_suggested_post_amount_min,
232+
tonUsdRate: appConfig.ton_usd_rate,
233+
tonTopupUrl: appConfig.ton_topup_url,
245234
pollMaxAnswers: appConfig.poll_answers_max,
246-
todoItemsMax: appConfig.todo_items_max ?? TODO_ITEMS_LIMIT,
247-
todoTitleLengthMax: appConfig.todo_title_length_max ?? TODO_TITLE_LENGTH_LIMIT,
248-
todoItemLengthMax: appConfig.todo_item_length_max ?? TODO_ITEM_LENGTH_LIMIT,
235+
todoItemsMax: appConfig.todo_items_max,
236+
todoTitleLengthMax: appConfig.todo_title_length_max,
237+
todoItemLengthMax: appConfig.todo_item_length_max,
249238
ignoreRestrictionReasons: appConfig.ignore_restriction_reasons,
250239
needAgeVideoVerification: appConfig.need_age_video_verification,
251240
verifyAgeBotUsername: appConfig.verify_age_bot_username,
252241
verifyAgeCountry: appConfig.verify_age_country,
253242
verifyAgeMin: appConfig.verify_age_min,
254243
};
244+
245+
return {
246+
...DEFAULT_APP_CONFIG,
247+
...omitUndefined(config),
248+
};
255249
}

src/api/gramjs/methods/calls.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66
ApiChat, ApiGroupCall, ApiPhoneCall, ApiUser,
77
} from '../../types';
88

9-
import { GROUP_CALL_PARTICIPANTS_LIMIT } from '../../../config';
9+
import { GROUP_CALL_PARTICIPANTS_LIMIT } from '../../../limits';
1010
import {
1111
buildApiGroupCall,
1212
buildApiGroupCallParticipant, buildCallProtocol,

src/api/gramjs/methods/chats.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ import {
2727
ARCHIVED_FOLDER_ID,
2828
DEBUG,
2929
GENERAL_TOPIC_ID,
30-
GLOBAL_SEARCH_CONTACTS_LIMIT,
3130
MAX_INT_32,
3231
MEMBERS_LOAD_SLICE,
3332
SERVICE_NOTIFICATIONS_USER_ID,
3433
TOPICS_SLICE,
3534
} from '../../../config';
3635
import { buildCollectionByKey, omitUndefined } from '../../../util/iteratees';
36+
import { GLOBAL_SEARCH_CONTACTS_LIMIT } from '../../../limits';
3737
import {
3838
buildApiChatBotCommands,
3939
buildApiChatFolder,

src/api/gramjs/methods/messages.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,11 @@ import {
3838
} from '../../types';
3939

4040
import {
41-
API_GENERAL_ID_LIMIT,
4241
DEBUG,
4342
GIF_MIME_TYPE,
4443
MAX_INT_32,
4544
MENTION_UNREAD_SLICE,
4645
MESSAGE_ID_REQUIRED_ERROR,
47-
PINNED_MESSAGES_LIMIT,
4846
REACTION_UNREAD_SLICE,
4947
SUPPORTED_PHOTO_CONTENT_TYPES,
5048
SUPPORTED_VIDEO_CONTENT_TYPES,
@@ -54,6 +52,7 @@ import { compact, split } from '../../../util/iteratees';
5452
import { getMessageKey } from '../../../util/keys/messageKey';
5553
import { getServerTime } from '../../../util/serverTime';
5654
import { interpolateArray } from '../../../util/waveform';
55+
import { API_GENERAL_ID_LIMIT, PINNED_MESSAGES_LIMIT } from '../../../limits';
5756
import {
5857
buildApiChatFromPreview,
5958
buildApiSendAsPeerId,

src/api/gramjs/methods/reactions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import type {
55
ApiChat, ApiReaction, ApiSticker,
66
} from '../../types';
77

8+
import { split } from '../../../util/iteratees';
89
import {
910
API_GENERAL_ID_LIMIT,
1011
REACTION_LIST_LIMIT,
1112
RECENT_REACTIONS_LIMIT,
1213
TOP_REACTIONS_LIMIT,
13-
} from '../../../config';
14-
import { split } from '../../../util/iteratees';
14+
} from '../../../limits';
1515
import {
1616
buildApiAvailableEffect,
1717
buildApiAvailableReaction,

src/api/gramjs/methods/settings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ import type {
1818

1919
import {
2020
ACCEPTABLE_USERNAME_ERRORS,
21-
BLOCKED_LIST_LIMIT,
2221
LANG_PACK,
2322
MAX_INT_32,
2423
} from '../../../config';
2524
import { buildCollectionByKey } from '../../../util/iteratees';
25+
import { BLOCKED_LIST_LIMIT } from '../../../limits';
2626
import { buildAppConfig } from '../apiBuilders/appConfig';
2727
import { buildApiPhoto, buildPrivacyRules } from '../apiBuilders/common';
2828
import { buildApiDisallowedGiftsSettings } from '../apiBuilders/gifts';

src/api/gramjs/methods/stories.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import type {
1010
ApiTypeStory,
1111
} from '../../types';
1212

13-
import { MESSAGE_ID_REQUIRED_ERROR, STORY_LIST_LIMIT } from '../../../config';
13+
import { MESSAGE_ID_REQUIRED_ERROR } from '../../../config';
1414
import { buildCollectionByCallback } from '../../../util/iteratees';
15+
import { STORY_LIST_LIMIT } from '../../../limits';
1516
import { buildApiReportResult } from '../apiBuilders/messages';
1617
import { getApiChatIdFromMtpPeer } from '../apiBuilders/peers';
1718
import {

src/api/types/misc.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ export interface ApiAppConfig {
205205
readDateExpiresAt: number;
206206
autologinDomains: string[];
207207
urlAuthDomains: string[];
208+
whitelistedDomains: string[];
208209
premiumInvoiceSlug: string;
209210
premiumBotUsername: string;
210211
isPremiumPurchaseBlocked: boolean;
@@ -217,27 +218,24 @@ export interface ApiAppConfig {
217218
defaultEmojiStatusesStickerSetId: string;
218219
maxUniqueReactions: number;
219220
topicsPinnedLimit: number;
220-
maxUserReactionsDefault: number;
221-
maxUserReactionsPremium: number;
222221
hiddenMembersMinCount: number;
223222
limits: Record<ApiLimitType, readonly [number, number]>;
224223
canDisplayAutoarchiveSetting: boolean;
225-
areStoriesHidden?: boolean;
226-
storyExpirePeriod: number;
227224
storyViewersExpirePeriod: number;
228225
storyChangelogUserId: string;
229-
maxPinnedStoriesCount?: number;
230-
groupTranscribeLevelMin?: number;
231-
canLimitNewMessagesWithoutPremium?: boolean;
226+
maxPinnedStoriesCount: number;
227+
groupTranscribeLevelMin: number;
228+
canLimitNewMessagesWithoutPremium: boolean;
232229
starsPaidMessagesAvailable?: boolean;
233230
starsPaidMessageCommissionPermille?: number;
234231
starsPaidMessageAmountMax?: number;
235-
starsUsdWithdrawRateX1000?: number;
232+
starsUsdWithdrawRateX1000: number;
236233
bandwidthPremiumNotifyPeriod?: number;
237234
bandwidthPremiumUploadSpeedup?: number;
238235
bandwidthPremiumDownloadSpeedup?: number;
239236
channelRestrictAdsLevelMin?: number;
240237
channelAutoTranslationLevelMin?: number;
238+
channelLevelMax: number;
241239
paidReactionMaxAmount?: number;
242240
isChannelRevenueWithdrawalEnabled?: boolean;
243241
isStarsGiftEnabled?: boolean;
@@ -252,24 +250,24 @@ export interface ApiAppConfig {
252250
starsStargiftResaleAmountMin?: number;
253251
starsStargiftResaleAmountMax?: number;
254252
starsStargiftResaleCommissionPermille?: number;
255-
starsSuggestedPostAmountMax?: number;
256-
starsSuggestedPostAmountMin?: number;
257-
starsSuggestedPostCommissionPermille?: number;
258-
starsSuggestedPostAgeMin?: number;
259-
starsSuggestedPostFutureMax?: number;
260-
starsSuggestedPostFutureMin?: number;
261-
tonSuggestedPostCommissionPermille?: number;
262-
tonSuggestedPostAmountMax?: number;
263-
tonSuggestedPostAmountMin?: number;
253+
starsSuggestedPostAmountMax: number;
254+
starsSuggestedPostAmountMin: number;
255+
starsSuggestedPostCommissionPermille: number;
256+
starsSuggestedPostAgeMin: number;
257+
starsSuggestedPostFutureMax: number;
258+
starsSuggestedPostFutureMin: number;
259+
tonSuggestedPostCommissionPermille: number;
260+
tonSuggestedPostAmountMax: number;
261+
tonSuggestedPostAmountMin: number;
264262
tonStargiftResaleAmountMax?: number;
265263
tonStargiftResaleAmountMin?: number;
266264
tonStargiftResaleCommissionPermille?: number;
267265
tonUsdRate?: number;
268-
tonTopupUrl?: string;
266+
tonTopupUrl: string;
269267
pollMaxAnswers?: number;
270-
todoItemsMax?: number;
271-
todoTitleLengthMax?: number;
272-
todoItemLengthMax?: number;
268+
todoItemsMax: number;
269+
todoTitleLengthMax: number;
270+
todoItemLengthMax: number;
273271
ignoreRestrictionReasons?: string[];
274272
needAgeVideoVerification?: boolean;
275273
verifyAgeBotUsername?: string;
@@ -375,14 +373,16 @@ export type ApiLimitType =
375373
| 'chatlistJoined'
376374
| 'recommendedChannels'
377375
| 'savedDialogsPinned'
376+
| 'maxReactions'
378377
| 'moreAccounts';
379378

380379
export type ApiLimitTypeWithModal = Exclude<ApiLimitType, (
381380
'captionLength' | 'aboutLength' | 'stickersFaved' | 'savedGifs' | 'recommendedChannels' | 'moreAccounts'
381+
| 'maxReactions'
382382
)>;
383383

384384
export type ApiLimitTypeForPromo = Exclude<ApiLimitType,
385-
'uploadMaxFileparts' | 'chatlistInvites' | 'chatlistJoined' | 'savedDialogsPinned'
385+
'uploadMaxFileparts' | 'chatlistInvites' | 'chatlistJoined' | 'savedDialogsPinned' | 'maxReactions'
386386
>;
387387

388388
export type ApiPeerNotifySettings = {

src/components/common/Composer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ import { MAIN_THREAD_ID } from '../../api/types';
4747

4848
import {
4949
BASE_EMOJI_KEYWORD_LANG,
50-
DEFAULT_MAX_MESSAGE_LENGTH,
5150
EDITABLE_INPUT_MODAL_ID,
5251
HEART_REACTION,
5352
MAX_UPLOAD_FILEPART_SIZE,
@@ -126,6 +125,7 @@ import parseHtmlAsFormattedText from '../../util/parseHtmlAsFormattedText';
126125
import { insertHtmlInSelection } from '../../util/selection';
127126
import { getServerTime } from '../../util/serverTime';
128127
import windowSize from '../../util/windowSize';
128+
import { DEFAULT_MAX_MESSAGE_LENGTH } from '../../limits';
129129
import applyIosAutoCapitalizationFix from '../middle/composer/helpers/applyIosAutoCapitalizationFix';
130130
import buildAttachment, { prepareAttachmentsToSend } from '../middle/composer/helpers/buildAttachment';
131131
import { buildCustomEmojiHtml } from '../middle/composer/helpers/customEmoji';
@@ -2622,7 +2622,7 @@ export default memo(withGlobal<OwnProps>(
26222622
isAccountFrozen,
26232623
isAppConfigLoaded,
26242624
insertingPeerIdMention,
2625-
pollMaxAnswers: appConfig?.pollMaxAnswers,
2625+
pollMaxAnswers: appConfig.pollMaxAnswers,
26262626
};
26272627
},
26282628
)(Composer));

src/components/common/SensitiveContentConfirmModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const SensitiveContentConfirmModal = ({
5353

5454
export default memo(withGlobal<OwnProps>((global): StateProps => {
5555
const appConfig = global.appConfig;
56-
const verifyAgeMin = appConfig?.verifyAgeMin;
56+
const verifyAgeMin = appConfig.verifyAgeMin;
5757

5858
return {
5959
verifyAgeMin: verifyAgeMin || VERIFY_AGE_MIN_DEFAULT,

0 commit comments

Comments
 (0)