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

Function getConfig

ts/textsecure/WebAPI.preload.ts:2095–2154  ·  view source on GitHub ↗
(
  configHash?: string
)

Source from the content-addressed store, hash-verified

2093}
2094
2095export async function getConfig(
2096 configHash?: string
2097): Promise<RemoteConfigResponseType> {
2098 const { data, response } = await _ajax({
2099 host: 'chatService',
2100 call: 'configV2',
2101 httpType: 'GET',
2102 responseType: 'jsonwithdetails',
2103 zodSchema: z.union([
2104 remoteConfigResponseZod,
2105 // When a 304 is returned, the body of the response is empty.
2106 z.literal(''),
2107 ]),
2108 headers: {
2109 ...(configHash && { 'if-none-match': configHash }),
2110 },
2111 });
2112
2113 const serverTimestamp = safeParseNumber(
2114 response.headers.get('x-signal-timestamp') || ''
2115 );
2116
2117 if (serverTimestamp == null) {
2118 throw new Error('Missing required x-signal-timestamp header');
2119 }
2120
2121 const newConfigHash = response.headers.get('etag');
2122 if (newConfigHash == null) {
2123 throw new Error('Missing required ETag header');
2124 }
2125
2126 const partialResponse = { serverTimestamp, configHash: newConfigHash };
2127
2128 if (response.status === 304) {
2129 return {
2130 config: 'unmodified',
2131 ...partialResponse,
2132 };
2133 }
2134
2135 if (data === '') {
2136 throw new Error('Empty data returned for non-304');
2137 }
2138
2139 const { config: newConfig } = data;
2140
2141 const config = new Map(
2142 Object.entries(newConfig).filter(
2143 ([name, _value]) =>
2144 name.startsWith('desktop.') ||
2145 name.startsWith('global.') ||
2146 name.startsWith('cds.')
2147 )
2148 );
2149
2150 return {
2151 config,
2152 ...partialResponse,

Callers 1

_refreshRemoteConfigFunction · 0.90

Calls 3

safeParseNumberFunction · 0.90
_ajaxFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected