Skip to content
Closed
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ zulip.callEndpoint('/messages', 'POST', params);
| `zulip.messages.flags.add()` | POST `/messages/flags` | add a flag to a list of messages. Its params are `flag` which is one of `[read, starred, mentioned, wildcard_mentioned, has_alert_word, historical]` and `messages` which is a list of messageIDs. |
| `zulip.messages.flags.remove()` | POST `/messages/flags` | remove a flag from a list of messages. Its params are `flag` which is one of `[read, starred, mentioned, wildcard_mentioned, has_alert_word, historical]` and `messages` which is a list of messageIDs. |
| `zulip.messages.getById()` | GET `/messages/<msg_id>` | returns a message by its id. |
| `zulip.messages.deleteById()` | DELETE `/messages/<msg_id>` | delete the message with the provided message id if the user has permission to do so. |
| `zulip.queues.register()` | POST `/register` | registers a new queue. You can pass it a params object with the types of events you are interested in and whether you want to receive raw text or html (using markdown). |
| `zulip.queues.deregister()` | DELETE `/events` | deletes a previously registered queue. |
| `zulip.reactions.add()` | POST `/reactions` | add a reaction to a message. Accepts a params object with `message_id`, `emoji_name`, `emoji_code` and `reaction_type` (default is `unicode_emoji`). |
Expand Down
7 changes: 7 additions & 0 deletions examples/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,10 @@ zulip(config).then((z) => {
};
z.messages.getById(readParams).then(console.log);
}).catch(err => console.log(err.message));

zulip(config).then((z) => {
const readParams = {
message_id: 1,
};
z.messages.deleteById(readParams).then(console.log);
}).catch(err => console.log(err.message));
4 changes: 4 additions & 0 deletions src/resources/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ function messages(config) {
const url = `${config.apiURL}/messages/${params.message_id}`;
return api(url, config, 'GET', params);
},
deleteById: (params) => {
const url = `${config.apiURL}/messages/${params.message_id}`;
return api(url, config, 'DELETE', params);
},
};
}

Expand Down
22 changes: 22 additions & 0 deletions test/resources/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,26 @@ describe('Messages', () => {
done();
}).catch(done);
});

it('should delete message by message id', (done) => {
const params = {
message_id: 1,
};
const validator = (url, options) => {
url.should.contain(`${common.config.apiURL}/messages/1`);
options.should.not.have.property('body');
options.method.should.be.equal('DELETE');
};
const output = {
msg: '',
result: 'success',
};
const stubs = common.getStubs(validator, output);
messages(common.config).deleteById(params)
.then((data) => {
data.should.have.property('result', 'success');
common.restoreStubs(stubs);
done();
}).catch(done);
});
});