"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "ts/RemoteConfig.ts" between
Signal-Desktop-1.35.2.tar.gz and Signal-Desktop-1.36.1.tar.gz

About: Signal-Desktop is a cross-platform encrypted messaging service (also available for mobile devices).

RemoteConfig.ts  (Signal-Desktop-1.35.2):RemoteConfig.ts  (Signal-Desktop-1.36.1)
import { get, throttle } from 'lodash'; import { get, throttle } from 'lodash';
import { WebAPIType } from './textsecure/WebAPI'; import { WebAPIType } from './textsecure/WebAPI';
type ConfigKeyType = 'desktop.messageRequests'; type ConfigKeyType =
| 'desktop.messageRequests'
| 'desktop.gv2'
| 'desktop.cds'
| 'desktop.storage'
| 'desktop.storageWrite'
| 'desktop.clientExpiration';
type ConfigValueType = { type ConfigValueType = {
name: ConfigKeyType; name: ConfigKeyType;
enabled: boolean; enabled: boolean;
enabledAt?: number; enabledAt?: number;
value?: unknown;
}; };
type ConfigMapType = { [key: string]: ConfigValueType }; type ConfigMapType = { [key: string]: ConfigValueType };
type ConfigListenerType = (value: ConfigValueType) => unknown; type ConfigListenerType = (value: ConfigValueType) => unknown;
type ConfigListenersMapType = { type ConfigListenersMapType = {
[key: string]: Array<ConfigListenerType>; [key: string]: Array<ConfigListenerType>;
}; };
function getServer(): WebAPIType { function getServer(): WebAPIType {
const OLD_USERNAME = window.storage.get<string>('number_id'); const OLD_USERNAME = window.storage.get<string>('number_id');
const USERNAME = window.storage.get<string>('uuid_id'); const USERNAME = window.storage.get<string>('uuid_id');
skipping to change at line 54 skipping to change at line 61
export const refreshRemoteConfig = async () => { export const refreshRemoteConfig = async () => {
const now = Date.now(); const now = Date.now();
const server = getServer(); const server = getServer();
const newConfig = await server.getConfig(); const newConfig = await server.getConfig();
// Process new configuration in light of the old configuration // Process new configuration in light of the old configuration
// The old configuration is not set as the initial value in reduce because // The old configuration is not set as the initial value in reduce because
// flags may have been deleted // flags may have been deleted
const oldConfig = config; const oldConfig = config;
config = newConfig.reduce((previous, { name, enabled }) => { config = newConfig.reduce((acc, { name, enabled, value }) => {
const previouslyEnabled: boolean = get(oldConfig, [name, 'enabled'], false); const previouslyEnabled: boolean = get(oldConfig, [name, 'enabled'], false);
const previousValue: unknown = get(oldConfig, [name, 'value'], undefined);
// If a flag was previously not enabled and is now enabled, record the time it was enabled // If a flag was previously not enabled and is now enabled, record the time it was enabled
const enabledAt: number | undefined = const enabledAt: number | undefined =
previouslyEnabled && enabled ? now : get(oldConfig, [name, 'enabledAt']); previouslyEnabled && enabled ? now : get(oldConfig, [name, 'enabledAt']);
const value = { const configValue = {
name: name as ConfigKeyType, name: name as ConfigKeyType,
enabled, enabled,
enabledAt, enabledAt,
value,
}; };
const hasChanged =
previouslyEnabled !== enabled || previousValue !== configValue.value;
// If enablement changes at all, notify listeners // If enablement changes at all, notify listeners
const currentListeners = listeners[name] || []; const currentListeners = listeners[name] || [];
if (previouslyEnabled !== enabled) { if (hasChanged) {
window.log.info(`Remote Config: Flag ${name} has changed`);
currentListeners.forEach(listener => { currentListeners.forEach(listener => {
listener(value); listener(configValue);
}); });
} }
// Return new configuration object // Return new configuration object
return { return {
...previous, ...acc,
[name]: value, [name]: configValue,
}; };
}, {}); }, {});
window.storage.put('remoteConfig', config); window.storage.put('remoteConfig', config);
}; };
export const maybeRefreshRemoteConfig = throttle( export const maybeRefreshRemoteConfig = throttle(
refreshRemoteConfig, refreshRemoteConfig,
// Only fetch remote configuration if the last fetch was more than two hours a go // Only fetch remote configuration if the last fetch was more than two hours a go
2 * 60 * 60 * 1000, 2 * 60 * 60 * 1000,
 End of changes. 10 change blocks. 
7 lines changed or deleted 20 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)