Merge remote-tracking branch 'upstream/rewrite' into rewrite

This commit is contained in:
abalabahaha
2015-11-15 12:47:43 -08:00
15 changed files with 177 additions and 0 deletions

View File

@@ -999,6 +999,29 @@ var InternalClient = (function () {
return this.setChannelNameAndTopic(chann, data.name, data.topic);
};
//def ack
InternalClient.prototype.ack = function ack(msg) {
var self = this;
return new Promise(function (resolve, reject) {
msg = self.resolver.resolveMessage(msg);
if (msg) {
request.post(Endpoints.CHANNEL_MESSAGE(msg.channel.id, msg.id) + "/ack").set("authorization", self.token).end(function (err) {
if (err) {
reject(err);
} else {
resolve();
}
});
} else {
reject(new Error("Message does not exist"));
}
});
};
InternalClient.prototype.sendWS = function sendWS(object) {
if (this.websocket) this.websocket.send(JSON.stringify(object));
};
@@ -1088,6 +1111,7 @@ var InternalClient = (function () {
if (channel) {
var msg = channel.messages.add(new Message(data, channel, client));
client.emit("message", msg);
self.ack(msg);
} else {
client.emit("warn", "message created but channel is not cached");
}