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

add endpoint for GET message by id. #64

Merged
merged 1 commit into from
Aug 21, 2018
Merged
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
@@ -93,6 +93,7 @@ zulip.callEndpoint('/messages', 'POST', params);
| `zulip.messages.update()` | PATCH `/messages/<msg_id>` | updates the content or topic of the message with the given `msg_id`. |
| `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.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`). |
7 changes: 7 additions & 0 deletions examples/messages.js
Original file line number Diff line number Diff line change
@@ -59,3 +59,10 @@ zulip(config).then((z) => {
});
}).then(res => console.log(res.messages));
}).catch(err => console.log(err.message));

zulip(config).then((z) => {
const readParams = {
message_id: 1,
};
z.messages.getById(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
@@ -52,6 +52,10 @@ function messages(config) {
return api(flagsURL, config, 'POST', params);
},
},
getById: (params) => {
const url = `${config.apiURL}/messages/${params.message_id}`;
return api(url, config, 'GET', params);
},
};
}

22 changes: 22 additions & 0 deletions test/resources/messages.js
Original file line number Diff line number Diff line change
@@ -121,6 +121,28 @@ describe('Messages', () => {
}).catch(done);
});

it('should get message by 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('GET');
};
const output = {
msg: '',
result: 'success',
};
const stubs = common.getStubs(validator, output);
messages(common.config).getById(params)
.then((data) => {
data.should.have.property('result', 'success');
common.restoreStubs(stubs);
done();
}).catch(done);
});

it('should mark message as read', (done) => {
const params = {
flag: 'read',