Skip to content

Commit

Permalink
refactor: Remove fromInteraction in internal channel creation (#9335)
Browse files Browse the repository at this point in the history
refactor: remove `fromInteraction`
  • Loading branch information
Jiralite committed Apr 14, 2023
1 parent 02dfaf1 commit 794abe8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
6 changes: 3 additions & 3 deletions packages/discord.js/src/managers/ChannelManager.js
Expand Up @@ -36,18 +36,18 @@ class ChannelManager extends CachedManager {
* @name ChannelManager#cache
*/

_add(data, guild, { cache = true, allowUnknownGuild = false, fromInteraction = false } = {}) {
_add(data, guild, { cache = true, allowUnknownGuild = false } = {}) {
const existing = this.cache.get(data.id);
if (existing) {
if (cache) existing._patch(data, fromInteraction);
if (cache) existing._patch(data);
guild?.channels?._add(existing);
if (ThreadChannelTypes.includes(existing.type)) {
existing.parent?.threads?._add(existing);
}
return existing;
}

const channel = createChannel(this.client, data, guild, { allowUnknownGuild, fromInteraction });
const channel = createChannel(this.client, data, guild, { allowUnknownGuild });

if (!channel) {
this.client.emit(Events.Debug, `Failed to find guild, or unknown type for channel ${data.id} ${data.type}`);
Expand Down
8 changes: 4 additions & 4 deletions packages/discord.js/src/structures/ThreadChannel.js
Expand Up @@ -14,7 +14,7 @@ const ChannelFlagsBitField = require('../util/ChannelFlagsBitField');
* @implements {TextBasedChannel}
*/
class ThreadChannel extends BaseChannel {
constructor(guild, data, client, fromInteraction = false) {
constructor(guild, data, client) {
super(guild?.client ?? client, data, false);

/**
Expand All @@ -40,10 +40,10 @@ class ThreadChannel extends BaseChannel {
* @type {ThreadMemberManager}
*/
this.members = new ThreadMemberManager(this);
if (data) this._patch(data, fromInteraction);
if (data) this._patch(data);
}

_patch(data, partial = false) {
_patch(data) {
super._patch(data);

if ('message' in data) this.messages._add(data.message);
Expand Down Expand Up @@ -149,7 +149,7 @@ class ThreadChannel extends BaseChannel {
this.lastPinTimestamp ??= null;
}

if ('rate_limit_per_user' in data || !partial) {
if ('rate_limit_per_user' in data) {
/**
* The rate limit per user (slowmode) for this thread in seconds
* @type {?number}
Expand Down
4 changes: 2 additions & 2 deletions packages/discord.js/src/util/Channels.js
Expand Up @@ -23,7 +23,7 @@ const getForumChannel = lazy(() => require('../structures/ForumChannel'));
* @returns {Channel} Any kind of channel.
* @ignore
*/
function createChannel(client, data, guild, { allowUnknownGuild, fromInteraction } = {}) {
function createChannel(client, data, guild, { allowUnknownGuild } = {}) {
let channel;
if (!data.guild_id && !guild) {
if ((data.recipients && data.type !== ChannelType.GroupDM) || data.type === ChannelType.DM) {
Expand Down Expand Up @@ -59,7 +59,7 @@ function createChannel(client, data, guild, { allowUnknownGuild, fromInteraction
case ChannelType.AnnouncementThread:
case ChannelType.PublicThread:
case ChannelType.PrivateThread: {
channel = new (getThreadChannel())(guild, data, client, fromInteraction);
channel = new (getThreadChannel())(guild, data, client);
if (!allowUnknownGuild) channel.parent?.threads.cache.set(channel.id, channel);
break;
}
Expand Down
3 changes: 1 addition & 2 deletions packages/discord.js/typings/index.d.ts
Expand Up @@ -2944,7 +2944,7 @@ export class ThreadChannel<Forum extends boolean = boolean> extends TextBasedCha
'createWebhook',
'setNSFW',
]) {
private constructor(guild: Guild, data?: RawThreadChannelData, client?: Client<true>, fromInteraction?: boolean);
private constructor(guild: Guild, data?: RawThreadChannelData, client?: Client<true>);
public archived: boolean | null;
public get archivedAt(): Date | null;
public archiveTimestamp: number | null;
Expand Down Expand Up @@ -3138,7 +3138,6 @@ export interface MappedComponentTypes {

export interface ChannelCreateOptions {
allowFromUnknownGuild?: boolean;
fromInteraction?: boolean;
}

export function createChannel(client: Client<true>, data: APIChannel, options?: ChannelCreateOptions): Channel;
Expand Down

0 comments on commit 794abe8

Please sign in to comment.