From 98a62eb94eebd118a4fd4f7792b3963ef371f5b1 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Fri, 6 Nov 2015 20:07:28 +0000 Subject: [PATCH] Added setTopic implementation --- lib/Client/Client.js | 18 ++++++++++++++++++ lib/Client/InternalClient.js | 28 ++++++++++++++++++++++++++++ src/Client/Client.js | 18 ++++++++++++++++++ src/Client/InternalClient.js | 31 +++++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+) diff --git a/lib/Client/Client.js b/lib/Client/Client.js index 29e2bc1f9..04d2d88a0 100644 --- a/lib/Client/Client.js +++ b/lib/Client/Client.js @@ -460,6 +460,24 @@ var Client = (function (_EventEmitter) { }); }; + // def setTopic + + Client.prototype.setTopic = function setTopic(channel, topic) { + var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err) {} : arguments[2]; + + var self = this; + return new Promise(function (resolve, reject) { + + self.internal.setTopic(channel, topic).then(function () { + callback(); + resolve(); + })["catch"](function (e) { + callback(e); + reject(e); + }); + }); + }; + _createClass(Client, [{ key: "users", get: function get() { diff --git a/lib/Client/InternalClient.js b/lib/Client/InternalClient.js index 97ad9bd8d..76d620f2d 100644 --- a/lib/Client/InternalClient.js +++ b/lib/Client/InternalClient.js @@ -729,6 +729,34 @@ var InternalClient = (function () { }); }; + //def setTopic + + InternalClient.prototype.setTopic = function setTopic(chann) { + var topic = arguments.length <= 1 || arguments[1] === undefined ? "" : arguments[1]; + + var self = this; + return new Promise(function (resolve, reject) { + + self.resolver.resolveChannel(chann).then(next)["catch"](reject); + + function next(channel) { + + request.patch(Endpoints.CHANNEL(channel.id)).set("authorization", self.token).send({ + name: channel.name, + position: 0, + topic: topic + }).end(function (err, res) { + if (err) { + reject(err); + } else { + channel.topic = res.body.topic; + resolve(); + } + }); + } + }); + }; + InternalClient.prototype.sendWS = function sendWS(object) { if (this.websocket) this.websocket.send(JSON.stringify(object)); }; diff --git a/src/Client/Client.js b/src/Client/Client.js index 7288f4568..8e85f3fc6 100644 --- a/src/Client/Client.js +++ b/src/Client/Client.js @@ -441,6 +441,24 @@ class Client extends EventEmitter { }); } + + // def setTopic + setTopic(channel, topic, callback=function(err){}){ + var self = this; + return new Promise((resolve, reject) => { + + self.internal.setTopic(channel, topic) + .then(() => { + callback(); + resolve(); + }) + .catch(e => { + callback(e); + reject(e); + }); + + }) + } } module.exports = Client; \ No newline at end of file diff --git a/src/Client/InternalClient.js b/src/Client/InternalClient.js index 9339c55be..5336188d2 100644 --- a/src/Client/InternalClient.js +++ b/src/Client/InternalClient.js @@ -776,6 +776,37 @@ class InternalClient { } }); } + + //def setTopic + setTopic(chann, topic=""){ + var self = this; + return new Promise((resolve, reject) => { + + self.resolver.resolveChannel(chann).then(next).catch(reject); + + function next(channel){ + + request + .patch(Endpoints.CHANNEL(channel.id)) + .set("authorization", self.token) + .send({ + name : channel.name, + position : 0, + topic : topic + }) + .end((err, res) => { + if(err){ + reject(err); + }else{ + channel.topic = res.body.topic; + resolve(); + } + }) + + } + + }); + } sendWS(object) { if (this.websocket)