From d02eb7afce87cae4b22333263dccf403f377f42a Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sun, 22 Mar 2020 14:36:44 +0100 Subject: [PATCH] Can get account image settings --- src/controllers/Routes.ts | 2 ++ src/controllers/SettingsController.ts | 25 +++++++++++++++++++++++++ src/entities/AccountImage.ts | 8 ++++++++ 3 files changed, 35 insertions(+) diff --git a/src/controllers/Routes.ts b/src/controllers/Routes.ts index 323897a..a09c827 100644 --- a/src/controllers/Routes.ts +++ b/src/controllers/Routes.ts @@ -97,6 +97,8 @@ export const Routes : Route[] = [ {path: "/settings/update_password", cb: (h) => SettingsController.UpdatePassword(h)}, + {path: "/settings/get_account_image", cb: (h) => SettingsController.GetAccountImageSettings(h)}, + // Friends controller {path: "/friends/getList", cb: (h) => FriendsController.GetList(h)}, diff --git a/src/controllers/SettingsController.ts b/src/controllers/SettingsController.ts index ad52ba7..4e63693 100644 --- a/src/controllers/SettingsController.ts +++ b/src/controllers/SettingsController.ts @@ -10,6 +10,16 @@ import { GeneralSettings, UserPageStatus, SupportedLanguages, LangSettings, Secu import { removeHTMLNodes, checkURL, fixEncoding } from "../utils/StringUtils"; import { checkVirtualDirectoryAvailability, VirtualDirType } from "../utils/VirtualDirsUtils"; import { AccountHelper } from "../helpers/AccountHelper"; +import { AccountImageVisibilityLevel } from "../entities/AccountImage"; + +/** + * API account image visibility levels + */ +const ACCOUNT_IMAGE_VISIBLITY_LEVELS = {}; +ACCOUNT_IMAGE_VISIBLITY_LEVELS[AccountImageVisibilityLevel.EVERYONE] = "open"; +ACCOUNT_IMAGE_VISIBLITY_LEVELS[AccountImageVisibilityLevel.COMUNIC_USERS] = "public"; +ACCOUNT_IMAGE_VISIBLITY_LEVELS[AccountImageVisibilityLevel.FRIENDS] = "friends"; + export class SettingsController { @@ -190,4 +200,19 @@ export class SettingsController { h.success(); } + + /** + * Get account image settings + * + * @param h Request handler + */ + public static async GetAccountImageSettings(h: RequestHandler) { + const imageInfo = (await UserHelper.GetUserInfo(h.getUserId())).accountImage; + + h.send({ + has_image: imageInfo.hasImage, + image_url: imageInfo.url, + visibility: ACCOUNT_IMAGE_VISIBLITY_LEVELS[imageInfo.level] + }); + } } \ No newline at end of file diff --git a/src/entities/AccountImage.ts b/src/entities/AccountImage.ts index a53cddd..c7cd819 100644 --- a/src/entities/AccountImage.ts +++ b/src/entities/AccountImage.ts @@ -33,6 +33,14 @@ export class AccountImage { return AccountImage.urlForFile(this.path); } + /** + * Check out whether the user has an account image + * or if it is the default account image + */ + get hasImage() : boolean { + return this.path.length > 0; + } + static get errorURL() : string { return this.urlForFile(errorAccountImage); }