mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-25 09:50:35 +01:00
Compare commits
8 Commits
v1.16.2
...
v1.16.2-be
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
14e211fb68 | ||
|
|
7b98fab95c | ||
|
|
a373731570 | ||
|
|
a76b5d15e0 | ||
|
|
a06b84d258 | ||
|
|
ecf212d307 | ||
|
|
dc6fc65322 | ||
|
|
27b481765b |
@@ -2,7 +2,7 @@
|
||||
"name": "nodebb",
|
||||
"license": "GPL-3.0",
|
||||
"description": "NodeBB Forum",
|
||||
"version": "1.16.2",
|
||||
"version": "1.16.2-beta.2",
|
||||
"homepage": "http://www.nodebb.org",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -43,7 +43,7 @@
|
||||
"bcryptjs": "2.4.3",
|
||||
"benchpressjs": "2.4.0",
|
||||
"body-parser": "^1.19.0",
|
||||
"bootbox": "5.5.2",
|
||||
"bootbox": "4.4.0",
|
||||
"bootstrap": "^3.4.1",
|
||||
"chart.js": "^2.9.3",
|
||||
"cli-graph": "^3.2.2",
|
||||
@@ -101,7 +101,7 @@
|
||||
"nodebb-plugin-spam-be-gone": "0.7.7",
|
||||
"nodebb-rewards-essentials": "0.1.4",
|
||||
"nodebb-theme-lavender": "5.0.17",
|
||||
"nodebb-theme-persona": "10.3.19",
|
||||
"nodebb-theme-persona": "10.3.18",
|
||||
"nodebb-theme-slick": "1.3.8",
|
||||
"nodebb-theme-vanilla": "11.3.10",
|
||||
"nodebb-widget-essentials": "5.0.2",
|
||||
@@ -154,12 +154,12 @@
|
||||
"@commitlint/cli": "11.0.0",
|
||||
"@commitlint/config-angular": "11.0.0",
|
||||
"coveralls": "3.1.0",
|
||||
"eslint": "7.18.0",
|
||||
"eslint": "7.17.0",
|
||||
"eslint-config-airbnb-base": "14.2.1",
|
||||
"eslint-plugin-import": "2.22.1",
|
||||
"grunt": "1.3.0",
|
||||
"grunt-contrib-watch": "1.1.0",
|
||||
"husky": "4.3.8",
|
||||
"husky": "4.3.7",
|
||||
"jsdom": "16.4.0",
|
||||
"lint-staged": "10.5.3",
|
||||
"mocha": "8.2.1",
|
||||
@@ -190,4 +190,4 @@
|
||||
"url": "https://github.com/barisusakli"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
"filter-active": "Ci sono uno o più filtri attivi in questa lista di segnalazioni",
|
||||
"filter-reset": "Rimuovi Filtri",
|
||||
"filters": "Opzioni Filtri",
|
||||
"filter-reporterId": "UID segnalatore",
|
||||
"filter-reporterId": "Segnalatore UID",
|
||||
"filter-targetUid": "UID segnalato",
|
||||
"filter-type": "Tipo Segnalazione",
|
||||
"filter-type-all": "Tutto il Contenuto",
|
||||
|
||||
@@ -104,16 +104,10 @@ paths:
|
||||
$ref: 'write/posts/pid.yaml'
|
||||
/posts/{pid}/state:
|
||||
$ref: 'write/posts/pid/state.yaml'
|
||||
/posts/{pid}/move:
|
||||
$ref: 'write/posts/pid/move.yaml'
|
||||
/posts/{pid}/vote:
|
||||
$ref: 'write/posts/pid/vote.yaml'
|
||||
/posts/{pid}/bookmark:
|
||||
$ref: 'write/posts/pid/bookmark.yaml'
|
||||
/posts/{pid}/diffs:
|
||||
$ref: 'write/posts/pid/diffs.yaml'
|
||||
/posts/{pid}/diffs/{since}:
|
||||
$ref: 'write/posts/pid/diffs/since.yaml'
|
||||
/admin/settings/{setting}:
|
||||
$ref: 'write/admin/settings/setting.yaml'
|
||||
/files/:
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
get:
|
||||
tags:
|
||||
- posts
|
||||
summary: get post edit history
|
||||
description: This operation retrieves a post's edit history
|
||||
parameters:
|
||||
- in: path
|
||||
name: pid
|
||||
schema:
|
||||
type: string
|
||||
required: true
|
||||
description: a valid post id
|
||||
example: 2
|
||||
responses:
|
||||
'200':
|
||||
description: Post history successfully retrieved.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
status:
|
||||
$ref: ../../../components/schemas/Status.yaml#/Status
|
||||
response:
|
||||
type: object
|
||||
properties:
|
||||
timestamps:
|
||||
type: array
|
||||
items:
|
||||
type: number
|
||||
revisions:
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
timestamp:
|
||||
type: number
|
||||
username:
|
||||
type: string
|
||||
editable:
|
||||
type: boolean
|
||||
@@ -1,65 +0,0 @@
|
||||
get:
|
||||
tags:
|
||||
- posts
|
||||
summary: get single post edit history
|
||||
description: This operation retrieves a post's edit history
|
||||
parameters:
|
||||
- in: path
|
||||
name: pid
|
||||
schema:
|
||||
type: string
|
||||
required: true
|
||||
description: a valid post id
|
||||
example: 2
|
||||
- in: path
|
||||
name: since
|
||||
schema:
|
||||
type: number
|
||||
required: true
|
||||
description: a valid UNIX timestamp
|
||||
example: 0
|
||||
responses:
|
||||
'200':
|
||||
description: Post history successfully retrieved.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
status:
|
||||
$ref: ../../../../components/schemas/Status.yaml#/Status
|
||||
response:
|
||||
$ref: ../../../../components/schemas/PostObject.yaml#/PostObject
|
||||
put:
|
||||
tags:
|
||||
- posts
|
||||
summary: revert a post
|
||||
description: This operation reverts a post to an earlier version. The revert process will append a new history item to the post's edit history.
|
||||
parameters:
|
||||
- in: path
|
||||
name: pid
|
||||
schema:
|
||||
type: string
|
||||
required: true
|
||||
description: a valid post id
|
||||
example: 2
|
||||
- in: path
|
||||
name: since
|
||||
schema:
|
||||
type: number
|
||||
required: true
|
||||
description: a valid UNIX timestamp
|
||||
example: 0
|
||||
responses:
|
||||
'200':
|
||||
description: Post successfully reverted
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
status:
|
||||
$ref: ../../../../components/schemas/Status.yaml#/Status
|
||||
response:
|
||||
type: object
|
||||
properties: {}
|
||||
@@ -1,36 +0,0 @@
|
||||
put:
|
||||
tags:
|
||||
- posts
|
||||
summary: move a post
|
||||
description: This operation moves a post to a different topic.
|
||||
parameters:
|
||||
- in: path
|
||||
name: pid
|
||||
schema:
|
||||
type: number
|
||||
required: true
|
||||
description: a valid post id
|
||||
example: 5
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
tid:
|
||||
type: number
|
||||
description: a valid topic id
|
||||
example: 4
|
||||
responses:
|
||||
'200':
|
||||
description: Post successfully moved
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
status:
|
||||
$ref: ../../../components/schemas/Status.yaml#/Status
|
||||
response:
|
||||
type: object
|
||||
properties: {}
|
||||
@@ -109,9 +109,9 @@ define('admin/manage/categories', [
|
||||
name: '[[admin/manage/categories:parent-category-none]]',
|
||||
icon: 'fa-none',
|
||||
});
|
||||
Benchpress.render('admin/partials/categories/create', {
|
||||
app.parseAndTranslate('admin/partials/categories/create', {
|
||||
categories: categories,
|
||||
}).then(function (html) {
|
||||
}, function (html) {
|
||||
var modal = bootbox.dialog({
|
||||
title: '[[admin/manage/categories:alert.create]]',
|
||||
message: html,
|
||||
|
||||
@@ -119,9 +119,9 @@ define('admin/manage/category', [
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
|
||||
Benchpress.render('admin/partials/categories/copy-settings', {
|
||||
app.parseAndTranslate('admin/partials/categories/copy-settings', {
|
||||
categories: allCategories,
|
||||
}).then(function (html) {
|
||||
}, function (html) {
|
||||
var selectedCid;
|
||||
var modal = bootbox.dialog({
|
||||
title: '[[modules:composer.select_category]]',
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
define('forum/topic/diffs', ['api', 'forum/topic/images'], function (api) {
|
||||
define('forum/topic/diffs', ['forum/topic/images'], function () {
|
||||
var Diffs = {};
|
||||
|
||||
Diffs.open = function (pid) {
|
||||
@@ -10,7 +10,11 @@ define('forum/topic/diffs', ['api', 'forum/topic/images'], function (api) {
|
||||
|
||||
var localeStringOpts = { year: 'numeric', month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric' };
|
||||
|
||||
api.get(`/posts/${pid}/diffs`, {}).then((data) => {
|
||||
socket.emit('posts.getDiffs', { pid: pid }, function (err, data) {
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
|
||||
app.parseAndTranslate('partials/modals/post_history', {
|
||||
diffs: data.revisions.map(function (revision) {
|
||||
var timestamp = parseInt(revision.timestamp, 10);
|
||||
@@ -52,7 +56,7 @@ define('forum/topic/diffs', ['api', 'forum/topic/images'], function (api) {
|
||||
revertEl.prop('disabled', true);
|
||||
});
|
||||
});
|
||||
}).catch(app.alertError);
|
||||
});
|
||||
};
|
||||
|
||||
Diffs.load = function (pid, since, postContainer) {
|
||||
@@ -60,7 +64,11 @@ define('forum/topic/diffs', ['api', 'forum/topic/images'], function (api) {
|
||||
return;
|
||||
}
|
||||
|
||||
api.get(`/posts/${pid}/diffs/${since}`, {}).then((data) => {
|
||||
socket.emit('posts.showPostAt', { pid: pid, since: since }, function (err, data) {
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
|
||||
data.deleted = !!parseInt(data.deleted, 10);
|
||||
|
||||
app.parseAndTranslate('partials/posts_list', 'posts', {
|
||||
@@ -68,7 +76,7 @@ define('forum/topic/diffs', ['api', 'forum/topic/images'], function (api) {
|
||||
}, function (html) {
|
||||
postContainer.empty().append(html);
|
||||
});
|
||||
}).catch(app.alertError);
|
||||
});
|
||||
};
|
||||
|
||||
Diffs.restore = function (pid, since, modal) {
|
||||
@@ -76,10 +84,14 @@ define('forum/topic/diffs', ['api', 'forum/topic/images'], function (api) {
|
||||
return;
|
||||
}
|
||||
|
||||
api.put(`/posts/${pid}/diffs/${since}`, {}).then(() => {
|
||||
socket.emit('posts.restoreDiff', { pid: pid, since: since }, function (err) {
|
||||
if (err) {
|
||||
return app.alertError(err);
|
||||
}
|
||||
|
||||
modal.modal('hide');
|
||||
app.alertSuccess('[[topic:diffs.post-restored]]');
|
||||
}).catch(app.alertError);
|
||||
});
|
||||
};
|
||||
|
||||
return Diffs;
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
|
||||
define('forum/topic/move-post', [
|
||||
'components', 'postSelect', 'translator', 'alerts', 'api',
|
||||
], function (components, postSelect, translator, alerts, api) {
|
||||
'components', 'postSelect', 'translator', 'alerts',
|
||||
], function (components, postSelect, translator, alerts) {
|
||||
var MovePost = {};
|
||||
|
||||
var moveModal;
|
||||
@@ -100,10 +100,10 @@ define('forum/topic/move-post', [
|
||||
if (!ajaxify.data.template.topic || !data.tid) {
|
||||
return;
|
||||
}
|
||||
|
||||
Promise.all(data.pids.map(pid => api.put(`/posts/${pid}/move`, {
|
||||
tid: data.tid,
|
||||
}))).then(() => {
|
||||
socket.emit('posts.movePosts', { pids: data.pids, tid: data.tid }, function (err) {
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
data.pids.forEach(function (pid) {
|
||||
components.get('post', 'pid', pid).fadeOut(500, function () {
|
||||
$(this).remove();
|
||||
@@ -111,7 +111,7 @@ define('forum/topic/move-post', [
|
||||
});
|
||||
|
||||
closeMoveModal();
|
||||
}).catch(app.alertError);
|
||||
});
|
||||
}
|
||||
|
||||
function closeMoveModal() {
|
||||
|
||||
@@ -210,9 +210,7 @@ define('forum/topic/posts', [
|
||||
html.insertBefore(before);
|
||||
|
||||
// Now restore the relative position the user was on prior to new post insertion
|
||||
if (scrollTop > 0) {
|
||||
$(window).scrollTop(scrollTop + ($(document).height() - height));
|
||||
}
|
||||
$(window).scrollTop(scrollTop + ($(document).height() - height));
|
||||
} else {
|
||||
components.get('topic').append(html);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,19 @@
|
||||
|
||||
(function (factory) {
|
||||
function loadClient(language, namespace) {
|
||||
return Promise.resolve(jQuery.getJSON([config.assetBaseUrl, 'language', language, namespace].join('/') + '.json?' + config['cache-buster']));
|
||||
return new Promise(function (resolve, reject) {
|
||||
jQuery.getJSON([config.assetBaseUrl, 'language', language, namespace].join('/') + '.json?' + config['cache-buster'], function (data) {
|
||||
const payload = {
|
||||
language: language,
|
||||
namespace: namespace,
|
||||
data: data,
|
||||
};
|
||||
$(window).trigger('action:translator.loadClient', payload);
|
||||
resolve(payload.promise ? Promise.resolve(payload.promise) : data);
|
||||
}).fail(function (jqxhr, textStatus, error) {
|
||||
reject(new Error(textStatus + ', ' + error));
|
||||
});
|
||||
});
|
||||
}
|
||||
var warn = function () { console.warn.apply(console, arguments); };
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
@@ -286,9 +298,6 @@
|
||||
var out = translated;
|
||||
translatedArgs.forEach(function (arg, i) {
|
||||
var escaped = arg.replace(/%(?=\d)/g, '%').replace(/\\,/g, ',');
|
||||
// fix double escaped translation keys, see https://github.com/NodeBB/NodeBB/issues/9206
|
||||
escaped = escaped.replace(/[/g, '[')
|
||||
.replace(/]/g, ']');
|
||||
out = out.replace(new RegExp('%' + (i + 1), 'g'), escaped);
|
||||
});
|
||||
return out;
|
||||
@@ -548,6 +557,18 @@
|
||||
});
|
||||
},
|
||||
|
||||
flushNamespace: function (namespace) {
|
||||
Object.keys(Translator.cache).forEach(function (code) {
|
||||
if (Translator.cache[code] &&
|
||||
Translator.cache[code].translations &&
|
||||
Translator.cache[code].translations[namespace]
|
||||
) {
|
||||
Translator.cache[code].translations[namespace] = null;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Legacy translator function for backwards compatibility
|
||||
*/
|
||||
|
||||
@@ -4,7 +4,6 @@ const validator = require('validator');
|
||||
const _ = require('lodash');
|
||||
|
||||
const utils = require('../utils');
|
||||
const user = require('../user');
|
||||
const posts = require('../posts');
|
||||
const topics = require('../topics');
|
||||
const groups = require('../groups');
|
||||
@@ -13,7 +12,6 @@ const events = require('../events');
|
||||
const privileges = require('../privileges');
|
||||
const apiHelpers = require('./helpers');
|
||||
const websockets = require('../socket.io');
|
||||
const socketHelpers = require('../socket.io/helpers');
|
||||
|
||||
const postsAPI = module.exports;
|
||||
|
||||
@@ -196,27 +194,6 @@ async function isMainAndLastPost(pid) {
|
||||
};
|
||||
}
|
||||
|
||||
postsAPI.move = async function (caller, data) {
|
||||
const canMove = await Promise.all([
|
||||
privileges.topics.isAdminOrMod(data.tid, caller.uid),
|
||||
privileges.posts.canMove(data.pid, caller.uid),
|
||||
]);
|
||||
if (!canMove.every(Boolean)) {
|
||||
throw new Error('[[error:no-privileges]]');
|
||||
}
|
||||
|
||||
await topics.movePostToTopic(caller.uid, data.pid, data.tid);
|
||||
|
||||
const [postDeleted, topicDeleted] = await Promise.all([
|
||||
posts.getPostField(data.pid, 'deleted'),
|
||||
topics.getTopicField(data.tid, 'deleted'),
|
||||
]);
|
||||
|
||||
if (!postDeleted && !topicDeleted) {
|
||||
socketHelpers.sendNotificationToPostOwner(data.pid, caller.uid, 'move', 'notifications:moved_your_post');
|
||||
}
|
||||
};
|
||||
|
||||
postsAPI.upvote = async function (caller, data) {
|
||||
return await apiHelpers.postCommand(caller, 'upvote', 'voted', 'notifications:upvoted_your_post_in', data);
|
||||
};
|
||||
@@ -236,61 +213,3 @@ postsAPI.bookmark = async function (caller, data) {
|
||||
postsAPI.unbookmark = async function (caller, data) {
|
||||
return await apiHelpers.postCommand(caller, 'unbookmark', 'bookmarked', '', data);
|
||||
};
|
||||
|
||||
async function diffsPrivilegeCheck(pid, uid) {
|
||||
const [deleted, privilegesData] = await Promise.all([
|
||||
posts.getPostField(pid, 'deleted'),
|
||||
privileges.posts.get([pid], uid),
|
||||
]);
|
||||
|
||||
const allowed = privilegesData[0]['posts:history'] && (deleted ? privilegesData[0]['posts:view_deleted'] : true);
|
||||
if (!allowed) {
|
||||
throw new Error('[[error:no-privileges]]');
|
||||
}
|
||||
}
|
||||
|
||||
postsAPI.getDiffs = async (caller, data) => {
|
||||
await diffsPrivilegeCheck(data.pid, caller.uid);
|
||||
const timestamps = await posts.diffs.list(data.pid);
|
||||
const post = await posts.getPostFields(data.pid, ['timestamp', 'uid']);
|
||||
|
||||
const diffs = await posts.diffs.get(data.pid);
|
||||
const uids = diffs.map(diff => diff.uid || null);
|
||||
uids.push(post.uid);
|
||||
let usernames = await user.getUsersFields(uids, ['username']);
|
||||
usernames = usernames.map(userObj => (userObj.uid ? userObj.username : null));
|
||||
|
||||
let canEdit = true;
|
||||
try {
|
||||
await user.isPrivilegedOrSelf(caller.uid, post.uid);
|
||||
} catch (e) {
|
||||
canEdit = false;
|
||||
}
|
||||
|
||||
timestamps.push(post.timestamp);
|
||||
|
||||
return {
|
||||
timestamps: timestamps,
|
||||
revisions: timestamps.map((timestamp, idx) => ({
|
||||
timestamp: timestamp,
|
||||
username: usernames[idx],
|
||||
})),
|
||||
editable: canEdit,
|
||||
};
|
||||
};
|
||||
|
||||
postsAPI.loadDiff = async (caller, data) => {
|
||||
await diffsPrivilegeCheck(data.pid, caller.uid);
|
||||
return await posts.diffs.load(data.pid, data.since, caller.uid);
|
||||
};
|
||||
|
||||
postsAPI.restoreDiff = async (caller, data) => {
|
||||
const cid = await posts.getCidByPid(data.pid);
|
||||
const canEdit = await privileges.categories.can('edit', cid, caller.uid);
|
||||
if (!canEdit) {
|
||||
throw new Error('[[error:no-privileges]]');
|
||||
}
|
||||
|
||||
const edit = await posts.diffs.restore(data.pid, data.since, caller.uid, apiHelpers.buildReqObject(caller));
|
||||
websockets.in('topic_' + edit.topic.tid).emit('event:post_edited', edit);
|
||||
};
|
||||
|
||||
@@ -57,9 +57,11 @@ Categories.getCategoryById = async function (data) {
|
||||
category.isIgnored = watchState[0] === Categories.watchStates.ignoring;
|
||||
category.parent = parent;
|
||||
|
||||
|
||||
calculateTopicPostCount(category);
|
||||
const result = await plugins.hooks.fire('filter:category.get', { category: category, uid: data.uid });
|
||||
const result = await plugins.hooks.fire('filter:category.get', {
|
||||
category: category,
|
||||
...data,
|
||||
});
|
||||
return result.category;
|
||||
};
|
||||
|
||||
|
||||
@@ -51,11 +51,12 @@ notificationsController.get = async function (req, res, next) {
|
||||
if (!selectedFilter) {
|
||||
return next();
|
||||
}
|
||||
let nids = await user.notifications.getAll(req.uid, selectedFilter.filter);
|
||||
const pageCount = Math.max(1, Math.ceil(nids.length / itemsPerPage));
|
||||
nids = nids.slice(start, stop + 1);
|
||||
|
||||
const notifications = await user.notifications.getNotifications(nids, req.uid);
|
||||
const nids = await user.notifications.getAll(req.uid, selectedFilter.filter);
|
||||
let notifications = await user.notifications.getNotifications(nids, req.uid);
|
||||
|
||||
const pageCount = Math.max(1, Math.ceil(notifications.length / itemsPerPage));
|
||||
notifications = notifications.slice(start, stop + 1);
|
||||
|
||||
res.render('notifications', {
|
||||
notifications: notifications,
|
||||
|
||||
@@ -118,7 +118,7 @@ function calculateStartStop(page, postIndex, settings) {
|
||||
let startSkip = 0;
|
||||
|
||||
if (!settings.usePagination) {
|
||||
if (postIndex !== 0) {
|
||||
if (postIndex > 1) {
|
||||
page = 1;
|
||||
}
|
||||
startSkip = Math.max(0, postIndex - Math.ceil(settings.postsPerPage / 2));
|
||||
|
||||
@@ -38,14 +38,6 @@ Posts.delete = async (req, res) => {
|
||||
helpers.formatApiResponse(200, res);
|
||||
};
|
||||
|
||||
Posts.move = async (req, res) => {
|
||||
await api.posts.move(req, {
|
||||
pid: req.params.pid,
|
||||
tid: req.body.tid,
|
||||
});
|
||||
helpers.formatApiResponse(200, res);
|
||||
};
|
||||
|
||||
async function mock(req) {
|
||||
const tid = await posts.getPostField(req.params.pid, 'tid');
|
||||
return { pid: req.params.pid, room_id: `topic_${tid}` };
|
||||
@@ -81,16 +73,3 @@ Posts.unbookmark = async (req, res) => {
|
||||
await api.posts.unbookmark(req, data);
|
||||
helpers.formatApiResponse(200, res);
|
||||
};
|
||||
|
||||
Posts.getDiffs = async (req, res) => {
|
||||
helpers.formatApiResponse(200, res, await api.posts.getDiffs(req, { ...req.params }));
|
||||
};
|
||||
|
||||
Posts.loadDiff = async (req, res) => {
|
||||
helpers.formatApiResponse(200, res, await api.posts.loadDiff(req, { ...req.params }));
|
||||
};
|
||||
|
||||
Posts.restoreDiff = async (req, res) => {
|
||||
helpers.formatApiResponse(200, res, await api.posts.restoreDiff(req, { ...req.params }));
|
||||
};
|
||||
|
||||
|
||||
@@ -104,14 +104,8 @@ Topics.deleteTags = async (req, res) => {
|
||||
};
|
||||
|
||||
Topics.getThumbs = async (req, res) => {
|
||||
if (isFinite(req.params.tid)) { // post_uuids can be passed in occasionally, in that case no checks are necessary
|
||||
const [exists, canRead] = await Promise.all([
|
||||
topics.exists(req.params.tid),
|
||||
privileges.topics.can('topics:read', req.params.tid, req.uid),
|
||||
]);
|
||||
if (!exists || !canRead) {
|
||||
return helpers.formatApiResponse(403, res);
|
||||
}
|
||||
if (!await privileges.topics.can('topics:read', req.params.tid, req.uid)) {
|
||||
return helpers.formatApiResponse(403, res);
|
||||
}
|
||||
|
||||
helpers.formatApiResponse(200, res, await topics.thumbs.get(req.params.tid));
|
||||
|
||||
@@ -230,16 +230,6 @@ Emailer.send = async (template, uid, params) => {
|
||||
params.uid = uid;
|
||||
params.username = userData.username;
|
||||
params.rtl = await translator.translate('[[language:dir]]', userSettings.userLang) === 'rtl';
|
||||
|
||||
const result = await Plugins.hooks.fire('filter:email.cancel', {
|
||||
cancel: false, // set to true in plugin to cancel sending email
|
||||
template: template,
|
||||
params: params,
|
||||
});
|
||||
|
||||
if (result.cancel) {
|
||||
return;
|
||||
}
|
||||
await Emailer.sendToEmail(template, userData.email, userSettings.userLang, params);
|
||||
};
|
||||
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const utils = require('./utils');
|
||||
const paths = require('./constants').paths;
|
||||
const { paths } = require('./constants');
|
||||
const plugins = require('./plugins');
|
||||
|
||||
const Languages = module.exports;
|
||||
const languagesPath = path.join(__dirname, '../build/public/language');
|
||||
@@ -12,8 +13,14 @@ const files = fs.readdirSync(path.join(paths.nodeModules, '/timeago/locales'));
|
||||
Languages.timeagoCodes = files.filter(f => f.startsWith('jquery.timeago')).map(f => f.split('.')[2]);
|
||||
|
||||
Languages.get = async function (language, namespace) {
|
||||
const data = await fs.promises.readFile(path.join(languagesPath, language, namespace + '.json'), 'utf8');
|
||||
return JSON.parse(data) || {};
|
||||
const data = await fs.promises.readFile(path.join(languagesPath, language, `${namespace}.json`), 'utf8');
|
||||
const parsed = JSON.parse(data) || {};
|
||||
const result = await plugins.hooks.fire('filter:languages.get', {
|
||||
language,
|
||||
namespace,
|
||||
data: parsed,
|
||||
});
|
||||
return result.data;
|
||||
};
|
||||
|
||||
let codeCache = null;
|
||||
|
||||
@@ -46,7 +46,7 @@ Assert.topic = helpers.try(async (req, res, next) => {
|
||||
|
||||
Assert.post = helpers.try(async (req, res, next) => {
|
||||
if (!await posts.exists(req.params.pid)) {
|
||||
return controllerHelpers.formatApiResponse(404, res, new Error('[[error:no-post]]'));
|
||||
return controllerHelpers.formatApiResponse(404, res, new Error('[[error:no-topic]]'));
|
||||
}
|
||||
|
||||
next();
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
const nconf = require('nconf');
|
||||
const jsesc = require('jsesc');
|
||||
const _ = require('lodash');
|
||||
var nconf = require('nconf');
|
||||
var jsesc = require('jsesc');
|
||||
var _ = require('lodash');
|
||||
const validator = require('validator');
|
||||
const util = require('util');
|
||||
var util = require('util');
|
||||
|
||||
const db = require('../database');
|
||||
const user = require('../user');
|
||||
const topics = require('../topics');
|
||||
const messaging = require('../messaging');
|
||||
const flags = require('../flags');
|
||||
const meta = require('../meta');
|
||||
const plugins = require('../plugins');
|
||||
const navigation = require('../navigation');
|
||||
const translator = require('../translator');
|
||||
const privileges = require('../privileges');
|
||||
const languages = require('../languages');
|
||||
const utils = require('../utils');
|
||||
const helpers = require('./helpers');
|
||||
var db = require('../database');
|
||||
var user = require('../user');
|
||||
var topics = require('../topics');
|
||||
var messaging = require('../messaging');
|
||||
var flags = require('../flags');
|
||||
var meta = require('../meta');
|
||||
var plugins = require('../plugins');
|
||||
var navigation = require('../navigation');
|
||||
var translator = require('../translator');
|
||||
var privileges = require('../privileges');
|
||||
var languages = require('../languages');
|
||||
var utils = require('../utils');
|
||||
var helpers = require('./helpers');
|
||||
|
||||
const controllers = {
|
||||
var controllers = {
|
||||
api: require('../controllers/api'),
|
||||
helpers: require('../controllers/helpers'),
|
||||
};
|
||||
@@ -49,9 +49,9 @@ middleware.buildHeader = helpers.try(async function buildHeader(req, res, next)
|
||||
middleware.buildHeaderAsync = util.promisify(middleware.buildHeader);
|
||||
|
||||
middleware.renderHeader = async function renderHeader(req, res, data) {
|
||||
const registrationType = meta.config.registrationType || 'normal';
|
||||
var registrationType = meta.config.registrationType || 'normal';
|
||||
res.locals.config = res.locals.config || {};
|
||||
const templateValues = {
|
||||
var templateValues = {
|
||||
title: meta.config.title || '',
|
||||
'title:url': meta.config['title:url'] || '',
|
||||
description: meta.config.description || '',
|
||||
@@ -240,7 +240,7 @@ middleware.renderFooter = async function renderFooter(req, res, templateValues)
|
||||
};
|
||||
|
||||
function modifyTitle(obj) {
|
||||
const title = controllers.helpers.buildTitle(meta.config.homePageTitle || '[[pages:home]]');
|
||||
var title = controllers.helpers.buildTitle(meta.config.homePageTitle || '[[pages:home]]');
|
||||
obj.browserTitle = title;
|
||||
|
||||
if (obj.metaTags) {
|
||||
|
||||
@@ -327,9 +327,10 @@ Notifications.prune = async function () {
|
||||
]);
|
||||
|
||||
await batch.processSortedSet('users:joindate', async function (uids) {
|
||||
const unread = uids.map(uid => 'uid:' + uid + ':notifications:unread');
|
||||
const read = uids.map(uid => 'uid:' + uid + ':notifications:read');
|
||||
await db.sortedSetsRemoveRangeByScore(unread.concat(read), '-inf', cutoffTime);
|
||||
await Promise.all([
|
||||
db.sortedSetsRemoveRangeByScore(uids.map(uid => 'uid:' + uid + ':notifications:unread'), '-inf', cutoffTime),
|
||||
db.sortedSetsRemoveRangeByScore(uids.map(uid => 'uid:' + uid + ':notifications:read'), '-inf', cutoffTime),
|
||||
]);
|
||||
}, { batch: 500, interval: 100 });
|
||||
} catch (err) {
|
||||
if (err) {
|
||||
|
||||
@@ -92,7 +92,7 @@ Hooks.unregister = function (id, hook, method) {
|
||||
Hooks.fire = async function (hook, params) {
|
||||
const hookList = plugins.loadedHooks[hook];
|
||||
const hookType = hook.split(':')[0];
|
||||
if (global.env === 'development' && hook !== 'action:plugins.firehook') {
|
||||
if (global.env === 'development' && hook !== 'action:plugins.fireHook') {
|
||||
winston.verbose('[plugins/fireHook] ' + hook);
|
||||
}
|
||||
|
||||
@@ -102,8 +102,8 @@ Hooks.fire = async function (hook, params) {
|
||||
}
|
||||
const result = await hookTypeToMethod[hookType](hook, hookList, params);
|
||||
|
||||
if (hook !== 'action:plugins.firehook') {
|
||||
Hooks.fire('action:plugins.firehook', { hook: hook, params: params });
|
||||
if (hook !== 'action:plugins.fireHook') {
|
||||
Hooks.fire('action:plugins.fireHook', { hook: hook, params: params });
|
||||
}
|
||||
if (result !== undefined) {
|
||||
return result;
|
||||
|
||||
@@ -18,17 +18,11 @@ module.exports = function () {
|
||||
setupApiRoute(router, 'put', '/:pid/state', [...middlewares, middleware.assert.post], controllers.write.posts.restore);
|
||||
setupApiRoute(router, 'delete', '/:pid/state', [...middlewares, middleware.assert.post], controllers.write.posts.delete);
|
||||
|
||||
setupApiRoute(router, 'put', '/:pid/move', [...middlewares, middleware.assert.post, middleware.checkRequired.bind(null, ['tid'])], controllers.write.posts.move);
|
||||
|
||||
setupApiRoute(router, 'put', '/:pid/vote', [...middlewares, middleware.checkRequired.bind(null, ['delta']), middleware.assert.post], controllers.write.posts.vote);
|
||||
setupApiRoute(router, 'delete', '/:pid/vote', [...middlewares, middleware.assert.post], controllers.write.posts.unvote);
|
||||
|
||||
setupApiRoute(router, 'put', '/:pid/bookmark', [...middlewares, middleware.assert.post], controllers.write.posts.bookmark);
|
||||
setupApiRoute(router, 'delete', '/:pid/bookmark', [...middlewares, middleware.assert.post], controllers.write.posts.unbookmark);
|
||||
|
||||
setupApiRoute(router, 'get', '/:pid/diffs', [middleware.authenticateOrGuest, middleware.assert.post], controllers.write.posts.getDiffs);
|
||||
setupApiRoute(router, 'get', '/:pid/diffs/:since', [middleware.authenticateOrGuest, middleware.assert.post], controllers.write.posts.loadDiff);
|
||||
setupApiRoute(router, 'put', '/:pid/diffs/:since', [...middlewares, middleware.assert.post], controllers.write.posts.restoreDiff);
|
||||
|
||||
return router;
|
||||
};
|
||||
|
||||
@@ -1,21 +1,67 @@
|
||||
'use strict';
|
||||
|
||||
const api = require('../../api');
|
||||
const posts = require('../../posts');
|
||||
const user = require('../../user');
|
||||
const privileges = require('../../privileges');
|
||||
const apiHelpers = require('../../api/helpers');
|
||||
const websockets = require('..');
|
||||
|
||||
module.exports = function (SocketPosts) {
|
||||
SocketPosts.getDiffs = async function (socket, data) {
|
||||
websockets.warnDeprecated(socket, 'GET /api/v3/posts/:pid/diffs');
|
||||
return await api.posts.getDiffs(socket, data);
|
||||
await privilegeCheck(data.pid, socket.uid);
|
||||
const timestamps = await posts.diffs.list(data.pid);
|
||||
const post = await posts.getPostFields(data.pid, ['timestamp', 'uid']);
|
||||
|
||||
const diffs = await posts.diffs.get(data.pid);
|
||||
const uids = diffs.map(diff => diff.uid || null);
|
||||
uids.push(post.uid);
|
||||
let usernames = await user.getUsersFields(uids, ['username']);
|
||||
usernames = usernames.map(userObj => (userObj.uid ? userObj.username : null));
|
||||
|
||||
let canEdit = true;
|
||||
try {
|
||||
await user.isPrivilegedOrSelf(socket.uid, post.uid);
|
||||
} catch (e) {
|
||||
canEdit = false;
|
||||
}
|
||||
|
||||
timestamps.push(post.timestamp);
|
||||
|
||||
return {
|
||||
timestamps: timestamps,
|
||||
revisions: timestamps.map((timestamp, idx) => ({
|
||||
timestamp: timestamp,
|
||||
username: usernames[idx],
|
||||
})),
|
||||
editable: canEdit,
|
||||
};
|
||||
};
|
||||
|
||||
SocketPosts.showPostAt = async function (socket, data) {
|
||||
websockets.warnDeprecated(socket, 'GET /api/v3/posts/:pid/diffs/:since');
|
||||
return await api.posts.loadDiff(socket, data);
|
||||
await privilegeCheck(data.pid, socket.uid);
|
||||
return await posts.diffs.load(data.pid, data.since, socket.uid);
|
||||
};
|
||||
|
||||
async function privilegeCheck(pid, uid) {
|
||||
const [deleted, privilegesData] = await Promise.all([
|
||||
posts.getPostField(pid, 'deleted'),
|
||||
privileges.posts.get([pid], uid),
|
||||
]);
|
||||
|
||||
const allowed = privilegesData[0]['posts:history'] && (deleted ? privilegesData[0]['posts:view_deleted'] : true);
|
||||
if (!allowed) {
|
||||
throw new Error('[[error:no-privileges]]');
|
||||
}
|
||||
}
|
||||
|
||||
SocketPosts.restoreDiff = async function (socket, data) {
|
||||
websockets.warnDeprecated(socket, 'PUT /api/v3/posts/:pid/diffs/:since');
|
||||
return await api.posts.restoreDiff(socket, data);
|
||||
const cid = await posts.getCidByPid(data.pid);
|
||||
const canEdit = await privileges.categories.can('edit', cid, socket.uid);
|
||||
if (!canEdit) {
|
||||
throw new Error('[[error:no-privileges]]');
|
||||
}
|
||||
|
||||
const edit = await posts.diffs.restore(data.pid, data.since, socket.uid, apiHelpers.buildReqObject(socket));
|
||||
websockets.in('topic_' + edit.topic.tid).emit('event:post_edited', edit);
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,33 +1,45 @@
|
||||
'use strict';
|
||||
|
||||
const api = require('../../api');
|
||||
const sockets = require('..');
|
||||
const privileges = require('../../privileges');
|
||||
const topics = require('../../topics');
|
||||
const posts = require('../../posts');
|
||||
const socketHelpers = require('../helpers');
|
||||
|
||||
module.exports = function (SocketPosts) {
|
||||
function moveChecks(socket, typeCheck, data) {
|
||||
SocketPosts.movePost = async function (socket, data) {
|
||||
await SocketPosts.movePosts(socket, { pids: [data.pid], tid: data.tid });
|
||||
};
|
||||
|
||||
SocketPosts.movePosts = async function (socket, data) {
|
||||
if (!socket.uid) {
|
||||
throw new Error('[[error:not-logged-in]]');
|
||||
}
|
||||
|
||||
if (!data || !typeCheck || !data.tid) {
|
||||
if (!data || !Array.isArray(data.pids) || !data.tid) {
|
||||
throw new Error('[[error:invalid-data]]');
|
||||
}
|
||||
}
|
||||
|
||||
SocketPosts.movePost = async function (socket, data) {
|
||||
sockets.warnDeprecated(socket, 'PUT /api/v3/posts/:pid/move');
|
||||
const canMove = await privileges.topics.isAdminOrMod(data.tid, socket.uid);
|
||||
if (!canMove) {
|
||||
throw new Error('[[error:no-privileges]]');
|
||||
}
|
||||
|
||||
moveChecks(socket, isFinite(data.pid), data);
|
||||
await api.posts.move(socket, data);
|
||||
};
|
||||
for (const pid of data.pids) {
|
||||
/* eslint-disable no-await-in-loop */
|
||||
const canMove = await privileges.posts.canMove(pid, socket.uid);
|
||||
if (!canMove) {
|
||||
throw new Error('[[error:no-privileges]]');
|
||||
}
|
||||
await topics.movePostToTopic(socket.uid, pid, data.tid);
|
||||
|
||||
SocketPosts.movePosts = async function (socket, data) {
|
||||
sockets.warnDeprecated(socket, 'PUT /api/v3/posts/:pid/move');
|
||||
const [postDeleted, topicDeleted] = await Promise.all([
|
||||
posts.getPostField(pid, 'deleted'),
|
||||
topics.getTopicField(data.tid, 'deleted'),
|
||||
]);
|
||||
|
||||
moveChecks(socket, !Array.isArray(data.pids), data);
|
||||
await Promise.all(data.pids.map(async pid => api.posts.move(socket, {
|
||||
tid: data.tid,
|
||||
pid,
|
||||
})));
|
||||
if (!postDeleted && !topicDeleted) {
|
||||
socketHelpers.sendNotificationToPostOwner(pid, socket.uid, 'move', 'notifications:moved_your_post');
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -48,6 +48,10 @@ module.exports = function (Topics) {
|
||||
tids = await db.getSortedSetRevRange('uid:' + params.uid + ':followed_tids', 0, -1);
|
||||
} else if (params.cids) {
|
||||
tids = await getCidTids(params);
|
||||
} else if (params.tags.length) {
|
||||
tids = await getTagTids(params);
|
||||
} else if (params.sort === 'old') {
|
||||
tids = await db.getSortedSetRange(`topics:recent`, 0, meta.config.recentMaxTopics - 1);
|
||||
} else {
|
||||
tids = await db.getSortedSetRevRange('topics:' + params.sort, 0, meta.config.recentMaxTopics - 1);
|
||||
}
|
||||
@@ -55,12 +59,30 @@ module.exports = function (Topics) {
|
||||
return tids;
|
||||
}
|
||||
|
||||
async function getTagTids(params) {
|
||||
const sets = [
|
||||
params.sort === 'old' ?
|
||||
'topics:recent' :
|
||||
`topics:${params.sort}`,
|
||||
...params.tags.map(tag => `tag:${tag}:topics`),
|
||||
];
|
||||
const method = params.sort === 'old' ?
|
||||
'getSortedSetIntersect' :
|
||||
'getSortedSetRevIntersect';
|
||||
return await db[method]({
|
||||
sets: sets,
|
||||
start: 0,
|
||||
stop: meta.config.recentMaxTopics - 1,
|
||||
weights: sets.map((s, index) => (index ? 0 : 1)),
|
||||
});
|
||||
}
|
||||
|
||||
async function getCidTids(params) {
|
||||
const sets = [];
|
||||
const pinnedSets = [];
|
||||
params.cids.forEach(function (cid) {
|
||||
if (params.sort === 'recent') {
|
||||
sets.push('cid:' + cid + ':tids');
|
||||
params.cids.forEach((cid) => {
|
||||
if (params.sort === 'recent' || params.sort === 'old') {
|
||||
sets.push(`cid:${cid}:tids`);
|
||||
} else {
|
||||
sets.push('cid:' + cid + ':tids' + (params.sort ? ':' + params.sort : ''));
|
||||
}
|
||||
@@ -68,7 +90,10 @@ module.exports = function (Topics) {
|
||||
});
|
||||
let pinnedTids = await db.getSortedSetRevRange(pinnedSets, 0, -1);
|
||||
pinnedTids = await Topics.tools.checkPinExpiry(pinnedTids);
|
||||
const tids = await db.getSortedSetRevRange(sets, 0, meta.config.recentMaxTopics - 1);
|
||||
const method = params.sort === 'old' ?
|
||||
'getSortedSetRange' :
|
||||
'getSortedSetRevRange';
|
||||
const tids = await db[method](sets, 0, meta.config.recentMaxTopics - 1);
|
||||
return pinnedTids.concat(tids);
|
||||
}
|
||||
|
||||
@@ -77,12 +102,13 @@ module.exports = function (Topics) {
|
||||
return tids;
|
||||
}
|
||||
const topicData = await Topics.getTopicsFields(tids, ['tid', 'lastposttime', 'upvotes', 'downvotes', 'postcount', 'pinned']);
|
||||
let sortFn = sortRecent;
|
||||
if (params.sort === 'posts') {
|
||||
sortFn = sortPopular;
|
||||
} else if (params.sort === 'votes') {
|
||||
sortFn = sortVotes;
|
||||
}
|
||||
const sortMap = {
|
||||
recent: sortRecent,
|
||||
old: sortOld,
|
||||
posts: sortPopular,
|
||||
votes: sortVotes,
|
||||
};
|
||||
const sortFn = sortMap[params.sort] || sortRecent;
|
||||
|
||||
if (params.floatPinned) {
|
||||
floatPinned(topicData, sortFn);
|
||||
@@ -106,6 +132,10 @@ module.exports = function (Topics) {
|
||||
return b.lastposttime - a.lastposttime;
|
||||
}
|
||||
|
||||
function sortOld(a, b) {
|
||||
return a.lastposttime - b.lastposttime;
|
||||
}
|
||||
|
||||
function sortVotes(a, b) {
|
||||
if (a.votes !== b.votes) {
|
||||
return b.votes - a.votes;
|
||||
|
||||
@@ -16,7 +16,7 @@ module.exports = {
|
||||
const userData = await user.getUsersFields(uids, ['uid', 'fullname']);
|
||||
const bulkAdd = userData
|
||||
.filter(u => u.uid && u.fullname)
|
||||
.map(u => ['fullname:sorted', 0, String(u.fullname).substr(0, 255).toLowerCase() + ':' + u.uid]);
|
||||
.map(u => ['fullname:sorted', 0, u.fullname.substr(0, 255).toLowerCase() + ':' + u.uid]);
|
||||
await db.sortedSetAddBulk(bulkAdd);
|
||||
}, {
|
||||
batch: 500,
|
||||
|
||||
@@ -13,9 +13,6 @@ module.exports = {
|
||||
timestamp: Date.UTC(2020, 9, 13),
|
||||
method: async function () {
|
||||
const progress = this.progress;
|
||||
|
||||
const maxGroupLength = meta.config.maximumGroupNameLength;
|
||||
meta.config.maximumGroupNameLength = 30;
|
||||
const timestamp = await db.getObjectField('group:administrators', 'timestamp');
|
||||
const verifiedExists = await groups.exists('verified-users');
|
||||
if (!verifiedExists) {
|
||||
@@ -41,8 +38,7 @@ module.exports = {
|
||||
timestamp: timestamp + 1,
|
||||
});
|
||||
}
|
||||
// restore setting
|
||||
meta.config.maximumGroupNameLength = maxGroupLength;
|
||||
|
||||
await batch.processSortedSet('users:joindate', async function (uids) {
|
||||
progress.incr(uids.length);
|
||||
const userData = await user.getUsersFields(uids, ['uid', 'email:confirmed']);
|
||||
|
||||
@@ -135,12 +135,6 @@ describe('API', async () => {
|
||||
title: 'Test Topic 2',
|
||||
content: 'Test topic 2 content',
|
||||
});
|
||||
await topics.post({
|
||||
uid: unprivUid,
|
||||
cid: testCategory.cid,
|
||||
title: 'Test Topic 3',
|
||||
content: 'Test topic 3 content',
|
||||
});
|
||||
|
||||
// Create a sample flag
|
||||
await flags.create('post', 1, unprivUid, 'sample reasons', Date.now());
|
||||
|
||||
@@ -2518,12 +2518,21 @@ describe('Topic\'s', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('sorted topics', function () {
|
||||
it('should get sorted topics in category', function (done) {
|
||||
var filters = ['', 'watched', 'unreplied', 'new'];
|
||||
async.map(filters, function (filter, next) {
|
||||
describe('sorted topics', () => {
|
||||
let category;
|
||||
before(async () => {
|
||||
category = await categories.create({ name: 'sorted' });
|
||||
const topic1Result = await topics.post({ uid: topic.userId, cid: category.cid, title: 'old replied', content: 'topic 1 OP' });
|
||||
const topic2Result = await topics.post({ uid: topic.userId, cid: category.cid, title: 'most recent replied', content: 'topic 2 OP' });
|
||||
await topics.reply({ uid: topic.userId, content: 'topic 1 reply', tid: topic1Result.topicData.tid });
|
||||
await topics.reply({ uid: topic.userId, content: 'topic 2 reply', tid: topic2Result.topicData.tid });
|
||||
});
|
||||
|
||||
it('should get sorted topics in category', (done) => {
|
||||
const filters = ['', 'watched', 'unreplied', 'new'];
|
||||
async.map(filters, (filter, next) => {
|
||||
topics.getSortedTopics({
|
||||
cids: [topic.categoryId],
|
||||
cids: [category.cid],
|
||||
uid: topic.userId,
|
||||
start: 0,
|
||||
stop: -1,
|
||||
@@ -2539,5 +2548,28 @@ describe('Topic\'s', function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('should get topics recent replied first', async () => {
|
||||
const data = await topics.getSortedTopics({
|
||||
cids: [category.cid],
|
||||
uid: topic.userId,
|
||||
start: 0,
|
||||
stop: -1,
|
||||
sort: 'recent',
|
||||
});
|
||||
assert.strictEqual(data.topics[0].title, 'most recent replied');
|
||||
assert.strictEqual(data.topics[1].title, 'old replied');
|
||||
});
|
||||
|
||||
it('should get topics recent replied last', async () => {
|
||||
const data = await topics.getSortedTopics({
|
||||
cids: [category.cid],
|
||||
uid: topic.userId,
|
||||
start: 0,
|
||||
stop: -1,
|
||||
sort: 'old',
|
||||
});
|
||||
assert.strictEqual(data.topics[0].title, 'old replied');
|
||||
assert.strictEqual(data.topics[1].title, 'most recent replied');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -135,16 +135,6 @@ describe('new Translator(language)', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should translate escaped translation arguments properly', function () {
|
||||
// https://github.com/NodeBB/NodeBB/issues/9206
|
||||
var translator = Translator.create('en-GB');
|
||||
|
||||
var key = '[[notifications:upvoted_your_post_in, test1, error: Error: [[error:group-name-too-long]] on NodeBB Upgrade]]';
|
||||
return translator.translate(key).then(function (translated) {
|
||||
assert.strictEqual(translated, '<strong>test1</strong> has upvoted your post in <strong>error: Error: [[error:group-name-too-long]] on NodeBB Upgrade</strong>.');
|
||||
});
|
||||
});
|
||||
|
||||
it('should properly escape and ignore % and \\, in arguments', function () {
|
||||
var translator = Translator.create('en-GB');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user