UNPKG

trender-client

Version:
69 lines (68 loc) 2.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const RequestEmitter_1 = tslib_1.__importDefault(require("../utils/RequestEmitter")); class MessageManager extends RequestEmitter_1.default { constructor(params) { super(params); } create(channel_id, params) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const request = yield this.postRequest(`/messages/${channel_id}`, { attachments: params === null || params === void 0 ? void 0 : params.attachments, content: params.content }); const response = request; return response; }); } fetch(channel_id, params) { return tslib_1.__awaiter(this, void 0, void 0, function* () { let _url = `/messages/${channel_id}`; const parameters = []; if (params === null || params === void 0 ? void 0 : params.skip) parameters.push(`skip=${params.skip.toString()}`); if (params === null || params === void 0 ? void 0 : params.limit) parameters.push(`limit=${params.limit.toString()}`); if (params === null || params === void 0 ? void 0 : params.pagination_key) parameters.push(`pagination_key=${params.pagination_key}`); if (parameters.length > 0) _url = _url.concat("?"); const request = yield this.getRequest(_url.concat(parameters.join("&"))); const response = request; return response; }); } unreads() { return tslib_1.__awaiter(this, void 0, void 0, function* () { const request = yield this.getRequest(`/messages/unreads`); const response = request; return response; }); } read(channel_id, message_id) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const request = yield this.postRequest(`/messages/${channel_id}/${message_id}`); const response = request; return response; }); } delete(channel_id, message_id) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const request = yield this.deleteRequest(`/messages/${channel_id}/${message_id}`); const response = request; return response; }); } report(target_id, reason, description) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const request = yield this.postRequest(`/messages/${target_id}/reports`, { reason: reason, description: description }); const response = request; return response; }); } } exports.default = MessageManager;