mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 00:53:31 +01:00
refactor: remove typing caching (#6114)
Co-authored-by: DTrombett <73136330+DTrombett@users.noreply.github.com>
This commit is contained in:
@@ -15,8 +15,6 @@ class ChannelUpdateAction extends Action {
|
||||
if (ChannelTypes[channel.type] !== data.type) {
|
||||
const newChannel = Channel.create(this.client, data, channel.guild);
|
||||
for (const [id, message] of channel.messages.cache) newChannel.messages.cache.set(id, message);
|
||||
newChannel._typing = new Map(channel._typing);
|
||||
channel = newChannel;
|
||||
this.client.channels.cache.set(channel.id, channel);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const { Events, TextBasedChannelTypes } = require('../../util/Constants');
|
||||
const { Events } = require('../../util/Constants');
|
||||
|
||||
class GuildDeleteAction extends Action {
|
||||
constructor(client) {
|
||||
@@ -14,10 +14,6 @@ class GuildDeleteAction extends Action {
|
||||
|
||||
let guild = client.guilds.cache.get(data.id);
|
||||
if (guild) {
|
||||
for (const channel of guild.channels.cache.values()) {
|
||||
if (TextBasedChannelTypes.includes(channel.type)) channel.stopTyping(true);
|
||||
}
|
||||
|
||||
if (data.unavailable) {
|
||||
// Guild is unavailable
|
||||
guild.available = false;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Typing = require('../../structures/Typing');
|
||||
const { Events, TextBasedChannelTypes } = require('../../util/Constants');
|
||||
|
||||
class TypingStart extends Action {
|
||||
@@ -15,43 +16,15 @@ class TypingStart extends Action {
|
||||
}
|
||||
|
||||
const user = this.getUserFromMember(data);
|
||||
const timestamp = new Date(data.timestamp * 1000);
|
||||
|
||||
if (channel && user) {
|
||||
if (channel._typing.has(user.id)) {
|
||||
const typing = channel._typing.get(user.id);
|
||||
|
||||
typing.lastTimestamp = timestamp;
|
||||
typing.elapsedTime = Date.now() - typing.since;
|
||||
this.client.clearTimeout(typing.timeout);
|
||||
typing.timeout = this.tooLate(channel, user);
|
||||
} else {
|
||||
const since = new Date();
|
||||
const lastTimestamp = new Date();
|
||||
channel._typing.set(user.id, {
|
||||
user,
|
||||
since,
|
||||
lastTimestamp,
|
||||
elapsedTime: Date.now() - since,
|
||||
timeout: this.tooLate(channel, user),
|
||||
});
|
||||
|
||||
/**
|
||||
* Emitted whenever a user starts typing in a channel.
|
||||
* @event Client#typingStart
|
||||
* @param {DMChannel|TextChannel|NewsChannel} channel The channel the user started typing in
|
||||
* @param {User} user The user that started typing
|
||||
*/
|
||||
this.client.emit(Events.TYPING_START, channel, user);
|
||||
}
|
||||
/**
|
||||
* Emitted whenever a user starts typing in a channel.
|
||||
* @event Client#typingStart
|
||||
* @param {Typing} typing The typing state
|
||||
*/
|
||||
this.client.emit(Events.TYPING_START, new Typing(channel, user, data));
|
||||
}
|
||||
}
|
||||
|
||||
tooLate(channel, user) {
|
||||
return channel.client.setTimeout(() => {
|
||||
channel._typing.delete(user.id);
|
||||
}, 10000);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TypingStart;
|
||||
|
||||
Reference in New Issue
Block a user