feat(profile): advertise per-variant dictionary versions for offline preload
The Profile now carries dict_versions (game variant -> current dictionary version), populated from the dictionary registry at the profileResponse choke point, so an installed PWA can preload the matching dawg per enabled variant off the existing cold-start profile request instead of adding a round-trip for a rare feature. Wire path: FBS DictVersion table + Profile.dict_versions (additive, backward-compatible trailing field) -> backend dto/registry -> gateway ProfileResp + FBS encoder -> client codec decode into a per-variant map on model.Profile. Empty in a degenerate no-dictionary deployment; the mock serves v1.3.0 for all three variants. Codec decode covered by a bite-tested round-trip unit test.
This commit is contained in:
@@ -712,6 +712,28 @@ describe('codec', () => {
|
||||
expect(decodeProfile(b.asUint8Array()).variantPreferences).toEqual(['erudit_ru', 'scrabble_en']);
|
||||
});
|
||||
|
||||
it('decodes the profile dictionary versions into a per-variant map', () => {
|
||||
const b = new Builder(128);
|
||||
const uid = b.createString('u-1');
|
||||
const en = fb.DictVersion.createDictVersion(b, b.createString('scrabble_en'), b.createString('v1.3.0'));
|
||||
const er = fb.DictVersion.createDictVersion(b, b.createString('erudit_ru'), b.createString('v1.2.0'));
|
||||
const vec = fb.Profile.createDictVersionsVector(b, [en, er]);
|
||||
fb.Profile.startProfile(b);
|
||||
fb.Profile.addUserId(b, uid);
|
||||
fb.Profile.addDictVersions(b, vec);
|
||||
b.finish(fb.Profile.endProfile(b));
|
||||
expect(decodeProfile(b.asUint8Array()).dictVersions).toEqual({ scrabble_en: 'v1.3.0', erudit_ru: 'v1.2.0' });
|
||||
});
|
||||
|
||||
it('decodes an absent dict_versions vector to an empty map', () => {
|
||||
const b = new Builder(64);
|
||||
const uid = b.createString('u-1');
|
||||
fb.Profile.startProfile(b);
|
||||
fb.Profile.addUserId(b, uid);
|
||||
b.finish(fb.Profile.endProfile(b));
|
||||
expect(decodeProfile(b.asUint8Array()).dictVersions).toEqual({});
|
||||
});
|
||||
|
||||
it('encodes the update-profile variant preferences', () => {
|
||||
const buf = encodeUpdateProfile({
|
||||
displayName: 'Kaya',
|
||||
|
||||
@@ -364,9 +364,25 @@ export function decodeProfile(buf: Uint8Array): Profile {
|
||||
email: s(p.email()),
|
||||
telegramLinked: p.telegramLinked(),
|
||||
vkLinked: p.vkLinked(),
|
||||
dictVersions: decodeDictVersions(p),
|
||||
};
|
||||
}
|
||||
|
||||
// decodeDictVersions reads the profile's per-variant current dictionary versions into a
|
||||
// variant-keyed map, so the offline preloader can look up the version for each enabled
|
||||
// variant. An entry with an unknown variant or empty version is skipped.
|
||||
function decodeDictVersions(p: fb.Profile): Partial<Record<Variant, string>> {
|
||||
const out: Partial<Record<Variant, string>> = {};
|
||||
for (let i = 0; i < p.dictVersionsLength(); i++) {
|
||||
const dv = p.dictVersions(i);
|
||||
if (!dv) continue;
|
||||
const variant = s(dv.variant()) as Variant;
|
||||
const version = s(dv.version());
|
||||
if (variant && version) out[variant] = version;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// decodeVariantPreferences reads the Profile.variant_preferences vector (the variants
|
||||
// the player enabled in Settings).
|
||||
function decodeVariantPreferences(p: fb.Profile): Variant[] {
|
||||
|
||||
@@ -42,6 +42,9 @@ export const PROFILE: Profile = {
|
||||
email: 'you@example.com',
|
||||
telegramLinked: false,
|
||||
vkLinked: false,
|
||||
// Every variant's current dictionary version, as the backend advertises it on the profile —
|
||||
// the offline preloader targets `variant@version`.
|
||||
dictVersions: { erudit_ru: 'v1.3.0', scrabble_ru: 'v1.3.0', scrabble_en: 'v1.3.0' },
|
||||
};
|
||||
|
||||
// Seed social/account data for the mock (pnpm start + Playwright). The mock profile
|
||||
|
||||
@@ -161,6 +161,10 @@ export interface Profile {
|
||||
/** Whether a Telegram / VK identity is attached — drives the Add / Unlink controls. */
|
||||
telegramLinked: boolean;
|
||||
vkLinked: boolean;
|
||||
/** Current dictionary version per game variant (deployment-wide, not per-account). An
|
||||
* offline-capable PWA reads it to preload the matching dawg for each enabled variant off
|
||||
* this cold-start response. Empty only in a degenerate deployment with no resident dictionary. */
|
||||
dictVersions: Partial<Record<Variant, string>>;
|
||||
}
|
||||
|
||||
/** Banner is the advertising-banner block of an eligible viewer's profile. */
|
||||
|
||||
Reference in New Issue
Block a user