UNPKG

@stackend/api

Version:

JS bindings to api.stackend.com

163 lines 6.76 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.setCommentUserApprovalStatus = exports.postComment = exports.getMultipleComments = exports.getComments = exports.getComment = exports.CommentModule = exports.CommentSortCriteria = exports.COMPONENT_NAME = exports.COMPONENT_CLASS = exports.COMMENT_CLASS = void 0; // @flow var api_1 = require("../api"); var SortOrder_1 = __importDefault(require("../api/SortOrder")); /** * Comment class name */ exports.COMMENT_CLASS = 'se.josh.xcap.comment.impl.CommentImpl'; /** * Comment manager component class name */ exports.COMPONENT_CLASS = 'se.josh.xcap.comment.CommentManager'; /** * Component name */ exports.COMPONENT_NAME = 'comment'; /** * Sort criteria */ var CommentSortCriteria; (function (CommentSortCriteria) { /** * Sort by creation date. */ CommentSortCriteria["CREATED"] = "CREATED"; /** * Sort after creation date, but preserving replies. The commenting system * supports one level of replies. */ CommentSortCriteria["CREATED_WITH_REPLIES"] = "CREATED_WITH_REPLIES"; })(CommentSortCriteria = exports.CommentSortCriteria || (exports.CommentSortCriteria = {})); /** * Is this comments instance tied to another function, or free standing? */ var CommentModule; (function (CommentModule) { /** * Free standing comments */ CommentModule["GENERIC"] = ""; /** * Comments on blog entries */ CommentModule["BLOG"] = "blog"; /** * Comments on forum entries */ CommentModule["FORUM"] = "forum"; /** * Personal shopper (personal) comments */ CommentModule["PERSONAL_SHOPPER"] = "personal-shopper"; })(CommentModule = exports.CommentModule || (exports.CommentModule = {})); /** * Get a single comment * @param id * @param module * @param referenceId * @param useVotes */ function getComment(_a) { var id = _a.id, _b = _a.module, module = _b === void 0 ? CommentModule.GENERIC : _b, _c = _a.useVotes, useVotes = _c === void 0 ? false : _c; return (0, api_1.getJson)({ url: (module !== CommentModule.GENERIC ? '/' + module : '') + '/comments/get', parameters: arguments }); } exports.getComment = getComment; /** * Get comments for a reference id. * * @param module {CommentModule} optional module: "blog" to get blog comments * @param referenceId Reference id (required) * @param sortCriteria {CommentSortCriteria} (optional) * @param order {SortOrder} (optional) * @param p Page number (optional) * @param pageSize Page size (optional) * @param useVotes Fetch votes (optional) */ function getComments(_a) { var _b = _a.module, module = _b === void 0 ? CommentModule.GENERIC : _b, referenceId = _a.referenceId, _c = _a.p, p = _c === void 0 ? null : _c, _d = _a.pageSize, pageSize = _d === void 0 ? null : _d, _e = _a.sortCriteria, sortCriteria = _e === void 0 ? CommentSortCriteria.CREATED_WITH_REPLIES : _e, _f = _a.order, order = _f === void 0 ? SortOrder_1.default.DESCENDING : _f, _g = _a.useVotes, useVotes = _g === void 0 ? false : _g; if (isNaN(referenceId)) { throw Error('Parameter referenceId is required'); } return (0, api_1.getJson)({ url: (module !== CommentModule.GENERIC ? '/' + module : '') + '/comments/list', parameters: arguments }); } exports.getComments = getComments; /** * Get multiple comments given an array of reference ids. * * Pagination is not supported since we deal with multiple collections. * However, the page size can be set and applies to all collections. * * The result is returned as a map from reference Ids to PaginatedCollection of comments. * * Pagination for the separate comment lists can be implemented using {@link getComments}. * * @param module {CommentModule} optional module: "blog" to get blog comments * @param referenceIds {Array} of referenceIds * @param sortCriteria * @param order * @param p * @param pageSize */ function getMultipleComments(_a) { var _b = _a.module, module = _b === void 0 ? CommentModule.GENERIC : _b, referenceIds = _a.referenceIds, _c = _a.p, p = _c === void 0 ? null : _c, _d = _a.pageSize, pageSize = _d === void 0 ? null : _d, _e = _a.sortCriteria, sortCriteria = _e === void 0 ? CommentSortCriteria.CREATED_WITH_REPLIES : _e, _f = _a.order, order = _f === void 0 ? SortOrder_1.default.DESCENDING : _f; if (!Array.isArray(referenceIds)) { throw Error('Parameter referenceIds is required'); } return (0, api_1.getJson)({ url: (module !== CommentModule.GENERIC ? '/' + module : '') + '/comments/list-multiple', parameters: arguments }); } exports.getMultipleComments = getMultipleComments; /** * Post a comment. * @param commentId {number} Comment id, available on edit.. (Optional) * @param module {CommentModule} optional module: "blog" to get blog comments * @param referenceId {number} Reference id * @param referenceGroupId Optional reference group id * @param parentId Id of parent comment, if reply (Optional) * @param subject * @param body Body HTML. Up to 64KB. * @param extraInformation Application specific text. * @param referenceUrl Reference url */ function postComment(_a) { var commentId = _a.commentId, referenceId = _a.referenceId, _b = _a.referenceGroupId, referenceGroupId = _b === void 0 ? 0 : _b, _c = _a.module, module = _c === void 0 ? CommentModule.GENERIC : _c, _d = _a.parentId, parentId = _d === void 0 ? 0 : _d, subject = _a.subject, body = _a.body, extraInformation = _a.extraInformation, referenceUrl = _a.referenceUrl, createdDate = _a.createdDate; // Add referenceUrl, if not set if (!referenceUrl && (0, api_1.isRunningInBrowser)()) { arguments[0].referenceUrl = window.location.href; } return (0, api_1.post)({ url: (module !== CommentModule.GENERIC ? '/' + module : '') + '/comments/post', parameters: arguments }); } exports.postComment = postComment; /** * Set user approval status of a comment * @param id * @param status * @param commentModule * @param moduleId, optional module id for checking elevated privileges */ function setCommentUserApprovalStatus(_a) { var id = _a.id, status = _a.status, _b = _a.commentModule, commentModule = _b === void 0 ? CommentModule.GENERIC : _b, moduleId = _a.moduleId; return (0, api_1.post)({ url: (commentModule !== CommentModule.GENERIC ? '/' + commentModule : '') + '/comments/moderate', parameters: arguments }); } exports.setCommentUserApprovalStatus = setCommentUserApprovalStatus; //# sourceMappingURL=index.js.map