added endpoint to retrieve message read receipts

pull/9907/head
Marcos Defendi 7 years ago
parent 273cdbc0ee
commit c2757f617a
  1. 8
      imports/message-read-receipt/server/api/methods/getReadReceipts.js
  2. 25
      packages/rocketchat-api/server/v1/chat.js
  3. 44
      tests/end-to-end/api/05-chat.js

@ -8,8 +8,16 @@ Meteor.methods({
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'getReadReceipts' });
}
if (!messageId) {
throw new Meteor.Error('error-invalid-message', 'The required \'messageId\' param is missing.', { method: 'getReadReceipts' });
}
const message = RocketChat.models.Messages.findOneById(messageId);
if (!message) {
throw new Meteor.Error('error-invalid-message', 'Invalid message', { method: 'getReadReceipts' });
}
const room = Meteor.call('canAccessRoom', message.rid, Meteor.userId());
if (!room) {
throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'getReadReceipts' });

@ -7,7 +7,7 @@ RocketChat.API.v1.addRoute('chat.delete', { authRequired: true }, {
asUser: Match.Maybe(Boolean)
}));
const msg = RocketChat.models.Messages.findOneById(this.bodyParams.msgId, { fields: { u: 1, rid: 1 }});
const msg = RocketChat.models.Messages.findOneById(this.bodyParams.msgId, { fields: { u: 1, rid: 1 } });
if (!msg) {
return RocketChat.API.v1.failure(`No message found with the id of "${ this.bodyParams.msgId }".`);
@ -247,7 +247,6 @@ RocketChat.API.v1.addRoute('chat.update', { authRequired: true }, {
//Permission checks are already done in the updateMessage method, so no need to duplicate them
Meteor.runAsUser(this.userId, () => {
Meteor.call('updateMessage', { _id: msg._id, msg: this.bodyParams.text, rid: msg.rid });
});
return RocketChat.API.v1.success({
@ -275,3 +274,25 @@ RocketChat.API.v1.addRoute('chat.react', { authRequired: true }, {
return RocketChat.API.v1.success();
}
});
RocketChat.API.v1.addRoute('chat.getMessageReadReceipts', { authRequired: true }, {
get() {
const { messageId } = this.queryParams;
if (!messageId) {
return RocketChat.API.v1.failure({
error: 'The required \'messageId\' param is missing.'
});
}
try {
const messageReadReceipts = Meteor.runAsUser(this.userId, () => Meteor.call('getReadReceipts', { messageId }));
return RocketChat.API.v1.success({
receipts: messageReadReceipts
});
} catch (error) {
return RocketChat.API.v1.failure({
error: error.message
});
}
}
});

@ -2,8 +2,17 @@
/* globals expect */
/* eslint no-unused-vars: 0 */
import {getCredentials, api, login, request, credentials, message, log, apiPrivateChannelName } from '../../data/api-data.js';
import {adminEmail, password} from '../../data/user.js';
import {
getCredentials,
api,
login,
request,
credentials,
message,
log,
apiPrivateChannelName
} from '../../data/api-data.js';
import { adminEmail, password } from '../../data/user.js';
import supertest from 'supertest';
describe('[Chat]', function() {
@ -183,4 +192,35 @@ describe('[Chat]', function() {
})
.end(done);
});
describe('[/chat.getMessageReadReceipts]', () => {
describe('when execute successfully', () => {
it('should return the statusCode 200 and \'receipts\' property and should be equal an array', (done) => {
request.get(api(`chat.getMessageReadReceipts?messageId=${ message._id }`))
.set(credentials)
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('receipts').and.to.be.an('array');
expect(res.body).to.have.property('success', true);
})
.end(done);
});
});
describe('when an error occurs', () => {
it('should return statusCode 400 and an error', (done) => {
request.get(api('chat.getMessageReadReceipts'))
.set(credentials)
.expect('Content-Type', 'application/json')
.expect(400)
.expect((res) => {
expect(res.body).not.have.property('receipts');
expect(res.body).to.have.property('success', false);
expect(res.body).to.have.property('error');
})
.end(done);
});
});
});
});

Loading…
Cancel
Save