From eb6d1b721625901aa1eef5e6d6c426fde5e35c75 Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Wed, 7 Apr 2021 13:00:22 -0700 Subject: [PATCH] Fix StickerType in sql/Interface and fix query --- ts/sql/Interface.ts | 6 +++--- ts/sql/Server.ts | 25 ++++++++++++++++++++----- ts/state/ducks/stickers.ts | 6 +++--- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/ts/sql/Interface.ts b/ts/sql/Interface.ts index e45c4ce3b063..21a4269bde19 100644 --- a/ts/sql/Interface.ts +++ b/ts/sql/Interface.ts @@ -91,9 +91,9 @@ export type StickerType = { id: number; packId: string; - emoji: string; - isCoverOnly: string; - lastUsed: number; + emoji: string | null; + isCoverOnly: boolean; + lastUsed?: number; path: string; width: number; height: number; diff --git a/ts/sql/Server.ts b/ts/sql/Server.ts index 47aaea462ed4..11cb24636867 100644 --- a/ts/sql/Server.ts +++ b/ts/sql/Server.ts @@ -69,6 +69,16 @@ type ConversationRow = Readonly<{ profileLastFetchedAt: null | number; }>; type ConversationRows = Array; +type StickerRow = Readonly<{ + id: number; + packId: string; + emoji: string | null; + height: number; + isCoverOnly: number; + lastUsed: number; + path: string; + width: number; +}>; type EmptyQuery = []; type ArrayQuery = Array>; @@ -259,6 +269,12 @@ function rowToConversation(row: ConversationRow): ConversationType { profileLastFetchedAt, }; } +function rowToSticker(row: StickerRow): StickerType { + return { + ...row, + isCoverOnly: Boolean(row.isCoverOnly), + }; +} function isRenderer() { if (typeof process === 'undefined' || !process) { @@ -3682,7 +3698,6 @@ async function updateStickerPackStatus( UPDATE sticker_packs SET status = $status, installedAt = $installedAt WHERE id = $id; - ) ` ).run({ id, @@ -3751,8 +3766,8 @@ async function createOrUpdateSticker(sticker: StickerType): Promise { emoji, height, id, - isCoverOnly, - lastUsed, + isCoverOnly: isCoverOnly ? 1 : 0, + lastUsed: lastUsed || null, packId, path, width, @@ -3996,7 +4011,7 @@ async function getAllStickers(): Promise> { ) .all(); - return rows || []; + return (rows || []).map(row => rowToSticker(row)); } async function getRecentStickers({ limit }: { limit?: number } = {}): Promise< Array @@ -4018,7 +4033,7 @@ async function getRecentStickers({ limit }: { limit?: number } = {}): Promise< limit: limit || 24, }); - return rows || []; + return (rows || []).map(row => rowToSticker(row)); } // Emojis diff --git a/ts/state/ducks/stickers.ts b/ts/state/ducks/stickers.ts index 27bee852d2cc..22eb04aae311 100644 --- a/ts/state/ducks/stickers.ts +++ b/ts/state/ducks/stickers.ts @@ -24,8 +24,8 @@ export type StickerDBType = { readonly id: number; readonly packId: string; - readonly emoji: string; - readonly isCoverOnly: string; + readonly emoji: string | null; + readonly isCoverOnly: boolean; readonly lastUsed: number; readonly path: string; }; @@ -75,7 +75,7 @@ export type StickersStateType = { export type StickerType = { readonly id: number; readonly packId: string; - readonly emoji: string; + readonly emoji: string | null; readonly url: string; };