2021-03-03 20:09:58 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { isNumber } from 'lodash';
|
|
|
|
import { parseIntOrThrow } from '../util/parseIntOrThrow';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { ConfigKeyType } from '../RemoteConfig';
|
|
|
|
import { getValue } from '../RemoteConfig';
|
2021-03-03 20:09:58 +00:00
|
|
|
|
|
|
|
function makeGetter(configKey: ConfigKeyType): (fallback?: number) => number {
|
|
|
|
return fallback => {
|
|
|
|
try {
|
|
|
|
return parseIntOrThrow(
|
|
|
|
getValue(configKey),
|
2021-03-04 23:19:20 +00:00
|
|
|
`Failed to parse ${configKey} as an integer`
|
2021-03-03 20:09:58 +00:00
|
|
|
);
|
|
|
|
} catch (err) {
|
|
|
|
if (isNumber(fallback)) {
|
|
|
|
return fallback;
|
|
|
|
}
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export const getGroupSizeRecommendedLimit = makeGetter(
|
|
|
|
'global.groupsv2.maxGroupSize'
|
|
|
|
);
|
2021-08-17 14:01:27 +00:00
|
|
|
|
2021-03-03 20:09:58 +00:00
|
|
|
export const getGroupSizeHardLimit = makeGetter(
|
|
|
|
'global.groupsv2.groupSizeHardLimit'
|
|
|
|
);
|