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

@@ -251,6 +251,8 @@ var Client = (function (_EventEmitter) {
});
};
// def leaveServer
Client.prototype.leaveServer = function leaveServer(server) {
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err) {} : arguments[1];
@@ -265,6 +267,26 @@ var Client = (function (_EventEmitter) {
});
};
// def createChannel
Client.prototype.createChannel = function createChannel(server, name) {
var type = arguments.length <= 2 || arguments[2] === undefined ? "text" : arguments[2];
var callback = arguments.length <= 3 || arguments[3] === undefined ? function (err, channel) {} : arguments[3];
var self = this;
return new Promise(function (resolve, reject) {
if (typeof type === "function") {
// options is the callback
callback = type;
}
self.internal.createChannel(server, name, type).then(function (channel) {
callback(channel);resolve(channel);
})["catch"](function (e) {
callback(e);reject(e);
});
});
};
return Client;
})(EventEmitter);

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