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

[NEW] Rest API Endpoint to get pinned messages from a room #13864

Merged
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