Skip to content
Snippets Groups Projects
Unverified Commit e76d6e36 authored by Bradley Hilton's avatar Bradley Hilton
Browse files

Add an api method for getting a single message by id, #6783

parent caeea792
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,28 @@ RocketChat.API.v1.addRoute('chat.delete', { authRequired: true }, {
}
});
RocketChat.API.v1.addRoute('chat.getMessage', { authRequired: true }, {
get() {
if (!this.queryParams.msgId) {
return RocketChat.API.v1.failure('The "msgId" query parameter must be provided.');
}
let msg;
Meteor.runAsUser(this.userId, () => {
msg = Meteor.call('getSingleMessage', this.queryParams.msgId);
});
if (!msg) {
return RocketChat.API.v1.failure();
}
return RocketChat.API.v1.success({
message: msg
});
}
});
RocketChat.API.v1.addRoute('chat.postMessage', { authRequired: true }, {
post() {
const messageReturn = processWebhookMessage(this.bodyParams, this.user)[0];
......
......@@ -143,6 +143,7 @@ Package.onUse(function(api) {
api.addFiles('server/methods/getFullUserData.js', 'server');
api.addFiles('server/methods/getRoomRoles.js', 'server');
api.addFiles('server/methods/getServerInfo.js', 'server');
api.addFiles('server/methods/getSingleMessage.js', 'server');
api.addFiles('server/methods/getUserRoles.js', 'server');
api.addFiles('server/methods/insertOrUpdateUser.js', 'server');
api.addFiles('server/methods/joinDefaultChannels.js', 'server');
......
Meteor.methods({
getSingleMessage(msgId) {
check(msgId, String);
if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'getSingleMessage' });
}
const msg = RocketChat.models.Messages.findOneById(msgId);
if (!msg && !msg.rid) {
return undefined;
}
Meteor.call('canAccessRoom', msg.rid, Meteor.userId());
return msg;
}
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment