makeLookup: Allow for key of zero
This commit is contained in:
parent
a769402c0c
commit
12c44d40a8
6 changed files with 34 additions and 3 deletions
|
@ -524,6 +524,13 @@ type WhatIsThis = import('./window.d').WhatIsThis;
|
||||||
await window.Signal.Services.eraseAllStorageServiceState();
|
await window.Signal.Services.eraseAllStorageServiceState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
lastVersion === 'v1.40.0-beta.1' &&
|
||||||
|
window.isAfterVersion(lastVersion, 'v1.40.0-beta.1')
|
||||||
|
) {
|
||||||
|
await window.Signal.Data.clearAllErrorStickerPackAttempts();
|
||||||
|
}
|
||||||
|
|
||||||
// This one should always be last - it could restart the app
|
// This one should always be last - it could restart the app
|
||||||
if (window.isBeforeVersion(lastVersion, 'v1.15.0-beta.5')) {
|
if (window.isBeforeVersion(lastVersion, 'v1.15.0-beta.5')) {
|
||||||
await window.Signal.Logs.deleteAll();
|
await window.Signal.Logs.deleteAll();
|
||||||
|
|
|
@ -203,6 +203,7 @@ const dataInterface: ClientInterface = {
|
||||||
getAllStickerPacks,
|
getAllStickerPacks,
|
||||||
getAllStickers,
|
getAllStickers,
|
||||||
getRecentStickers,
|
getRecentStickers,
|
||||||
|
clearAllErrorStickerPackAttempts,
|
||||||
|
|
||||||
updateEmojiUsage,
|
updateEmojiUsage,
|
||||||
getRecentEmojis,
|
getRecentEmojis,
|
||||||
|
@ -1333,6 +1334,9 @@ async function getRecentStickers() {
|
||||||
|
|
||||||
return recentStickers;
|
return recentStickers;
|
||||||
}
|
}
|
||||||
|
async function clearAllErrorStickerPackAttempts() {
|
||||||
|
await channels.clearAllErrorStickerPackAttempts();
|
||||||
|
}
|
||||||
|
|
||||||
// Emojis
|
// Emojis
|
||||||
async function updateEmojiUsage(shortName: string) {
|
async function updateEmojiUsage(shortName: string) {
|
||||||
|
|
|
@ -169,6 +169,7 @@ export type DataInterface = {
|
||||||
getRecentStickers: (options?: {
|
getRecentStickers: (options?: {
|
||||||
limit?: number;
|
limit?: number;
|
||||||
}) => Promise<Array<StickerType>>;
|
}) => Promise<Array<StickerType>>;
|
||||||
|
clearAllErrorStickerPackAttempts: () => Promise<void>;
|
||||||
|
|
||||||
updateEmojiUsage: (shortName: string, timeUsed?: number) => Promise<void>;
|
updateEmojiUsage: (shortName: string, timeUsed?: number) => Promise<void>;
|
||||||
getRecentEmojis: (limit?: number) => Promise<Array<EmojiType>>;
|
getRecentEmojis: (limit?: number) => Promise<Array<EmojiType>>;
|
||||||
|
|
|
@ -180,6 +180,7 @@ const dataInterface: ServerInterface = {
|
||||||
getAllStickerPacks,
|
getAllStickerPacks,
|
||||||
getAllStickers,
|
getAllStickers,
|
||||||
getRecentStickers,
|
getRecentStickers,
|
||||||
|
clearAllErrorStickerPackAttempts,
|
||||||
|
|
||||||
updateEmojiUsage,
|
updateEmojiUsage,
|
||||||
getRecentEmojis,
|
getRecentEmojis,
|
||||||
|
@ -3465,6 +3466,13 @@ async function updateStickerPackStatus(
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
async function clearAllErrorStickerPackAttempts(): Promise<void> {
|
||||||
|
const db = getInstance();
|
||||||
|
|
||||||
|
await db.run(
|
||||||
|
"UPDATE sticker_packs SET downloadAttempts = 0 WHERE status = 'error';"
|
||||||
|
);
|
||||||
|
}
|
||||||
async function createOrUpdateSticker(sticker: StickerType) {
|
async function createOrUpdateSticker(sticker: StickerType) {
|
||||||
const db = getInstance();
|
const db = getInstance();
|
||||||
const {
|
const {
|
||||||
|
|
|
@ -33,13 +33,24 @@ describe('makeLookup', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('ignores falsy properties', () => {
|
it('ignores undefined properties', () => {
|
||||||
const arr = [{}, { foo: '' }, { foo: false }, { foo: null }];
|
const arr = [{}, { foo: undefined }];
|
||||||
const result = makeLookup(arr, 'foo');
|
const result = makeLookup(arr, 'foo');
|
||||||
|
|
||||||
assert.deepEqual(result, {});
|
assert.deepEqual(result, {});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('allows key of 0', () => {
|
||||||
|
const arr = [{}, { id: 0 }, { id: 1 }, { id: 2 }];
|
||||||
|
const result = makeLookup(arr, 'id');
|
||||||
|
|
||||||
|
assert.deepEqual(result, {
|
||||||
|
0: { id: 0 },
|
||||||
|
1: { id: 1 },
|
||||||
|
2: { id: 2 },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('converts the lookup to a string', () => {
|
it('converts the lookup to a string', () => {
|
||||||
const arr = [
|
const arr = [
|
||||||
{ foo: 'bar' },
|
{ foo: 'bar' },
|
||||||
|
|
|
@ -6,7 +6,7 @@ export function makeLookup<T>(
|
||||||
key: keyof T
|
key: keyof T
|
||||||
): Record<string, T> {
|
): Record<string, T> {
|
||||||
return (items || []).reduce((lookup, item) => {
|
return (items || []).reduce((lookup, item) => {
|
||||||
if (item && item[key]) {
|
if (item !== undefined && item[key] !== undefined) {
|
||||||
// The force cast is necessary if we want the keyof T above, and the flexibility
|
// The force cast is necessary if we want the keyof T above, and the flexibility
|
||||||
// to pass anything in. And of course we're modifying a parameter!
|
// to pass anything in. And of course we're modifying a parameter!
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
|
|
Loading…
Reference in a new issue