Skip to content

Commit

Permalink
[NEW] REST API Endpoint to get pinned messages from a room (#13864)
Browse files Browse the repository at this point in the history
  • Loading branch information
thayannevls authored and sampaiodiego committed Aug 20, 2019
1 parent f7ce6ac commit af88653
Show file tree
Hide file tree
Showing 3 changed files with 678 additions and 549 deletions.
31 changes: 31 additions & 0 deletions app/api/server/v1/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,37 @@ API.v1.addRoute('chat.getDeletedMessages', { authRequired: true }, {
},
});

API.v1.addRoute('chat.getPinnedMessages', { authRequired: true }, {
get() {
const { roomId } = this.queryParams;
const { offset, count } = this.getPaginationItems();

if (!roomId) {
throw new Meteor.Error('error-roomId-param-not-provided', 'The required "roomId" query param is missing.');
}
const room = Meteor.call('canAccessRoom', roomId, this.userId);
if (!room) {
throw new Meteor.Error('error-not-allowed', 'Not allowed');
}

const cursor = Messages.findPinnedByRoom(room._id, {
skip: offset,
limit: count,
});

const total = cursor.count();

const messages = cursor.fetch();

return API.v1.success({
messages,
count: messages.length,
offset,
total,
});
},
});

API.v1.addRoute('chat.getThreadsList', { authRequired: true }, {
get() {
const { rid } = this.queryParams;
Expand Down
12 changes: 12 additions & 0 deletions tests/data/chat.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ export const sendSimpleMessage = ({ roomId, text = 'test message', tmid }) => {
.send({ message });
};

export const pinMessage = ({ msgId }) => {
if (!msgId) {
throw new Error('"msgId" is required in "pinMessage" test helper');
}

return request.post(api('chat.pinMessage'))
.set(credentials)
.send({
messageId: msgId,
});
};

export const deleteMessage = ({ roomId, msgId }) => {
if (!roomId) {
throw new Error('"roomId" is required in "deleteMessage" test helper');
Expand Down
Loading

0 comments on commit af88653

Please sign in to comment.