Fix StickerType in sql/Interface and fix query

This commit is contained in:
Fedor Indutny 2021-04-07 13:00:22 -07:00 committed by Josh Perez
parent c609389aaf
commit eb6d1b7216
3 changed files with 26 additions and 11 deletions

View file

@ -91,9 +91,9 @@ export type StickerType = {
id: number; id: number;
packId: string; packId: string;
emoji: string; emoji: string | null;
isCoverOnly: string; isCoverOnly: boolean;
lastUsed: number; lastUsed?: number;
path: string; path: string;
width: number; width: number;
height: number; height: number;

View file

@ -69,6 +69,16 @@ type ConversationRow = Readonly<{
profileLastFetchedAt: null | number; profileLastFetchedAt: null | number;
}>; }>;
type ConversationRows = Array<ConversationRow>; type ConversationRows = Array<ConversationRow>;
type StickerRow = Readonly<{
id: number;
packId: string;
emoji: string | null;
height: number;
isCoverOnly: number;
lastUsed: number;
path: string;
width: number;
}>;
type EmptyQuery = []; type EmptyQuery = [];
type ArrayQuery = Array<Array<null | number | string>>; type ArrayQuery = Array<Array<null | number | string>>;
@ -259,6 +269,12 @@ function rowToConversation(row: ConversationRow): ConversationType {
profileLastFetchedAt, profileLastFetchedAt,
}; };
} }
function rowToSticker(row: StickerRow): StickerType {
return {
...row,
isCoverOnly: Boolean(row.isCoverOnly),
};
}
function isRenderer() { function isRenderer() {
if (typeof process === 'undefined' || !process) { if (typeof process === 'undefined' || !process) {
@ -3682,7 +3698,6 @@ async function updateStickerPackStatus(
UPDATE sticker_packs UPDATE sticker_packs
SET status = $status, installedAt = $installedAt SET status = $status, installedAt = $installedAt
WHERE id = $id; WHERE id = $id;
)
` `
).run({ ).run({
id, id,
@ -3751,8 +3766,8 @@ async function createOrUpdateSticker(sticker: StickerType): Promise<void> {
emoji, emoji,
height, height,
id, id,
isCoverOnly, isCoverOnly: isCoverOnly ? 1 : 0,
lastUsed, lastUsed: lastUsed || null,
packId, packId,
path, path,
width, width,
@ -3996,7 +4011,7 @@ async function getAllStickers(): Promise<Array<StickerType>> {
) )
.all(); .all();
return rows || []; return (rows || []).map(row => rowToSticker(row));
} }
async function getRecentStickers({ limit }: { limit?: number } = {}): Promise< async function getRecentStickers({ limit }: { limit?: number } = {}): Promise<
Array<StickerType> Array<StickerType>
@ -4018,7 +4033,7 @@ async function getRecentStickers({ limit }: { limit?: number } = {}): Promise<
limit: limit || 24, limit: limit || 24,
}); });
return rows || []; return (rows || []).map(row => rowToSticker(row));
} }
// Emojis // Emojis

View file

@ -24,8 +24,8 @@ export type StickerDBType = {
readonly id: number; readonly id: number;
readonly packId: string; readonly packId: string;
readonly emoji: string; readonly emoji: string | null;
readonly isCoverOnly: string; readonly isCoverOnly: boolean;
readonly lastUsed: number; readonly lastUsed: number;
readonly path: string; readonly path: string;
}; };
@ -75,7 +75,7 @@ export type StickersStateType = {
export type StickerType = { export type StickerType = {
readonly id: number; readonly id: number;
readonly packId: string; readonly packId: string;
readonly emoji: string; readonly emoji: string | null;
readonly url: string; readonly url: string;
}; };