Fixed typing and added createChannel

This commit is contained in:
hydrabolt
2015-11-02 17:14:04 +00:00
parent 576715f531
commit 25f0408fae
6 changed files with 164 additions and 48 deletions

View File

@@ -384,6 +384,35 @@ var InternalClient = (function () {
});
};
// def createChannel
InternalClient.prototype.createChannel = function createChannel(server, name) {
var type = arguments.length <= 2 || arguments[2] === undefined ? "text" : arguments[2];
var self = this;
return new Promise(function (resolve, reject) {
server = self.resolver.resolveServer(server);
request.post(Endpoints.SERVER_CHANNELS(server.id)).set("authorization", self.token).send({
name: name, type: type
}).end(function (err, res) {
if (err) {
reject(err);
} else {
var channel;
if (res.body.type === "text") {
channel = new TextChannel(res.body, self.client, server);
} else {
channel = new VoiceChannel(res.body, self.client, server);
}
resolve(server.channels.add(self.channels.add(channel)));
}
});
});
};
InternalClient.prototype.sendWS = function sendWS(object) {
if (this.websocket) this.websocket.send(JSON.stringify(object));
};
@@ -760,11 +789,14 @@ var InternalClient = (function () {
var channel = self.channels.get("id", data.channel_id);
if (user && channel) {
user.typing.since = Date.now();
user.typing.channel = channel;
client.emit("userTypingStart", user, channel);
if (user.typing.since) {
user.typing.since = Date.now();
user.typing.channel = channel;
} else {
user.typing.since = Date.now();
user.typing.channel = channel;
client.emit("userTypingStart", user, channel);
}
setTimeout(function () {
if (Date.now() - user.typing.since > 5990) {
// they haven't typed since