mirror of
https://github.com/stoatchat/javascript-client-sdk.git
synced 2026-07-20 20:16:06 -04:00
feat: add helper getters for messages
This commit is contained in:
@@ -230,6 +230,20 @@ export class Member {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a pre-configured avatar URL of a member
|
||||
*/
|
||||
get avatarURL() {
|
||||
return this.generateAvatarURL({ max_side: 256 }) ?? this.user?.avatarURL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a pre-configured animated avatar URL of a member
|
||||
*/
|
||||
get animatedAvatarURL() {
|
||||
return this.generateAvatarURL({ max_side: 256 }, true) ?? this.user?.animatedAvatarURL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate URL to this member's avatar
|
||||
* @param args File parameters
|
||||
|
||||
@@ -86,6 +86,40 @@ export class Message {
|
||||
return this.client.configuration?.app + this.path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the username for this message.
|
||||
*/
|
||||
get username() {
|
||||
return this.masquerade?.name ?? this.member?.nickname ?? this.author?.username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the role colour for this message.
|
||||
*/
|
||||
get roleColour() {
|
||||
return this.member?.roleColour;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the avatar URL for this message.
|
||||
*/
|
||||
get avatarURL() {
|
||||
return this.generateMasqAvatarURL()
|
||||
?? (this.member
|
||||
? this.member?.avatarURL
|
||||
: this.author?.avatarURL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the animated avatar URL for this message.
|
||||
*/
|
||||
get animatedAvatarURL() {
|
||||
return this.generateMasqAvatarURL()
|
||||
?? (this.member
|
||||
? this.member?.animatedAvatarURL
|
||||
: this.author?.animatedAvatarURL);
|
||||
}
|
||||
|
||||
@computed generateMasqAvatarURL() {
|
||||
const avatar = this.masquerade?.avatar;
|
||||
return avatar ? this.client.proxyFile(avatar) : undefined;
|
||||
|
||||
@@ -179,6 +179,20 @@ export class User {
|
||||
return `${this.client.apiURL}/users/${this._id}/default_avatar`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a pre-configured avatar URL of a user
|
||||
*/
|
||||
get avatarURL() {
|
||||
return this.generateAvatarURL({ max_side: 256 });
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a pre-configured animated avatar URL of a user
|
||||
*/
|
||||
get animatedAvatarURL() {
|
||||
return this.generateAvatarURL({ max_side: 256 }, true);
|
||||
}
|
||||
|
||||
@computed generateAvatarURL(...args: FileArgs) {
|
||||
return (
|
||||
this.client.generateFileURL(this.avatar ?? undefined, ...args) ??
|
||||
|
||||
Reference in New Issue
Block a user