From 2b9e7ee5b73ffffb57891b919dd9b263c6123147 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Sat, 15 Oct 2022 20:28:40 -0700 Subject: [PATCH] refactor: convertFlags to utils --- src/components/Timeline.vue | 21 +-------------------- src/services/Utils.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/components/Timeline.vue b/src/components/Timeline.vue index 89afb1c7..59f4d314 100644 --- a/src/components/Timeline.vue +++ b/src/components/Timeline.vue @@ -718,26 +718,7 @@ export default class Timeline extends Mixins(GlobalMixin, UserConfig) { } // Flag conversion - if (photo.isvideo) { - photo.flag |= this.c.FLAG_IS_VIDEO; - delete photo.isvideo; - } - if (photo.isfavorite) { - photo.flag |= this.c.FLAG_IS_FAVORITE; - delete photo.isfavorite; - } - if (photo.isfolder) { - photo.flag |= this.c.FLAG_IS_FOLDER; - delete photo.isfolder; - } - if (photo.isface) { - photo.flag |= this.c.FLAG_IS_FACE; - delete photo.isface; - } - if (photo.istag) { - photo.flag |= this.c.FLAG_IS_TAG; - delete photo.istag; - } + utils.convertFlags(photo); // Get aspect ratio photo.dispWp = utils.round(100 * jbox.width / this.rowWidth, 2); diff --git a/src/services/Utils.ts b/src/services/Utils.ts index 1c241f9b..9a3d20ed 100644 --- a/src/services/Utils.ts +++ b/src/services/Utils.ts @@ -1,4 +1,5 @@ import { getCanonicalLocale } from "@nextcloud/l10n"; +import { IPhoto } from "../types"; // Memoize the result of short date conversions // These operations are surprisingly expensive @@ -108,6 +109,33 @@ export function roundHalf(num: number) { return Math.round(num * 2) / 2; } +/** + * Convert server-side flags to bitmask + * @param photo Photo to process + */ +export function convertFlags(photo: IPhoto) { + if (photo.isvideo) { + photo.flag |= constants.c.FLAG_IS_VIDEO; + delete photo.isvideo; + } + if (photo.isfavorite) { + photo.flag |= constants.c.FLAG_IS_FAVORITE; + delete photo.isfavorite; + } + if (photo.isfolder) { + photo.flag |= constants.c.FLAG_IS_FOLDER; + delete photo.isfolder; + } + if (photo.isface) { + photo.flag |= constants.c.FLAG_IS_FACE; + delete photo.isface; + } + if (photo.istag) { + photo.flag |= constants.c.FLAG_IS_TAG; + delete photo.istag; + } +} + /** Global constants */ export const constants = { c: {