Skip to content

Commit

Permalink
refactor(Chat): Renamed the concept of a Chat to a PM in outward-faci…
Browse files Browse the repository at this point in the history
…ng 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
  • Loading branch information
yamikuronue committed Nov 29, 2016
1 parent 3178b14 commit 9261660
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
22 changes: 11 additions & 11 deletions lib/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,14 @@ exports.bindCommands = function bindCommands(forum) {
}

/**
* Get ChatRoom who posted the command
* Get PrivateMessage who posted the command
*
* @public
*
* @returns {Promise<ChatRoom>} Resolved to retrieved ChatRoom
* @returns {Promise<PrivateMessage>} Resolved to retrieved PrivateMessage
*/
getRoom() {
return this.parent.getRoom();
getPM() {
return this.parent.getPM();
}

/**
Expand Down Expand Up @@ -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<ChatRoom>} 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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion providers/nodebb/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion providers/nodebb/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 6 additions & 6 deletions test/lib/commandsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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()', () => {
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -932,7 +932,7 @@ describe('lib/config', () => {
[
['setPost', 'post'],
['setTopic', 'topic'],
['setRoom', 'room'],
['setPM', 'pm'],
['setUser', 'user']
].forEach((config) => {
const method = config[0],
Expand Down
4 changes: 2 additions & 2 deletions test/providers/nodebb/chatTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/providers/nodebb/notificationTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9261660

Please sign in to comment.