2022-03-19 10:37:45 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const Base = require('./Base');
|
2022-03-24 10:55:32 +00:00
|
|
|
const ThreadMemberFlags = require('../util/ThreadMemberFlags');
|
2022-03-19 10:37:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents a Member for a Thread.
|
|
|
|
* @extends {Base}
|
|
|
|
*/
|
|
|
|
class ThreadMember extends Base {
|
|
|
|
constructor(thread, data) {
|
|
|
|
super(thread.client);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The thread that this member is a part of
|
|
|
|
* @type {ThreadChannel}
|
|
|
|
*/
|
|
|
|
this.thread = thread;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The timestamp the member last joined the thread at
|
|
|
|
* @type {?number}
|
|
|
|
*/
|
|
|
|
this.joinedTimestamp = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The id of the thread member
|
|
|
|
* @type {Snowflake}
|
|
|
|
*/
|
|
|
|
this.id = data.user_id;
|
|
|
|
|
|
|
|
this._patch(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
_patch(data) {
|
2022-03-24 10:55:32 +00:00
|
|
|
if ('join_timestamp' in data) this.joinedTimestamp = new Date(data.join_timestamp).getTime();
|
2022-03-19 10:37:45 +00:00
|
|
|
|
|
|
|
if ('flags' in data) {
|
|
|
|
/**
|
|
|
|
* The flags for this thread member
|
2022-03-24 10:55:32 +00:00
|
|
|
* @type {ThreadMemberFlags}
|
2022-03-19 10:37:45 +00:00
|
|
|
*/
|
2022-03-24 10:55:32 +00:00
|
|
|
this.flags = new ThreadMemberFlags(data.flags).freeze();
|
2022-03-19 10:37:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The guild member associated with this thread member
|
|
|
|
* @type {?GuildMember}
|
|
|
|
* @readonly
|
|
|
|
*/
|
|
|
|
get guildMember() {
|
|
|
|
return this.thread.guild.members.resolve(this.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The last time this member joined the thread
|
|
|
|
* @type {?Date}
|
|
|
|
* @readonly
|
|
|
|
*/
|
|
|
|
get joinedAt() {
|
2022-03-24 10:55:32 +00:00
|
|
|
return this.joinedTimestamp ? new Date(this.joinedTimestamp) : null;
|
2022-03-19 10:37:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The user associated with this thread member
|
|
|
|
* @type {?User}
|
|
|
|
* @readonly
|
|
|
|
*/
|
|
|
|
get user() {
|
|
|
|
return this.client.users.resolve(this.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the client user can manage this thread member
|
|
|
|
* @type {boolean}
|
|
|
|
* @readonly
|
|
|
|
*/
|
|
|
|
get manageable() {
|
|
|
|
return !this.thread.archived && this.thread.editable;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes this member from the thread.
|
|
|
|
* @param {string} [reason] Reason for removing the member
|
|
|
|
* @returns {ThreadMember}
|
|
|
|
*/
|
|
|
|
async remove(reason) {
|
|
|
|
await this.thread.members.remove(this.id, reason);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = ThreadMember;
|