2019-11-23 16:10:51 +01: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)
|
|
|
|
return AccountImage.urlForFile(defaultAccountImage);
|
|
|
|
|
|
|
|
return AccountImage.urlForFile(this.path);
|
|
|
|
}
|
|
|
|
|
2020-03-22 14:36:44 +01: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 16:10:51 +01:00
|
|
|
static get errorURL() : string {
|
|
|
|
return this.urlForFile(errorAccountImage);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static urlForFile(file : string) : string {
|
|
|
|
return pathUserData("avatars/" + file, false);
|
|
|
|
}
|
|
|
|
}
|