mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2025-06-20 16:45:16 +00:00
Start to process user account image
This commit is contained in:
43
src/entities/AccountImage.ts
Normal file
43
src/entities/AccountImage.ts
Normal file
@ -0,0 +1,43 @@
|
||||
import { pathUserData } from "../utils/UserDataUtils";
|
||||
|
||||
/**
|
||||
* Single user account image
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
const defaultAccountImage = "0Reverse.png";
|
||||
const errorAccountImage = "0Red.png";
|
||||
|
||||
export enum AccountImageVisibilityLevel {
|
||||
FRIENDS = 1,
|
||||
COMUNIC_USERS = 2,
|
||||
EVERYONE = 3
|
||||
}
|
||||
|
||||
export class AccountImage {
|
||||
|
||||
public constructor(
|
||||
public userID: number,
|
||||
public path : string,
|
||||
public level: AccountImageVisibilityLevel
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Get account image URL
|
||||
*/
|
||||
get url() : string {
|
||||
if(this.path.length < 1)
|
||||
return AccountImage.urlForFile(defaultAccountImage);
|
||||
|
||||
return AccountImage.urlForFile(this.path);
|
||||
}
|
||||
|
||||
static get errorURL() : string {
|
||||
return this.urlForFile(errorAccountImage);
|
||||
}
|
||||
|
||||
private static urlForFile(file : string) : string {
|
||||
return pathUserData("avatars/" + file, false);
|
||||
}
|
||||
}
|
@ -167,6 +167,13 @@ export class RequestHandler {
|
||||
return this.userID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check out whether user is signed in or not
|
||||
*/
|
||||
public get signedIn() : boolean {
|
||||
return this.userID > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output an error code and throws an error
|
||||
*
|
||||
|
@ -1,3 +1,5 @@
|
||||
import { AccountImage } from "./AccountImage";
|
||||
|
||||
/**
|
||||
* User information
|
||||
*
|
||||
@ -17,6 +19,7 @@ export interface UserBuilder {
|
||||
timeCreate: number,
|
||||
virtualDirectory: string,
|
||||
pageStatus: UserPageStatus,
|
||||
accountImage: AccountImage,
|
||||
}
|
||||
|
||||
export class User {
|
||||
@ -26,6 +29,7 @@ export class User {
|
||||
timeCreate: number;
|
||||
virtualDirectory: string;
|
||||
pageStatus: UserPageStatus;
|
||||
accountImage: AccountImage;
|
||||
|
||||
public constructor(info : UserBuilder) {
|
||||
this.id = info.id;
|
||||
@ -34,6 +38,7 @@ export class User {
|
||||
this.timeCreate = info.timeCreate;
|
||||
this.virtualDirectory = info.virtualDirectory;
|
||||
this.pageStatus = info.pageStatus;
|
||||
this.accountImage = info.accountImage;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user