Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Send a message when muted returns inconsistent result in chat.sendMessage #10720

Merged
merged 3 commits into from
May 11, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/rocketchat-api/server/v1/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ RocketChat.API.v1.addRoute('chat.sendMessage', { authRequired: true }, {
}

let message;
Meteor.runAsUser(this.userId, () => message = Meteor.call('sendMessage', this.bodyParams.message));
Meteor.runAsUser(this.userId, () => message = Meteor.call('sendMessage', this.bodyParams.message, 'RESTAPI'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not need to be adding origins and where things are coming from. Let's just always throw an error and if the web client needs to change to handle it, then we will need to change it.


return RocketChat.API.v1.success({
message
Expand Down
8 changes: 7 additions & 1 deletion packages/rocketchat-lib/server/methods/sendMessage.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import moment from 'moment';

Meteor.methods({
sendMessage(message) {
sendMessage(message, origin) {
check(message, Object);

if (!Meteor.userId()) {
Expand Down Expand Up @@ -55,6 +55,9 @@ Meteor.methods({
ts: new Date,
msg: TAPi18n.__('room_is_blocked', {}, user.language)
});
if (origin && origin === 'RESTAPI') {
throw new Meteor.Error('You can\'t send messages because you are blocked');
}
return false;
}

Expand All @@ -65,6 +68,9 @@ Meteor.methods({
ts: new Date,
msg: TAPi18n.__('You_have_been_muted', {}, user.language)
});
if (origin && origin === 'RESTAPI') {
throw new Meteor.Error('You can\'t send messages because you have been muted');
}
return false;
}

Expand Down