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;
packId: string;
emoji: string;
isCoverOnly: string;
lastUsed: number;
emoji: string | null;
isCoverOnly: boolean;
lastUsed?: number;
path: string;
width: number;
height: number;

View File

@ -69,6 +69,16 @@ type ConversationRow = Readonly<{
profileLastFetchedAt: null | number;
}>;
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 ArrayQuery = Array<Array<null | number | string>>;
@ -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<void> {
emoji,
height,
id,
isCoverOnly,
lastUsed,
isCoverOnly: isCoverOnly ? 1 : 0,
lastUsed: lastUsed || null,
packId,
path,
width,
@ -3996,7 +4011,7 @@ async function getAllStickers(): Promise<Array<StickerType>> {
)
.all();
return rows || [];
return (rows || []).map(row => rowToSticker(row));
}
async function getRecentStickers({ limit }: { limit?: number } = {}): Promise<
Array<StickerType>
@ -4018,7 +4033,7 @@ async function getRecentStickers({ limit }: { limit?: number } = {}): Promise<
limit: limit || 24,
});
return rows || [];
return (rows || []).map(row => rowToSticker(row));
}
// Emojis

View File

@ -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;
};