From 0c5caefa9f4e53ab9d02eb91b8c1a467dda26096 Mon Sep 17 00:00:00 2001 From: Neto Becker Date: Thu, 15 Oct 2015 11:41:18 -0300 Subject: [PATCH 1/3] store gameId on user object --- lib/ChannelPermissions.js | 2 +- lib/Client.js | 7 +++++-- lib/Endpoints.js | 2 +- lib/EvaluatedPermissions.js | 2 +- lib/Member.js | 2 +- lib/PMChannel.js | 2 +- lib/ServerPermissions.js | 2 +- lib/channel.js | 2 +- lib/index.js | 2 +- lib/internal.js | 2 +- lib/invite.js | 2 +- lib/message.js | 2 +- lib/server.js | 2 +- lib/user.js | 3 ++- src/Client.js | 5 ++++- src/user.js | 1 + 16 files changed, 24 insertions(+), 16 deletions(-) diff --git a/lib/ChannelPermissions.js b/lib/ChannelPermissions.js index bbc8545db..71d7da55d 100644 --- a/lib/ChannelPermissions.js +++ b/lib/ChannelPermissions.js @@ -179,4 +179,4 @@ var ChannelPermissions = (function () { return ChannelPermissions; })(); -module.exports = ChannelPermissions; \ No newline at end of file +module.exports = ChannelPermissions; diff --git a/lib/Client.js b/lib/Client.js index f02f8f1d6..2d0ba4a34 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -1091,6 +1091,7 @@ var Client = (function () { gameId: data.game_id }); userInCache.status = data.status; + userInCache.gameId = data.game_id; } else { //one of their details changed. self.userCache[self.userCache.indexOf(userInCache)] = presenceUser; @@ -1288,7 +1289,9 @@ var Client = (function () { for (var _iterator9 = data.presences[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) { var presence = _step9.value; - self.getUser("id", presence.user.id).status = presence.status; + var user = self.getUser("id", presence.user.id); + user.status = presence.status; + user.gameId = presence.game_id; } } catch (err) { _didIteratorError9 = true; @@ -1864,4 +1867,4 @@ var Client = (function () { return Client; })(); -module.exports = Client; \ No newline at end of file +module.exports = Client; diff --git a/lib/Endpoints.js b/lib/Endpoints.js index 271b465eb..e55f0f580 100644 --- a/lib/Endpoints.js +++ b/lib/Endpoints.js @@ -10,4 +10,4 @@ exports.LOGIN = exports.AUTH + "/login"; exports.LOGOUT = exports.AUTH + "/logout"; exports.USERS = exports.API + "/users"; exports.SERVERS = exports.API + "/guilds"; -exports.CHANNELS = exports.API + "/channels"; \ No newline at end of file +exports.CHANNELS = exports.API + "/channels"; diff --git a/lib/EvaluatedPermissions.js b/lib/EvaluatedPermissions.js index b441500cf..ed213ac6e 100644 --- a/lib/EvaluatedPermissions.js +++ b/lib/EvaluatedPermissions.js @@ -169,4 +169,4 @@ var EvaluatedPermissions = (function () { return EvaluatedPermissions; })(); -module.exports = EvaluatedPermissions; \ No newline at end of file +module.exports = EvaluatedPermissions; diff --git a/lib/Member.js b/lib/Member.js index ba29467db..e2596b7ea 100644 --- a/lib/Member.js +++ b/lib/Member.js @@ -222,4 +222,4 @@ var Member = (function (_User) { return Member; })(User); -module.exports = Member; \ No newline at end of file +module.exports = Member; diff --git a/lib/PMChannel.js b/lib/PMChannel.js index f777d342c..0f4bb36ba 100644 --- a/lib/PMChannel.js +++ b/lib/PMChannel.js @@ -69,4 +69,4 @@ var PMChannel = (function () { return PMChannel; })(); -module.exports = PMChannel; \ No newline at end of file +module.exports = PMChannel; diff --git a/lib/ServerPermissions.js b/lib/ServerPermissions.js index 73148ca06..e730fcd42 100644 --- a/lib/ServerPermissions.js +++ b/lib/ServerPermissions.js @@ -199,4 +199,4 @@ var ServerPermissions = (function () { return ServerPermissions; })(); -module.exports = ServerPermissions; \ No newline at end of file +module.exports = ServerPermissions; diff --git a/lib/channel.js b/lib/channel.js index 4ff1e673c..42e701b10 100644 --- a/lib/channel.js +++ b/lib/channel.js @@ -149,4 +149,4 @@ var Channel = (function () { return Channel; })(); -module.exports = Channel; \ No newline at end of file +module.exports = Channel; diff --git a/lib/index.js b/lib/index.js index 6a2f82f05..f0c3c0ab7 100644 --- a/lib/index.js +++ b/lib/index.js @@ -9,4 +9,4 @@ var Discord = { Client: Client }; -module.exports = Discord; \ No newline at end of file +module.exports = Discord; diff --git a/lib/internal.js b/lib/internal.js index 3acf5940b..e8b3385da 100644 --- a/lib/internal.js +++ b/lib/internal.js @@ -200,4 +200,4 @@ Internal.XHR.setUsername = function (token, avatar, email, newPassword, password }); }; -exports.Internal = Internal; \ No newline at end of file +exports.Internal = Internal; diff --git a/lib/invite.js b/lib/invite.js index 5f51dc1a9..7bc8204bd 100644 --- a/lib/invite.js +++ b/lib/invite.js @@ -32,4 +32,4 @@ var Invite = (function () { return Invite; })(); -module.exports = Invite; \ No newline at end of file +module.exports = Invite; diff --git a/lib/message.js b/lib/message.js index a156acc81..7152b1d0f 100644 --- a/lib/message.js +++ b/lib/message.js @@ -82,4 +82,4 @@ var Message = (function () { return Message; })(); -module.exports = Message; \ No newline at end of file +module.exports = Message; diff --git a/lib/server.js b/lib/server.js index 871e30928..4b225584a 100644 --- a/lib/server.js +++ b/lib/server.js @@ -341,4 +341,4 @@ var Server = (function () { return Server; })(); -module.exports = Server; \ No newline at end of file +module.exports = Server; diff --git a/lib/user.js b/lib/user.js index 9a3d64c88..cb6663852 100644 --- a/lib/user.js +++ b/lib/user.js @@ -13,6 +13,7 @@ var User = (function () { this.id = data.id; this.avatar = data.avatar; this.status = data.status || "offline"; + this.gameId = data.game_id || null; } // access using user.avatarURL; @@ -54,4 +55,4 @@ var User = (function () { return User; })(); -module.exports = User; \ No newline at end of file +module.exports = User; diff --git a/src/Client.js b/src/Client.js index 1900642f7..79da43ec1 100644 --- a/src/Client.js +++ b/src/Client.js @@ -1000,6 +1000,7 @@ class Client { gameId: data.game_id }); userInCache.status = data.status; + userInCache.gameId = data.game_id; } else { //one of their details changed. self.userCache[self.userCache.indexOf(userInCache)] = presenceUser; @@ -1168,7 +1169,9 @@ class Client { } for (var presence of data.presences) { - self.getUser("id", presence.user.id).status = presence.status; + var user = self.getUser("id", presence.user.id); + user.status = presence.status; + user.gameId = presence.game_id; } return server; diff --git a/src/user.js b/src/user.js index 9686fed27..30af4f3e6 100644 --- a/src/user.js +++ b/src/user.js @@ -5,6 +5,7 @@ class User{ this.id = data.id; this.avatar = data.avatar; this.status = data.status || "offline"; + this.gameId = data.game_id || null; } // access using user.avatarURL; From 0e8264c9cee8113baff4b2fc72bdfc988dd4c6ee Mon Sep 17 00:00:00 2001 From: Neto Becker Date: Thu, 15 Oct 2015 11:45:21 -0300 Subject: [PATCH 2/3] fix private messages --- lib/Client.js | 9 +++++++-- src/Client.js | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/Client.js b/lib/Client.js index 2d0ba4a34..cc86f6f87 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -1013,7 +1013,12 @@ var Client = (function () { if (!channel) { - var chann = self.addChannel(data, data.guild_id); + var chann; + if (data.is_private) { + chann = self.addPMChannel(data); + } else { + chann = self.addChannel(data, data.guild_id); + } var srv = self.getServer("id", data.guild_id); if (srv) { srv.addChannel(chann); @@ -1507,7 +1512,7 @@ var Client = (function () { for (var _iterator14 = self.pmChannelCache[Symbol.iterator](), _step14; !(_iteratorNormalCompletion14 = (_step14 = _iterator14.next()).done); _iteratorNormalCompletion14 = true) { var pmc = _step14.value; - if (pmc.user.equals(destination)) { + if (pmc.user && pmc.user.equals(destination)) { resolve(pmc.id); return; } diff --git a/src/Client.js b/src/Client.js index 79da43ec1..ad9b33524 100644 --- a/src/Client.js +++ b/src/Client.js @@ -920,7 +920,12 @@ class Client { if (!channel) { - var chann = self.addChannel(data, data.guild_id); + var chann; + if (data.is_private) { + chann = self.addPMChannel(data); + } else { + chann = self.addChannel(data, data.guild_id); + } var srv = self.getServer("id", data.guild_id); if (srv) { srv.addChannel(chann); @@ -1268,7 +1273,7 @@ class Client { //check if we have a PM for (var pmc of self.pmChannelCache) { - if (pmc.user.equals(destination)) { + if (pmc.user && pmc.user.equals(destination)) { resolve(pmc.id); return; } From 23fae86ccb8c061706ee2847bccb239ecac1b3c8 Mon Sep 17 00:00:00 2001 From: Neto Becker Date: Thu, 15 Oct 2015 11:55:18 -0300 Subject: [PATCH 3/3] removed new line on end of files --- lib/ChannelPermissions.js | 2 +- lib/Client.js | 2 +- lib/Endpoints.js | 2 +- lib/EvaluatedPermissions.js | 2 +- lib/Member.js | 2 +- lib/PMChannel.js | 2 +- lib/ServerPermissions.js | 2 +- lib/channel.js | 2 +- lib/index.js | 2 +- lib/internal.js | 2 +- lib/invite.js | 2 +- lib/message.js | 2 +- lib/server.js | 2 +- lib/user.js | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/ChannelPermissions.js b/lib/ChannelPermissions.js index 71d7da55d..bbc8545db 100644 --- a/lib/ChannelPermissions.js +++ b/lib/ChannelPermissions.js @@ -179,4 +179,4 @@ var ChannelPermissions = (function () { return ChannelPermissions; })(); -module.exports = ChannelPermissions; +module.exports = ChannelPermissions; \ No newline at end of file diff --git a/lib/Client.js b/lib/Client.js index cc86f6f87..7cf2e0ec6 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -1872,4 +1872,4 @@ var Client = (function () { return Client; })(); -module.exports = Client; +module.exports = Client; \ No newline at end of file diff --git a/lib/Endpoints.js b/lib/Endpoints.js index e55f0f580..271b465eb 100644 --- a/lib/Endpoints.js +++ b/lib/Endpoints.js @@ -10,4 +10,4 @@ exports.LOGIN = exports.AUTH + "/login"; exports.LOGOUT = exports.AUTH + "/logout"; exports.USERS = exports.API + "/users"; exports.SERVERS = exports.API + "/guilds"; -exports.CHANNELS = exports.API + "/channels"; +exports.CHANNELS = exports.API + "/channels"; \ No newline at end of file diff --git a/lib/EvaluatedPermissions.js b/lib/EvaluatedPermissions.js index ed213ac6e..b441500cf 100644 --- a/lib/EvaluatedPermissions.js +++ b/lib/EvaluatedPermissions.js @@ -169,4 +169,4 @@ var EvaluatedPermissions = (function () { return EvaluatedPermissions; })(); -module.exports = EvaluatedPermissions; +module.exports = EvaluatedPermissions; \ No newline at end of file diff --git a/lib/Member.js b/lib/Member.js index e2596b7ea..ba29467db 100644 --- a/lib/Member.js +++ b/lib/Member.js @@ -222,4 +222,4 @@ var Member = (function (_User) { return Member; })(User); -module.exports = Member; +module.exports = Member; \ No newline at end of file diff --git a/lib/PMChannel.js b/lib/PMChannel.js index 0f4bb36ba..f777d342c 100644 --- a/lib/PMChannel.js +++ b/lib/PMChannel.js @@ -69,4 +69,4 @@ var PMChannel = (function () { return PMChannel; })(); -module.exports = PMChannel; +module.exports = PMChannel; \ No newline at end of file diff --git a/lib/ServerPermissions.js b/lib/ServerPermissions.js index e730fcd42..73148ca06 100644 --- a/lib/ServerPermissions.js +++ b/lib/ServerPermissions.js @@ -199,4 +199,4 @@ var ServerPermissions = (function () { return ServerPermissions; })(); -module.exports = ServerPermissions; +module.exports = ServerPermissions; \ No newline at end of file diff --git a/lib/channel.js b/lib/channel.js index 42e701b10..4ff1e673c 100644 --- a/lib/channel.js +++ b/lib/channel.js @@ -149,4 +149,4 @@ var Channel = (function () { return Channel; })(); -module.exports = Channel; +module.exports = Channel; \ No newline at end of file diff --git a/lib/index.js b/lib/index.js index f0c3c0ab7..6a2f82f05 100644 --- a/lib/index.js +++ b/lib/index.js @@ -9,4 +9,4 @@ var Discord = { Client: Client }; -module.exports = Discord; +module.exports = Discord; \ No newline at end of file diff --git a/lib/internal.js b/lib/internal.js index e8b3385da..3acf5940b 100644 --- a/lib/internal.js +++ b/lib/internal.js @@ -200,4 +200,4 @@ Internal.XHR.setUsername = function (token, avatar, email, newPassword, password }); }; -exports.Internal = Internal; +exports.Internal = Internal; \ No newline at end of file diff --git a/lib/invite.js b/lib/invite.js index 7bc8204bd..5f51dc1a9 100644 --- a/lib/invite.js +++ b/lib/invite.js @@ -32,4 +32,4 @@ var Invite = (function () { return Invite; })(); -module.exports = Invite; +module.exports = Invite; \ No newline at end of file diff --git a/lib/message.js b/lib/message.js index 7152b1d0f..a156acc81 100644 --- a/lib/message.js +++ b/lib/message.js @@ -82,4 +82,4 @@ var Message = (function () { return Message; })(); -module.exports = Message; +module.exports = Message; \ No newline at end of file diff --git a/lib/server.js b/lib/server.js index 4b225584a..871e30928 100644 --- a/lib/server.js +++ b/lib/server.js @@ -341,4 +341,4 @@ var Server = (function () { return Server; })(); -module.exports = Server; +module.exports = Server; \ No newline at end of file diff --git a/lib/user.js b/lib/user.js index cb6663852..1f0fb0eed 100644 --- a/lib/user.js +++ b/lib/user.js @@ -55,4 +55,4 @@ var User = (function () { return User; })(); -module.exports = User; +module.exports = User; \ No newline at end of file