MCPcopy
hub / github.com/signalapp/Signal-Desktop / _refreshRemoteConfig

Function _refreshRemoteConfig

ts/RemoteConfig.dom.ts:182–342  ·  view source on GitHub ↗
({
  getConfig,
  storage,
}: OptionsType)

Source from the content-addressed store, hash-verified

180}
181
182export const _refreshRemoteConfig = async ({
183 getConfig,
184 storage,
185}: OptionsType): Promise<void> => {
186 const now = Date.now();
187 const oldConfigHash = storage.get('remoteConfigHash');
188
189 const {
190 config: newConfig,
191 serverTimestamp,
192 configHash,
193 } = await getConfig(oldConfigHash);
194
195 const serverTimeSkew = serverTimestamp - now;
196
197 if (Math.abs(serverTimeSkew) > HOUR) {
198 log.warn(
199 'Remote Config: severe clock skew detected. ' +
200 `Server time ${serverTimestamp}, local time ${now}`
201 );
202 }
203
204 if (newConfig === 'unmodified') {
205 log.info(
206 'remote config was unmodified; server-generated hash is %s',
207 configHash
208 );
209 return;
210 }
211
212 // Process new configuration in light of the old configuration. Since the
213 // new configuration only includes enabled flags we can't distinguish betewen
214 // a remote flag being deleted or being disabled. We synthesize that for our
215 // known keys.
216 const newConfigValues = new Map<string, string | undefined>(
217 KnownConfigKeys.map(name => [name, undefined])
218 );
219 for (const [name, value] of newConfig) {
220 newConfigValues.set(name, value);
221 }
222
223 const changedKeys = new Set<string>();
224 const changeDescriptions: Array<{
225 name: string;
226 from: string;
227 to: string;
228 }> = [];
229
230 const oldConfig = config;
231 let semverError = false;
232 config = Array.from(newConfigValues.entries()).reduce(
233 (acc, [name, value]) => {
234 const enabled = value !== undefined && value.toLowerCase() !== 'false';
235 const previouslyEnabled: boolean = get(
236 oldConfig,
237 [name, 'enabled'],
238 false
239 );

Callers 2

updateRemoteConfigFunction · 0.90
forceRefreshRemoteConfigFunction · 0.85

Calls 15

getConfigFunction · 0.90
isEnabledFunction · 0.85
parseMethod · 0.80
removeMethod · 0.80
putMethod · 0.80
getValueFunction · 0.70
getFunction · 0.50
callbackFunction · 0.50
getMethod · 0.45
warnMethod · 0.45
infoMethod · 0.45

Tested by

no test coverage detected