Clean up a bunch of stuff

- Channel typing data is now a Map
- Client properties on structures are now non-enumerable and
non-configurable
This commit is contained in:
Schuyler Cebulskie
2016-09-07 00:24:45 -04:00
parent 3a790e74f4
commit b7f582b7f0
22 changed files with 411 additions and 316 deletions

View File

@@ -9,21 +9,13 @@ class TypingStartHandler extends AbstractHandler {
const user = client.users.get(data.user_id);
const timestamp = new Date(data.timestamp * 1000);
function tooLate() {
return client.setTimeout(() => {
client.emit(Constants.Events.TYPING_STOP, channel, user, channel.typingMap[user.id]);
delete channel.typingMap[user.id];
}, 6000);
}
if (channel && user) {
if (channel.typingMap[user.id]) {
// already typing, renew
const mapping = channel.typingMap[user.id];
mapping.lastTimestamp = timestamp;
mapping.resetTimeout(tooLate());
if (channel._typing.has(user.id)) {
const typing = channel._typing.get(user.id);
typing.lastTimestamp = timestamp;
typing.resetTimeout(tooLate(channel, user));
} else {
channel.typingMap[user.id] = new TypingData(timestamp, timestamp, tooLate());
channel._typing.set(user.id, new TypingData(timestamp, timestamp, tooLate(channel, user)));
client.emit(Constants.Events.TYPING_START, channel, user);
}
}
@@ -47,6 +39,13 @@ class TypingData {
}
}
function tooLate(channel, user) {
return channel.client.setTimeout(() => {
channel.client.emit(Constants.Events.TYPING_STOP, channel, user, channel._typing[user.id]);
delete channel._typing[user.id];
}, 6000);
}
/**
* Emitted whenever a user starts typing in a channel
* @event Client#typingStart