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