@stackend/api
Version:
JS bindings to api.stackend.com
428 lines • 16.3 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getThreadFromRedux = exports.getThreadEntryFromRedux = exports.getVoteSummary = exports.vote = exports.removeThreadCategories = exports.addThreadCategories = exports.listMostActiveForums = exports.listMostViewedThreds = exports.listMostActiveThreds = exports.listLastCreatedThreads = exports.listLastActiveThreads = exports.moveForumEntry = exports.pinForumEntry = exports.moveForumThread = exports.removeForumThreadEntry = exports.closeForumThread = exports.pinForumThread = exports.setThreadWatch = exports.listWatchedThreads = exports.listEntries = exports.listThreads = exports.listForums = exports.editForumThread = exports.getCreateThreadUrl = exports.QNA_FORUM_PERMALINK = exports.getForumUrl = exports.COMPONENT_CLASS = exports.FORUM_THREAD_ENTRY_CLASS = exports.FORUM_THREAD_CLASS = exports.FORUM_CLASS = exports.COMPONENT_NAME = exports.AnonymityLevel = void 0;
// @flow
var get_1 = __importDefault(require("lodash/get"));
var api_1 = require("../api");
/**
* Xcap Forum API constants and methods.
*
* @since 22 jun 2017
*/
var AnonymityLevel;
(function (AnonymityLevel) {
/**
* No anonymity
*/
AnonymityLevel["NOT_ANONYMOUS"] = "NOT_ANONYMOUS";
/**
* Anonymity from other users only.
* Admins may still reveal the user id
*/
AnonymityLevel["TRACEABLE_ANONYMITY"] = "TRACEABLE_ANONYMITY";
/**
* Completely anonymous
*/
AnonymityLevel["ANONYMOUS"] = "ANONYMOUS";
})(AnonymityLevel = exports.AnonymityLevel || (exports.AnonymityLevel = {}));
/**
* Forum Context
* @type {string}
*/
var CONTEXT = 'forum';
/**
* Forum Component name
* @type {string}
*/
exports.COMPONENT_NAME = 'forum';
exports.FORUM_CLASS = 'net.josh.community.forum.impl.ForumImpl';
exports.FORUM_THREAD_CLASS = 'net.josh.community.forum.impl.ForumThreadImpl';
exports.FORUM_THREAD_ENTRY_CLASS = 'net.josh.community.forum.impl.ForumThreadEntryImpl';
/**
* Component class (used to look up privileges, etc)
*/
exports.COMPONENT_CLASS = 'net.josh.community.forum.ForumManager';
/**
* Get the url to a forum or forum thread
* @param request
* @param forumPermalink
* @param threadPermalink
* @param absolute
* @param community
* @return {string}
* @deprecated Implement in frontend code
*/
function getForumUrl(_a) {
//TODO: Set support for castle orange, set Forum for Black
/* FIXME: bad merge?
if(!!community){
return xcapApi.getServerWithContextPath() + '/'+community + (!!forumPermalink ? '/' + forumPermalink : '') + (!!threadPermalink ? '/' + threadPermalink : '');
}
*/
var request = _a.request, forumPermalink = _a.forumPermalink, threadPermalink = _a.threadPermalink, community = _a.community, absolute = _a.absolute;
if (!!forumPermalink && exports.QNA_FORUM_PERMALINK === forumPermalink) {
return (0, api_1.createCommunityUrl)({
request: request,
path: '/support' + (forumPermalink ? '/' + forumPermalink : '') + (threadPermalink ? '/' + threadPermalink : ''),
absolute: absolute
});
}
else {
return (0, api_1.createCommunityUrl)({
request: request,
path: '/forum' + (forumPermalink ? '/' + forumPermalink : '') + (threadPermalink ? '/' + threadPermalink : ''),
absolute: absolute
});
}
}
exports.getForumUrl = getForumUrl;
// export const COMPONENT_NAME = 'forum';
/**
* Permalink for the QNA forum
*/
exports.QNA_FORUM_PERMALINK = 'question';
/**
* returns the url to Ask a question in the Qnas.
* @deprecated Implement in frontend code instead
*/
function getCreateThreadUrl(_a) {
var request = _a.request, _b = _a.forumPermalink, forumPermalink = _b === void 0 ? '' : _b;
return (0, api_1.createCommunityUrl)({
request: request,
path: "/forum".concat(forumPermalink ? "/".concat(forumPermalink) : '', "/create-a-thread")
});
}
exports.getCreateThreadUrl = getCreateThreadUrl;
/**
* Create a sorum thread
* @param subject
* @param text
* @param categoryId
* @param entryId
* @param forumThreadPermalink
* @param forumPermalink
*/
function editForumThread(_a) {
var subject = _a.subject, text = _a.text, _b = _a.categoryId, categoryId = _b === void 0 ? [] : _b, forumThreadPermalink = _a.forumThreadPermalink, forumPermalink = _a.forumPermalink, isAI = _a.isAI;
if (isAI) {
return (0, api_1.post)({ url: '/forum/edit-forum-thread-ai', parameters: arguments });
}
else {
return (0, api_1.post)({ url: '/forum/edit-forum-thread', parameters: arguments });
}
}
exports.editForumThread = editForumThread;
/**
* List forums
*
* @param p Page number (optional)
* @param pageSize Page size (optional)
* @returns {Promise}
*/
function listForums(_a) {
var p = _a.p, pageSize = _a.pageSize;
return (0, api_1.getJson)({ url: '/forum/list', parameters: arguments });
}
exports.listForums = listForums;
/**
* List threads of a forum.
*
* @param forumPermalink permalink of forum
* @param p Page number (optional)
* @param pageSize Page size (optional)
* @returns {Promise}
*/
function listThreads(_a) {
var forumPermalink = _a.forumPermalink, p = _a.p, pageSize = _a.pageSize;
return (0, api_1.getJson)({ url: '/forum/threads/list', parameters: arguments });
}
exports.listThreads = listThreads;
/**
* List entries of a thread.
*
* @param forumPermalink permalink of forum
* @param forumThreadPermalink permalink of forum thread
* @param entryId {number} Jump to the page of this entry (optional)
* @param p Page number (optional)
* @param pageSize Page size (optional)
* @param isQna
*/
function listEntries(_a) {
var forumPermalink = _a.forumPermalink, forumThreadPermalink = _a.forumThreadPermalink, entryId = _a.entryId, p = _a.p, pageSize = _a.pageSize, isQna = _a.isQna;
return (0, api_1.getJson)({
url: '/forum/entries/list',
parameters: arguments,
context: CONTEXT,
componentName: exports.COMPONENT_NAME
});
}
exports.listEntries = listEntries;
/**
* List threads the user is watching.
* @param watchesHavingNewEntriesOnly {boolean} Set to true to only list threads with new entries.
*/
function listWatchedThreads(_a) {
var watchesHavingNewEntriesOnly = _a.watchesHavingNewEntriesOnly;
return (0, api_1.getJson)({ url: '/forum/threads/list/watched', parameters: arguments });
}
exports.listWatchedThreads = listWatchedThreads;
/**
* Watch/unwatch a thread for new activity.
*
* @param threadId {number} Thread id.
* @param watch {boolean} If set to true, the thread is watched, if false, the watch is removed
*/
function setThreadWatch(_a) {
var threadId = _a.threadId, _b = _a.watch, watch = _b === void 0 ? true : _b;
return (0, api_1.getJson)({ url: '/forum/thread/watch', parameters: arguments });
}
exports.setThreadWatch = setThreadWatch;
/**
* Pin a forum thread to the top of the listing.
* Works as a toggle.
* Requires admin access.
* @param threadId {number} Thread id.
*/
function pinForumThread(_a) {
var threadId = _a.threadId;
return (0, api_1.post)({ url: '/forum/thread/pin', parameters: arguments });
}
exports.pinForumThread = pinForumThread;
/**
* Close a forum thread.
* Requires admin access.
* @param threadId {number} Thread id.
*/
function closeForumThread(_a) {
var threadId = _a.threadId;
return (0, api_1.post)({ url: '/forum/thread/close', parameters: arguments });
}
exports.closeForumThread = closeForumThread;
/**
* Remove a forum thread entry using moderation.
* Requires admin access or that user is owner of entry.
* @param v {number} Forum thread entry id.
*/
function removeForumThreadEntry(_a) {
var entryId = _a.entryId;
return (0, api_1.post)({ url: '/forum/thread/remove', parameters: arguments });
}
exports.removeForumThreadEntry = removeForumThreadEntry;
/**
* Move a forum thread to a different forum.
* Requires admin access.
* @param threadId {number} Thread id.
* @param forumId {number} New forum id
*/
function moveForumThread(_a) {
var threadId = _a.threadId, forumId = _a.forumId;
return (0, api_1.post)({ url: '/forum/thread/move', parameters: arguments });
}
exports.moveForumThread = moveForumThread;
/**
* Pin a forum entry to the top of the listing.
* Works as a toggle.
* Requires admin access.
* @param entryId {number} Entry id.
*/
function pinForumEntry(_a) {
var entryId = _a.entryId;
return (0, api_1.post)({ url: '/forum/thread/pin', parameters: arguments });
}
exports.pinForumEntry = pinForumEntry;
/**
* Move an entry to a different thread.
* Requires admin access.
* @param entryId {number} Entry id.
* @param threadId {number} New thread id
* @param includeReplies {boolean} Should replies also be moved?
*/
function moveForumEntry(_a) {
var entryId = _a.entryId, threadId = _a.threadId, _b = _a.includeReplies, includeReplies = _b === void 0 ? true : _b;
return (0, api_1.post)({ url: '/forum/entry/move', parameters: arguments });
}
exports.moveForumEntry = moveForumEntry;
/**
* List the last active threads.
*
* @param categoryIds {number[]} Category ids (optional)
* @param categoryPermalinks {string[]} Category permalinks (optional)
* @param p Page number (optional)
* @param pageSize Page size (optional)
*/
function listLastActiveThreads(_a) {
var categoryIds = _a.categoryIds, categoryPermalinks = _a.categoryPermalinks, _b = _a.p, p = _b === void 0 ? 1 : _b, pageSize = _a.pageSize;
return (0, api_1.getJson)({ url: '/forum/threads/list/last-active', parameters: arguments });
}
exports.listLastActiveThreads = listLastActiveThreads;
/**
* List the last created threads.
*
* @param categoryIds {number[]} Category ids (optional)
* @param categoryPermalinks {string[]} Category permalinks (optional)
* @param p Page number (optional)
* @param pageSize Page size (optional)
*/
function listLastCreatedThreads(_a) {
var categoryIds = _a.categoryIds, categoryPermalinks = _a.categoryPermalinks, _b = _a.p, p = _b === void 0 ? 1 : _b, pageSize = _a.pageSize;
return (0, api_1.getJson)({ url: '/forum/threads/list/last-created', parameters: arguments });
}
exports.listLastCreatedThreads = listLastCreatedThreads;
/**
* List the most active threads.
*
* @param daysBack {number} Number of days back. (optional)
* @param categoryIds {number[]} Category ids (optional)
* @param categoryPermalinks {string[]} Category permalinks (optional)
* @param p Page number (optional)
* @param pageSize Page size (optional)
*/
function listMostActiveThreds(_a) {
var daysBack = _a.daysBack, categoryIds = _a.categoryIds, categoryPermalinks = _a.categoryPermalinks, _b = _a.p, p = _b === void 0 ? 1 : _b, pageSize = _a.pageSize;
return (0, api_1.getJson)({ url: '/forum/threads/list/most-active', parameters: arguments });
}
exports.listMostActiveThreds = listMostActiveThreds;
/**
* List the most viewed threads.
*
* @param daysBack {number} Number of days back. (optional)
* @param categoryIds {number[]} Category ids (optional)
* @param categoryPermalinks {string[]} Category permalinks (optional)
* @param p Page number (optional)
* @param pageSize Page size (optional)
*/
function listMostViewedThreds(_a) {
var daysBack = _a.daysBack, categoryIds = _a.categoryIds, categoryPermalinks = _a.categoryPermalinks, _b = _a.p, p = _b === void 0 ? 1 : _b, pageSize = _a.pageSize;
return (0, api_1.getJson)({ url: '/forum/threads/list/most-viewed', parameters: arguments });
}
exports.listMostViewedThreds = listMostViewedThreds;
/**
* List the the forums with most new entries during the specified period.
*
* @param daysBack {number} Number of days back. (optional)
* @param categoryIds {number[]} Category ids (optional)
* @param categoryPermalinks {string[]} Category permalinks (optional)
* @param p Page number (optional)
* @param pageSize Page size (optional)
*/
function listMostActiveForums(_a) {
var daysBack = _a.daysBack, categoryIds = _a.categoryIds, categoryPermalinks = _a.categoryPermalinks, _b = _a.p, p = _b === void 0 ? 1 : _b, pageSize = _a.pageSize;
return (0, api_1.getJson)({ url: '/forum/list/most-active', parameters: arguments });
}
exports.listMostActiveForums = listMostActiveForums;
/**
* Assign additional categories to a forum thread.
*
* Will not affect previously assigned categories.
* Requires moderator access.
*
* @param threadId {number} Entry id.
* @param categoryIds {number[]} Additional categories
*/
function addThreadCategories(_a) {
var threadId = _a.threadId, categoryIds = _a.categoryIds;
return (0, api_1.post)({ url: '/forum/thread/add-categories', parameters: arguments });
}
exports.addThreadCategories = addThreadCategories;
/**
* Remove categories from a forum thread.
*
* Requires moderator access.
*
* @param threadId {number} Entry id.
* @param categoryIds {number[]} Remove these categories
*/
function removeThreadCategories(_a) {
var threadId = _a.threadId, categoryIds = _a.categoryIds;
return (0, api_1.post)({ url: '/forum/thread/remove-categories', parameters: arguments });
}
exports.removeThreadCategories = removeThreadCategories;
/**
* Vote thumbs up/down for a forum entry.
*
*/
function vote(_a) {
var forumThreadEntry = _a.forumThreadEntry, score = _a.score;
var forumThreadEntryId = forumThreadEntry.id;
var forumId = forumThreadEntry.forumRef.id;
return (0, api_1.post)({
url: '/forum/entry/vote',
parameters: {
referenceId: forumThreadEntryId,
score: score,
referenceGroupId: forumId
}
});
}
exports.vote = vote;
/**
* Get vote summary (number of votes per score and total) for an entry.
* @param entryId
*/
function getVoteSummary(_a) {
var entryId = _a.entryId;
return (0, api_1.getJson)({
url: '/forum/entry/get-vote-summary',
parameters: {
referenceId: entryId
}
});
}
exports.getVoteSummary = getVoteSummary;
/**
* Search the store for a ForumThreadEntry matching the id or permalink
* @param forumThreads
* @param id
* @param forumPermalink
* @param forumThreadPermalink
*/
function getThreadEntryFromRedux(_a) {
var forumThreads = _a.forumThreads, id = _a.id, forumPermalink = _a.forumPermalink, forumThreadPermalink = _a.forumThreadPermalink;
if (id) {
// FIXME: What is this? Fix
// @ts-ignore
return _.find(_.flatten(Object.values(forumThreads.forums)), {
id: id /*, __type:FTE_COMPONENT_CLASS*/
});
}
return (0, get_1.default)((0, get_1.default)(forumThreads, "forums[".concat(forumPermalink ? forumPermalink : '', "]"), []).filter(function (thread) {
return (0, get_1.default)(thread, 'threadRef.permalink') === forumThreadPermalink &&
// @ts-ignore
// FIXME: Type definition
thread.threadId === thread.id;
}), '[0]');
}
exports.getThreadEntryFromRedux = getThreadEntryFromRedux;
/**
* Search the store for a ForumThread matching the id or permalink
* @param forumThreads
* @param id
* @param forumPermalink
* @param forumThreadPermalink
*/
function getThreadFromRedux(_a) {
var forumThreads = _a.forumThreads, id = _a.id, forumPermalink = _a.forumPermalink, forumThreadPermalink = _a.forumThreadPermalink;
if (id) {
// @ts-ignore
return _.find(_.flatten(Object.values(forumThreads.forums)), {
id: id /*, __type:FT_COMPONENT_CLASS*/
});
}
var forumThread = (0, get_1.default)(forumThreads, "forums[".concat(forumPermalink, "]"), []).filter(function (thread) {
return ((0, get_1.default)(thread, 'threadRef.permalink') === forumThreadPermalink &&
// @ts-ignore
thread.threadId === thread.id) ||
(0, get_1.default)(thread, 'permalink') === forumThreadPermalink;
});
if (forumThread.threadRef) {
return (0, get_1.default)(forumThread, '[0].threadRef');
}
else {
return (0, get_1.default)(forumThread, '[0]');
}
}
exports.getThreadFromRedux = getThreadFromRedux;
//# sourceMappingURL=index.js.map