2019-11-23 15:10:51 +00:00
|
|
|
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)
|
2020-03-22 14:00:08 +00:00
|
|
|
return AccountImage.pathForFile(defaultAccountImage);
|
2019-11-23 15:10:51 +00:00
|
|
|
|
2020-03-22 14:00:08 +00:00
|
|
|
return AccountImage.pathForFile(this.path);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get account image sys path
|
|
|
|
*/
|
|
|
|
get sysPath() : string {
|
|
|
|
if(this.path.length < 1)
|
|
|
|
throw new Error("This user has no account image!");
|
|
|
|
|
|
|
|
return AccountImage.pathForFile(this.path, true);
|
2019-11-23 15:10:51 +00:00
|
|
|
}
|
|
|
|
|
2020-03-22 13:36:44 +00:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2019-11-23 15:10:51 +00:00
|
|
|
static get errorURL() : string {
|
2020-03-22 14:00:08 +00:00
|
|
|
return this.pathForFile(errorAccountImage);
|
2019-11-23 15:10:51 +00:00
|
|
|
}
|
|
|
|
|
2020-03-22 14:00:08 +00:00
|
|
|
private static pathForFile(file : string, sysPath = false) : string {
|
|
|
|
return pathUserData("avatars/" + file, sysPath);
|
2019-11-23 15:10:51 +00:00
|
|
|
}
|
|
|
|
}
|