Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 18 additions & 0 deletions packages/rocketchat-api/server/v1/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,24 @@ RocketChat.API.v1.addRoute('channels.setTopic', { authRequired: true }, {
}
});

RocketChat.API.v1.addRoute('channels.setAnnouncement', { authRequired: true }, {
post() {
if (!this.bodyParams.announcement || !this.bodyParams.announcement.trim()) {
return RocketChat.API.v1.failure('The bodyParam "announcement" is required');
}

const findResult = findChannelByIdOrName({ params: this.requestParams() });

Meteor.runAsUser(this.userId, () => {
Meteor.call('saveRoomSettings', findResult._id, 'roomAnnouncement', this.bodyParams.announcement);
});

return RocketChat.API.v1.success({
announcement: this.bodyParams.announcement
});
}
});

RocketChat.API.v1.addRoute('channels.setType', { authRequired: true }, {
post() {
if (!this.bodyParams.type || !this.bodyParams.type.trim()) {
Expand Down
16 changes: 16 additions & 0 deletions tests/end-to-end/api/02-channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,22 @@ describe('[Channels]', function() {
.end(done);
});

it('/channels.setAnnouncement', (done) => {
request.post(api('channels.setAnnouncement'))
.set(credentials)
.send({
roomId: channel._id,
announcement: 'this is an announcement of a channel for api tests'
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.nested.property('announcement', 'this is an announcement of a channel for api tests');
})
.end(done);
});

it('/channels.setPurpose', (done) => {
request.post(api('channels.setPurpose'))
.set(credentials)
Expand Down