From fbe607500980a4c04184446f1f2b9c6a576c0259 Mon Sep 17 00:00:00 2001 From: Yami Date: Tue, 29 Nov 2016 13:38:17 +0000 Subject: [PATCH 1/4] refactor: Rename Chat to PrivateMessage in public-facing apis --- providers/nodebb/index.js | 5 +++-- test/providers/nodebb/indexTest.js | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/providers/nodebb/index.js b/providers/nodebb/index.js index b41db0d5..8ff93edb 100644 --- a/providers/nodebb/index.js +++ b/providers/nodebb/index.js @@ -55,7 +55,8 @@ class Forum extends EventEmitter { this.Category = categoryModule.bindCategory(this); this.User = userModule.bindUser(this); this.Notification = notifications.bindNotification(this); - this.Chat = chatModule.bindChat(this); + this.PrivateMessage = chatModule.bindChat(this); + this.Chat = this.PrivateMessage; this.Format = formatters; this._plugins = []; } @@ -404,7 +405,7 @@ class Forum extends EventEmitter { */ supports(supportString) { const supported = [ - 'Chats', + 'PrivateMessage', 'Users', 'Users.Avatars', 'Users.Follow', 'Users.URL', 'Users.Seen', 'Users.PostCount', 'Posts', 'Posts.Edit', 'Posts.Vote', 'Posts.Delete', 'Posts.Bookmark', 'Posts.URL', 'Topics', 'Topics.URL', 'Topics.Watch', 'Topics.Mute', diff --git a/test/providers/nodebb/indexTest.js b/test/providers/nodebb/indexTest.js index 83212572..23de9567 100644 --- a/test/providers/nodebb/indexTest.js +++ b/test/providers/nodebb/indexTest.js @@ -881,7 +881,7 @@ describe('providers/nodebb', () => { }); it('must return true if a capability is supported', () => { - forum.supports('Chats').should.be.true; + forum.supports('PrivateMessage').should.be.true; forum.supports('Users').should.be.true; forum.supports('Posts').should.be.true; forum.supports('Topics').should.be.true; @@ -900,11 +900,11 @@ describe('providers/nodebb', () => { }); it('should return true if all items in an array are supported', () => { - forum.supports(['Users', 'Chats']).should.be.true; + forum.supports(['Users', 'PrivateMessage']).should.be.true; }); it('must return false if any items in an array are not supported', () => { - forum.supports(['Users', 'Chats', 'Halloween']).should.be.false; + forum.supports(['Users', 'PrivateMessage', 'Halloween']).should.be.false; }); }); describe('_emit', () => { From 3178b145e5789bf90c24e37a2a94885d91bc8306 Mon Sep 17 00:00:00 2001 From: Yami Date: Tue, 29 Nov 2016 13:48:47 +0000 Subject: [PATCH 2/4] fix: add missing dependency --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 0d7f2937..2ca57c9c 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "eslint": "^3.11.0", "ghooks": "^1.3.2", "istanbul": "^0.4.3", + "jsdoc-to-markdown": "^2.0.1", "mkdirp": "^0.5.1", "mocha": "^3.0.2", "semantic-release": "^4.3.5", From 92616603fbb02ce9052eaff705579d1e60da337b Mon Sep 17 00:00:00 2001 From: Yami Date: Tue, 29 Nov 2016 16:14:14 +0000 Subject: [PATCH 3/4] refactor(Chat): Renamed the concept of a Chat to a PM in outward-facing APIs for Command and Notific Since Private Message is the generic term, we are using this going forward for non-nodeBB providers BREAKING CHANGE: getRoom renamed to getPM. Closes #359 --- lib/commands.js | 22 +++++++++++----------- providers/nodebb/chat.js | 2 +- providers/nodebb/notification.js | 2 +- test/lib/commandsTest.js | 12 ++++++------ test/providers/nodebb/chatTests.js | 4 ++-- test/providers/nodebb/notificationTest.js | 2 +- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/commands.js b/lib/commands.js index 255e1708..e4927f54 100644 --- a/lib/commands.js +++ b/lib/commands.js @@ -217,14 +217,14 @@ exports.bindCommands = function bindCommands(forum) { } /** - * Get ChatRoom who posted the command + * Get PrivateMessage who posted the command * * @public * - * @returns {Promise} Resolved to retrieved ChatRoom + * @returns {Promise} Resolved to retrieved PrivateMessage */ - getRoom() { - return this.parent.getRoom(); + getPM() { + return this.parent.getPM(); } /** @@ -422,25 +422,25 @@ exports.bindCommands = function bindCommands(forum) { } /** - * Get the ChatRoom this Commands object referrs to + * Get the PrivateMessage this Commands object referrs to * * @public * * @returns {Promise} Resolves to the retrieved ChatRoom */ - getRoom() { - return this._getItem('room', this.ids.room, forum.Chat); + getPM() { + return this._getItem('pm', this.ids.pm, forum.PrivateMessage); } /** - * Set the ChatRoom this Commands object refers to + * Set the PrivateMessage this Commands object refers to * * @public * - * @param {ChatRoom} room The ChatRoom to cache + * @param {PrivateMessage} pm The pm to cache */ - setRoom(room) { - this._setItem('room', room); + setPM(pm) { + this._setItem('pm', pm); } /** diff --git a/providers/nodebb/chat.js b/providers/nodebb/chat.js index a1fcb9c6..9f467661 100644 --- a/providers/nodebb/chat.js +++ b/providers/nodebb/chat.js @@ -449,7 +449,7 @@ exports.bindChat = function bindChat(forum) { post: -1, topic: -1, user: message.from.id, - room: message.room, + pm: message.room, chat: message.id }; return forum.Commands.get(ids, message.content, (content) => message.reply(content)) diff --git a/providers/nodebb/notification.js b/providers/nodebb/notification.js index 3d7753a8..e0b16088 100644 --- a/providers/nodebb/notification.js +++ b/providers/nodebb/notification.js @@ -380,7 +380,7 @@ exports.bindNotification = function bindNotification(forum) { post: notification.postId, topic: notification.topicId, user: notification.userId, - room: -1, + pm: -1, chat: -1 }; return notification.getText() diff --git a/test/lib/commandsTest.js b/test/lib/commandsTest.js index 2716b712..2cbd1e80 100644 --- a/test/lib/commandsTest.js +++ b/test/lib/commandsTest.js @@ -715,7 +715,7 @@ describe('lib/config', () => { getPost: sinon.stub(), getTopic: sinon.stub(), getUser: sinon.stub(), - getRoom: sinon.stub() + getPM: sinon.stub() }; command = new Command({}, parent); }); @@ -739,9 +739,9 @@ describe('lib/config', () => { }); it('should proxy getRoom() to parent.getRoom()', () => { const expected = Math.random(); - parent.getRoom.returns(expected); - command.getRoom().should.equal(expected); - parent.getRoom.should.have.been.calledOnce; + parent.getPM.returns(expected); + command.getPM().should.equal(expected); + parent.getPM.should.have.been.calledOnce; }); }); describe('reply()', () => { @@ -883,7 +883,7 @@ describe('lib/config', () => { ['getPost', 'Post', 'post'], ['getTopic', 'Topic', 'topic'], ['getUser', 'User', 'user'], - ['getRoom', 'Chat', 'room'] + ['getPM', 'PrivateMessage', 'pm'] ].forEach((config) => { const method = config[0], object = config[1], @@ -932,7 +932,7 @@ describe('lib/config', () => { [ ['setPost', 'post'], ['setTopic', 'topic'], - ['setRoom', 'room'], + ['setPM', 'pm'], ['setUser', 'user'] ].forEach((config) => { const method = config[0], diff --git a/test/providers/nodebb/chatTests.js b/test/providers/nodebb/chatTests.js index 4bfbc76f..706c820b 100644 --- a/test/providers/nodebb/chatTests.js +++ b/test/providers/nodebb/chatTests.js @@ -1068,11 +1068,11 @@ describe('providers/nodebb/chat', () => { message: 1 }).then(() => { const param = forum.Commands.get.firstCall.args[0]; - param.should.have.all.keys('post', 'topic', 'user', 'room', 'chat'); + param.should.have.all.keys('post', 'topic', 'user', 'pm', 'chat'); param.post.should.equal(-1); param.topic.should.equal(-1); param.user.should.equal(userId); - param.room.should.equal(roomId); + param.pm.should.equal(roomId); param.chat.should.equal(chatId); }); }); diff --git a/test/providers/nodebb/notificationTest.js b/test/providers/nodebb/notificationTest.js index 35e15416..76bc861e 100644 --- a/test/providers/nodebb/notificationTest.js +++ b/test/providers/nodebb/notificationTest.js @@ -604,7 +604,7 @@ describe('providers/nodebb/notification', () => { post: post, topic: topic, user: user, - room: -1, + pm: -1, chat: -1 }); args[1].should.eql(text); From 1093c3162cb25bdbcc81b93514df91783cd5b07c Mon Sep 17 00:00:00 2001 From: Yami Date: Tue, 29 Nov 2016 16:14:14 +0000 Subject: [PATCH 4/4] docs: Update API Documentation --- docs/api/lib/commands.md | 34 +++++++++++------------ docs/api/providers/nodebb/notification.md | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/docs/api/lib/commands.md b/docs/api/lib/commands.md index 12b35c0d..961413dd 100644 --- a/docs/api/lib/commands.md +++ b/docs/api/lib/commands.md @@ -29,7 +29,7 @@ NodeBB provider module User class * [.getPost()](#sockbot.lib.module_commands..Command+getPost) ⇒ Promise.<Post> * [.getTopic()](#sockbot.lib.module_commands..Command+getTopic) ⇒ Promise.<Topic> * [.getUser()](#sockbot.lib.module_commands..Command+getUser) ⇒ Promise.<User> - * [.getRoom()](#sockbot.lib.module_commands..Command+getRoom) ⇒ Promise.<ChatRoom> + * [.getPM()](#sockbot.lib.module_commands..Command+getPM) ⇒ Promise.<PrivateMessage> * [.reply(content)](#sockbot.lib.module_commands..Command+reply) * [.appendReply(content)](#sockbot.lib.module_commands..Command+appendReply) * [~Commands](#sockbot.lib.module_commands..Commands) @@ -42,8 +42,8 @@ NodeBB provider module User class * [.setPost(post)](#sockbot.lib.module_commands..Commands+setPost) * [.getTopic()](#sockbot.lib.module_commands..Commands+getTopic) ⇒ Promise.<Topic> * [.setTopic(topic)](#sockbot.lib.module_commands..Commands+setTopic) - * [.getRoom()](#sockbot.lib.module_commands..Commands+getRoom) ⇒ Promise.<ChatRoom> - * [.setRoom(room)](#sockbot.lib.module_commands..Commands+setRoom) + * [.getPM()](#sockbot.lib.module_commands..Commands+getPM) ⇒ Promise.<ChatRoom> + * [.setPM(pm)](#sockbot.lib.module_commands..Commands+setPM) * [.getUser()](#sockbot.lib.module_commands..Commands+getUser) ⇒ Promise.<User> * [.setUser(user)](#sockbot.lib.module_commands..Commands+setUser) * [.execute()](#sockbot.lib.module_commands..Commands+execute) ⇒ Promise.<Commands> @@ -137,7 +137,7 @@ Command Class. Represents a single command within a post * [.getPost()](#sockbot.lib.module_commands..Command+getPost) ⇒ Promise.<Post> * [.getTopic()](#sockbot.lib.module_commands..Command+getTopic) ⇒ Promise.<Topic> * [.getUser()](#sockbot.lib.module_commands..Command+getUser) ⇒ Promise.<User> - * [.getRoom()](#sockbot.lib.module_commands..Command+getRoom) ⇒ Promise.<ChatRoom> + * [.getPM()](#sockbot.lib.module_commands..Command+getPM) ⇒ Promise.<PrivateMessage> * [.reply(content)](#sockbot.lib.module_commands..Command+reply) * [.appendReply(content)](#sockbot.lib.module_commands..Command+appendReply) @@ -240,13 +240,13 @@ Get User who posted the command **Kind**: instance method of [Command](#sockbot.lib.module_commands..Command) **Returns**: Promise.<User> - Resolved to retrieved User **Access:** public - + -#### command.getRoom() ⇒ Promise.<ChatRoom> -Get ChatRoom who posted the command +#### command.getPM() ⇒ Promise.<PrivateMessage> +Get PrivateMessage who posted the command **Kind**: instance method of [Command](#sockbot.lib.module_commands..Command) -**Returns**: Promise.<ChatRoom> - Resolved to retrieved ChatRoom +**Returns**: Promise.<PrivateMessage> - Resolved to retrieved PrivateMessage **Access:** public @@ -290,8 +290,8 @@ Commands class. Represents all commands for a Notification * [.setPost(post)](#sockbot.lib.module_commands..Commands+setPost) * [.getTopic()](#sockbot.lib.module_commands..Commands+getTopic) ⇒ Promise.<Topic> * [.setTopic(topic)](#sockbot.lib.module_commands..Commands+setTopic) - * [.getRoom()](#sockbot.lib.module_commands..Commands+getRoom) ⇒ Promise.<ChatRoom> - * [.setRoom(room)](#sockbot.lib.module_commands..Commands+setRoom) + * [.getPM()](#sockbot.lib.module_commands..Commands+getPM) ⇒ Promise.<ChatRoom> + * [.setPM(pm)](#sockbot.lib.module_commands..Commands+setPM) * [.getUser()](#sockbot.lib.module_commands..Commands+getUser) ⇒ Promise.<User> * [.setUser(user)](#sockbot.lib.module_commands..Commands+setUser) * [.execute()](#sockbot.lib.module_commands..Commands+execute) ⇒ Promise.<Commands> @@ -375,25 +375,25 @@ Set the Topic this Commands object refers to | --- | --- | --- | | topic | Topic | The Topic to cache | - + -#### commands.getRoom() ⇒ Promise.<ChatRoom> -Get the ChatRoom this Commands object referrs to +#### commands.getPM() ⇒ Promise.<ChatRoom> +Get the PrivateMessage this Commands object referrs to **Kind**: instance method of [Commands](#sockbot.lib.module_commands..Commands) **Returns**: Promise.<ChatRoom> - Resolves to the retrieved ChatRoom **Access:** public - + -#### commands.setRoom(room) -Set the ChatRoom this Commands object refers to +#### commands.setPM(pm) +Set the PrivateMessage this Commands object refers to **Kind**: instance method of [Commands](#sockbot.lib.module_commands..Commands) **Access:** public | Param | Type | Description | | --- | --- | --- | -| room | ChatRoom | The ChatRoom to cache | +| pm | PrivateMessage | The pm to cache | diff --git a/docs/api/providers/nodebb/notification.md b/docs/api/providers/nodebb/notification.md index 35da254e..936b2879 100644 --- a/docs/api/providers/nodebb/notification.md +++ b/docs/api/providers/nodebb/notification.md @@ -53,7 +53,7 @@ Create a Notification class and bind it to a forum instance #### bindNotification~notificationType Notification types enum -**Kind**: inner constant of [bindNotification](#sockbot.providers.nodebb.module_Notification.bindNotification) +**Kind**: inner enum of [bindNotification](#sockbot.providers.nodebb.module_Notification.bindNotification) **Read only**: true **Properties**