mirror of
https://github.com/projectdysnomia/dysnomia.git
synced 2026-12-02 13:48:31 +02:00
This should allow for not using the `Client.channelGuildMap`, `Client.threadGuildMap`, and `Client.guildShardMap` when `caching.disableMaps` is on. Some caveats: - Obviously `getChannel` will do linear searching now, but this can be skipped with guild hinting. `getChannel` now has a `guildIDHint` parameter for getting that specific guild rather than searching all of them. Which has some caveats: - `editChannelPosition`'s option param has `guildIDHint`, it's channel's corresponding function will use it. - Same for `joinVoiceChannel` and `leaveVoiceChannel`, but `leaveVoiceChannel` has it's hinting in a new parameter. - `ThreadMember`'s construction to find the guild *will* do linear searching, sad. - Many of the shard events that use `getChannel` either now hint at the guild or just gets the guild directly. --------- Co-authored-by: TTtie <me@tttie.cz>
78 lines
2.0 KiB
JavaScript
78 lines
2.0 KiB
JavaScript
"use strict";
|
|
|
|
const Base = require("./Base");
|
|
const Member = require("./Member");
|
|
|
|
/**
|
|
* Represents a thread member
|
|
* @extends Base
|
|
*/
|
|
class ThreadMember extends Base {
|
|
/**
|
|
* The ID of the thread member
|
|
* @member {String} ThreadMember#id
|
|
*/
|
|
#client;
|
|
constructor(data, client) {
|
|
super(data.user_id);
|
|
this.#client = client;
|
|
/**
|
|
* The user-thread settings of this member
|
|
* @type {Number}
|
|
*/
|
|
this.flags = data.flags;
|
|
/**
|
|
* The ID of the thread this member is a part of
|
|
* @type {String}
|
|
*/
|
|
this.threadID = data.thread_id || data.id; // Thanks Discord
|
|
/**
|
|
* Timestamp of when the member joined the thread
|
|
* @type {Number}
|
|
*/
|
|
this.joinTimestamp = Date.parse(data.join_timestamp);
|
|
|
|
if(data.member !== undefined) {
|
|
if(data.member.id === undefined) {
|
|
data.member.id = this.id;
|
|
}
|
|
|
|
const guild = client.options.caching.disableMaps ? this.#client.guilds.find((g) => g.threads.has(this.threadID)) : this.#client.guilds.get(this.#client.threadGuildMap[this.threadID]);
|
|
/**
|
|
* The guild member that this thread member belongs to
|
|
* @type {Member?}
|
|
*/
|
|
this.guildMember = guild ? guild.members.update(data.member, guild) : new Member(data.member, guild, client);
|
|
if(data.presence) {
|
|
this.guildMember.update(data.presence);
|
|
}
|
|
}
|
|
|
|
this.update(data);
|
|
}
|
|
|
|
update(data) {
|
|
if(data.flags !== undefined) {
|
|
this.flags = data.flags;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Remove the member from the thread
|
|
* @returns {Promise}
|
|
*/
|
|
leave() {
|
|
return this.#client.leaveThread.call(this.#client, this.threadID, this.id);
|
|
}
|
|
|
|
toJSON(props = []) {
|
|
return super.toJSON([
|
|
"threadID",
|
|
"joinTimestamp",
|
|
...props
|
|
]);
|
|
}
|
|
}
|
|
|
|
module.exports = ThreadMember;
|