Skip to content

Commit cd72243

Browse files
Anupam-dagaraero31aero
authored andcommitted
api: Add support for GET /messages/<msgid>/history.
1 parent 901466d commit cd72243

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ zulip.callEndpoint('/messages', 'POST', params);
9494
| `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. |
9595
| `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. |
9696
| `zulip.messages.getById()` | GET `/messages/<msg_id>` | returns a message by its id. |
97+
| `zulip.messages.getHistoryById()` | GET `/messages/<msg_id>/history` | return the history of a message |
9798
| `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). |
9899
| `zulip.queues.deregister()` | DELETE `/events` | deletes a previously registered queue. |
99100
| `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`). |

examples/messages.js

+7
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,10 @@ zulip(config).then((z) => {
6666
};
6767
z.messages.getById(readParams).then(console.log);
6868
}).catch(err => console.log(err.message));
69+
70+
zulip(config).then((z) => {
71+
const readParams = {
72+
message_id: 2,
73+
};
74+
z.messages.getHistoryById(readParams).then(console.log);
75+
}).catch(err => console.log(err.message));

src/resources/messages.js

+4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ function messages(config) {
5656
const url = `${config.apiURL}/messages/${params.message_id}`;
5757
return api(url, config, 'GET', params);
5858
},
59+
getHistoryById: (params) => {
60+
const url = `${config.apiURL}/messages/${params.message_id}/history`;
61+
return api(url, config, 'GET', params);
62+
},
5963
};
6064
}
6165

test/resources/messages.js

+22
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,28 @@ describe('Messages', () => {
143143
}).catch(done);
144144
});
145145

146+
it('should get message history by id', (done) => {
147+
const params = {
148+
message_id: 2,
149+
};
150+
const validator = (url, options) => {
151+
url.should.contain(`${common.config.apiURL}/messages/2/history`);
152+
options.should.not.have.property('body');
153+
options.method.should.be.equal('GET');
154+
};
155+
const output = {
156+
msg: '',
157+
result: 'success',
158+
};
159+
const stubs = common.getStubs(validator, output);
160+
messages(common.config).getHistoryById(params)
161+
.then((data) => {
162+
data.should.have.property('result', 'success');
163+
common.restoreStubs(stubs);
164+
done();
165+
}).catch(done);
166+
});
167+
146168
it('should mark message as read', (done) => {
147169
const params = {
148170
flag: 'read',

0 commit comments

Comments
 (0)