Localized release notes
This commit is contained in:
parent
ebc01d0ce5
commit
55705a08d4
2 changed files with 79 additions and 15 deletions
|
@ -106,20 +106,51 @@ export class ReleaseNotesFetcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
const { uuid, ctaId, link } = note;
|
const { uuid, ctaId, link } = note;
|
||||||
const result = await window.textsecure.server.getReleaseNote({
|
const globalLocale = new Intl.Locale(window.SignalContext.getI18nLocale());
|
||||||
uuid,
|
const localesToTry = [
|
||||||
});
|
globalLocale.toString(),
|
||||||
strictAssert(
|
globalLocale.language.toString(),
|
||||||
result.uuid === uuid,
|
'en',
|
||||||
'UUID of localized release note should match requested UUID'
|
].map(locale => locale.toLocaleLowerCase().replace('-', '_'));
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
for (const localeToTry of localesToTry) {
|
||||||
...result,
|
try {
|
||||||
uuid,
|
// eslint-disable-next-line no-await-in-loop
|
||||||
ctaId,
|
const hash = await window.textsecure.server.getReleaseNoteHash({
|
||||||
link,
|
uuid,
|
||||||
};
|
locale: localeToTry,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (hash === undefined) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-await-in-loop
|
||||||
|
const result = await window.textsecure.server.getReleaseNote({
|
||||||
|
uuid,
|
||||||
|
locale: localeToTry,
|
||||||
|
});
|
||||||
|
|
||||||
|
strictAssert(
|
||||||
|
result.uuid === uuid,
|
||||||
|
'UUID of localized release note should match requested UUID'
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
uuid,
|
||||||
|
ctaId,
|
||||||
|
link,
|
||||||
|
};
|
||||||
|
} catch {
|
||||||
|
// If either request fails, try the next locale
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(
|
||||||
|
`Could not fetch release note with any locale for UUID ${uuid}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async processReleaseNotes(
|
private async processReleaseNotes(
|
||||||
|
|
|
@ -1216,6 +1216,7 @@ export type GetBackupInfoResponseType = z.infer<
|
||||||
|
|
||||||
export type GetReleaseNoteOptionsType = Readonly<{
|
export type GetReleaseNoteOptionsType = Readonly<{
|
||||||
uuid: string;
|
uuid: string;
|
||||||
|
locale: string;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
export const releaseNoteSchema = z.object({
|
export const releaseNoteSchema = z.object({
|
||||||
|
@ -1408,6 +1409,9 @@ export type WebAPIType = {
|
||||||
getReleaseNote: (
|
getReleaseNote: (
|
||||||
options: GetReleaseNoteOptionsType
|
options: GetReleaseNoteOptionsType
|
||||||
) => Promise<ReleaseNoteResponseType>;
|
) => Promise<ReleaseNoteResponseType>;
|
||||||
|
getReleaseNoteHash: (
|
||||||
|
options: GetReleaseNoteOptionsType
|
||||||
|
) => Promise<string | undefined>;
|
||||||
getReleaseNotesManifest: () => Promise<ReleaseNotesManifestResponseType>;
|
getReleaseNotesManifest: () => Promise<ReleaseNotesManifestResponseType>;
|
||||||
getReleaseNotesManifestHash: () => Promise<string | undefined>;
|
getReleaseNotesManifestHash: () => Promise<string | undefined>;
|
||||||
getSticker: (packId: string, stickerId: number) => Promise<Uint8Array>;
|
getSticker: (packId: string, stickerId: number) => Promise<Uint8Array>;
|
||||||
|
@ -1880,6 +1884,7 @@ export function initialize({
|
||||||
getProfileUnauth,
|
getProfileUnauth,
|
||||||
getProvisioningResource,
|
getProvisioningResource,
|
||||||
getReleaseNote,
|
getReleaseNote,
|
||||||
|
getReleaseNoteHash,
|
||||||
getReleaseNotesManifest,
|
getReleaseNotesManifest,
|
||||||
getReleaseNotesManifestHash,
|
getReleaseNotesManifestHash,
|
||||||
getTransferArchive,
|
getTransferArchive,
|
||||||
|
@ -2174,15 +2179,43 @@ export function initialize({
|
||||||
languages: Record<string, Array<string>>;
|
languages: Record<string, Array<string>>;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getReleaseNoteHash({
|
||||||
|
uuid,
|
||||||
|
locale,
|
||||||
|
}: {
|
||||||
|
uuid: string;
|
||||||
|
locale: string;
|
||||||
|
}): Promise<string | undefined> {
|
||||||
|
const { response } = await _ajax({
|
||||||
|
call: 'releaseNotes',
|
||||||
|
host: resourcesUrl,
|
||||||
|
httpType: 'HEAD',
|
||||||
|
urlParameters: `/${uuid}/${locale}.json`,
|
||||||
|
responseType: 'byteswithdetails',
|
||||||
|
});
|
||||||
|
|
||||||
|
const etag = response.headers.get('etag');
|
||||||
|
|
||||||
|
if (etag == null) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return etag;
|
||||||
|
}
|
||||||
async function getReleaseNote({
|
async function getReleaseNote({
|
||||||
uuid,
|
uuid,
|
||||||
}: GetReleaseNoteOptionsType): Promise<ReleaseNoteResponseType> {
|
locale,
|
||||||
|
}: {
|
||||||
|
uuid: string;
|
||||||
|
locale: string;
|
||||||
|
}): Promise<ReleaseNoteResponseType> {
|
||||||
const rawRes = await _ajax({
|
const rawRes = await _ajax({
|
||||||
call: 'releaseNotes',
|
call: 'releaseNotes',
|
||||||
host: resourcesUrl,
|
host: resourcesUrl,
|
||||||
httpType: 'GET',
|
httpType: 'GET',
|
||||||
responseType: 'json',
|
responseType: 'json',
|
||||||
urlParameters: `/${uuid}/en.json`,
|
urlParameters: `/${uuid}/${locale}.json`,
|
||||||
});
|
});
|
||||||
return parseUnknown(releaseNoteSchema, rawRes);
|
return parseUnknown(releaseNoteSchema, rawRes);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue