Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions public/language/en-GB/topic.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
"share": "Share",
"tools": "Tools",
"locked": "Locked",
"resolved": "Resolved",
"unresolved": "Unresolved",
"pinned": "Pinned",
"pinned-with-expiry": "Pinned until %1",
"scheduled": "Scheduled",
Expand Down Expand Up @@ -115,6 +117,8 @@
"thread-tools.unpin": "Unpin Topic",
"thread-tools.lock": "Lock Topic",
"thread-tools.unlock": "Unlock Topic",
"thread-tools.resolve": "Mark Resolved",
"thread-tools.unresolve": "Mark Unresolved",
"thread-tools.move": "Move Topic",
"thread-tools.crosspost": "Crosspost Topic",
"thread-tools.move-posts": "Move Posts",
Expand Down
4 changes: 3 additions & 1 deletion public/language/en-GB/unread.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@
"new-topics": "New Topics",
"watched-topics": "Watched Topics",
"unreplied-topics": "Unreplied Topics",
"resolved-topics": "Resolved Topics",
"unresolved-topics": "Unresolved Topics",
"multiple-categories-selected": "Multiple Selected"
}
}
6 changes: 5 additions & 1 deletion public/language/en-US/topic.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
"share": "Share",
"tools": "Tools",
"locked": "Locked",
"resolved": "Resolved",
"unresolved": "Unresolved",
"pinned": "Pinned",
"pinned-with-expiry": "Pinned until %1",
"scheduled": "Scheduled",
Expand Down Expand Up @@ -102,6 +104,8 @@
"thread-tools.unpin": "Unpin Topic",
"thread-tools.lock": "Lock Topic",
"thread-tools.unlock": "Unlock Topic",
"thread-tools.resolve": "Mark Resolved",
"thread-tools.unresolve": "Mark Unresolved",
"thread-tools.move": "Move Topic",
"thread-tools.crosspost": "Crosspost Topic",
"thread-tools.move-posts": "Move Posts",
Expand Down Expand Up @@ -231,4 +235,4 @@
"thumb-image": "Topic thumbnail image",
"announcers": "Shares",
"announcers-x": "Shares (%1)"
}
}
4 changes: 3 additions & 1 deletion public/language/en-US/unread.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@
"new-topics": "New Topics",
"watched-topics": "Watched Topics",
"unreplied-topics": "Unreplied Topics",
"resolved-topics": "Resolved Topics",
"unresolved-topics": "Unresolved Topics",
"multiple-categories-selected": "Multiple Selected"
}
}
4 changes: 3 additions & 1 deletion public/openapi/write.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ paths:
$ref: 'write/topics/tid/state.yaml'
/topics/{tid}/lock:
$ref: 'write/topics/tid/lock.yaml'
/topics/{tid}/resolve:
$ref: 'write/topics/tid/resolve.yaml'
/topics/{tid}/pin:
$ref: 'write/topics/tid/pin.yaml'
/topics/{tid}/follow:
Expand Down Expand Up @@ -287,4 +289,4 @@ paths:
/files/:
$ref: 'write/files.yaml'
/files/folder:
$ref: 'write/files/folder.yaml'
$ref: 'write/files/folder.yaml'
52 changes: 52 additions & 0 deletions public/openapi/write/topics/tid/resolve.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
put:
tags:
- topics
summary: mark a topic as resolved
description: This operation marks an existing Q&A topic as resolved.
parameters:
- in: path
name: tid
schema:
type: string
required: true
description: a valid topic id
example: 1
responses:
'200':
description: Topic successfully marked as resolved
content:
application/json:
schema:
type: object
properties:
status:
$ref: ../../../components/schemas/Status.yaml#/Status
response:
type: object
properties: {}
delete:
tags:
- topics
summary: mark a topic as unresolved
description: This operation marks an existing Q&A topic as unresolved.
parameters:
- in: path
name: tid
schema:
type: string
required: true
description: a valid topic id
example: 1
responses:
'200':
description: Topic successfully marked as unresolved
content:
application/json:
schema:
type: object
properties:
status:
$ref: ../../../components/schemas/Status.yaml#/Status
response:
type: object
properties: {}
12 changes: 12 additions & 0 deletions public/src/client/category/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ define('forum/category/tools', [
socket.on('event:topic_unlocked', setLockedState);
socket.on('event:topic_pinned', setPinnedState);
socket.on('event:topic_unpinned', setPinnedState);
socket.on('event:topic_resolved', setResolvedState);
socket.on('event:topic_unresolved', setResolvedState);
socket.on('event:topic_moved', onTopicMoved);
};

Expand Down Expand Up @@ -182,6 +184,8 @@ define('forum/category/tools', [
socket.removeListener('event:topic_unlocked', setLockedState);
socket.removeListener('event:topic_pinned', setPinnedState);
socket.removeListener('event:topic_unpinned', setPinnedState);
socket.removeListener('event:topic_resolved', setResolvedState);
socket.removeListener('event:topic_unresolved', setResolvedState);
socket.removeListener('event:topic_moved', onTopicMoved);
};

Expand Down Expand Up @@ -284,6 +288,14 @@ define('forum/category/tools', [
topic.find('[component="topic/locked"]').toggleClass('hidden', !data.isLocked);
}

function setResolvedState(data) {
const topic = getTopicEl(data.tid);
const isResolved = !!(data.isResolved || parseInt(data.resolved, 10) === 1);
topic.toggleClass('resolved', isResolved);
topic.find('[component="topic/resolved"]').toggleClass('hidden', !isResolved);
topic.find('[component="topic/unresolved"]').toggleClass('hidden', isResolved);
}

async function onTopicMoved(data) {
if (ajaxify.data.template.category || String(data.toCid) === '-1') {
getTopicEl(data.tid).remove();
Expand Down
3 changes: 3 additions & 0 deletions public/src/client/topic/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ define('forum/topic/events', [
'event:topic_pinned': threadTools.setPinnedState,
'event:topic_unpinned': threadTools.setPinnedState,

'event:topic_resolved': threadTools.setResolvedState,
'event:topic_unresolved': threadTools.setResolvedState,

'event:topic_moved': onTopicMoved,

'event:post_edited': onPostEdited,
Expand Down
25 changes: 25 additions & 0 deletions public/src/client/topic/threadTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ define('forum/topic/threadTools', [
return false;
});

topicContainer.on('click', '[component="topic/resolve"]', function () {
topicCommand('put', '/resolve', 'resolve');
return false;
});

topicContainer.on('click', '[component="topic/unresolve"]', function () {
topicCommand('del', '/resolve', 'unresolve');
return false;
});

topicContainer.on('click', '[component="topic/pin"]', function () {
topicCommand('put', '/pin', 'pin');
return false;
Expand Down Expand Up @@ -394,6 +404,21 @@ define('forum/topic/threadTools', [
posts.addTopicEvents(data.events);
};

ThreadTools.setResolvedState = function (data) {
const threadEl = components.get('topic');
if (String(data.tid) !== threadEl.attr('data-tid')) {
return;
}

const isResolved = !!(data.isResolved || parseInt(data.resolved, 10) === 1);
components.get('topic/resolve').toggleClass('hidden', isResolved).parent().attr('hidden', isResolved ? '' : null);
components.get('topic/unresolve').toggleClass('hidden', !isResolved).parent().attr('hidden', !isResolved ? '' : null);

$('[component="topic/labels"] [component="topic/resolved"]').toggleClass('hidden', !isResolved);
$('[component="topic/labels"] [component="topic/unresolved"]').toggleClass('hidden', isResolved);
ajaxify.data.resolved = isResolved ? 1 : 0;
};

function setFollowState(state) {
const titles = {
follow: '[[topic:watching]]',
Expand Down
12 changes: 12 additions & 0 deletions src/api/topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,18 @@ topicsAPI.unlock = async function (caller, data) {
});
};

topicsAPI.resolve = async function (caller, data) {
await doTopicAction('resolve', 'event:topic_resolved', caller, {
tids: data.tids,
});
};

topicsAPI.unresolve = async function (caller, data) {
await doTopicAction('unresolve', 'event:topic_unresolved', caller, {
tids: data.tids,
});
};

topicsAPI.follow = async function (caller, data) {
await topics.follow(data.tid, caller.uid);
};
Expand Down
22 changes: 20 additions & 2 deletions src/controllers/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ helpers.addLinkTags = function (params) {
});
};

helpers.buildFilters = function (url, filter, query) {
return [{
helpers.buildFilters = function (url, filter, query, options = {}) {
const filters = [{
name: '[[unread:all-topics]]',
url: url + helpers.buildQueryString(query, 'filter', ''),
selected: filter === '',
Expand All @@ -96,6 +96,24 @@ helpers.buildFilters = function (url, filter, query) {
filter: 'unreplied',
icon: 'fa-reply',
}];

if (options.includeQandAFilters) {
filters.push({
name: '[[unread:resolved-topics]]',
url: url + helpers.buildQueryString(query, 'filter', 'resolved'),
selected: filter === 'resolved',
filter: 'resolved',
icon: 'fa-check-circle',
}, {
name: '[[unread:unresolved-topics]]',
url: url + helpers.buildQueryString(query, 'filter', 'unresolved'),
selected: filter === 'unresolved',
filter: 'unresolved',
icon: 'fa-question-circle',
});
}

return filters;
};

helpers.buildTerms = function (url, term, query) {
Expand Down
4 changes: 3 additions & 1 deletion src/controllers/recent.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ recentController.getData = async function (req, url, sort, selectedTerm = 'allti
}
}

data.filters = helpers.buildFilters(baseUrl, filter, query);
data.filters = helpers.buildFilters(baseUrl, filter, query, {
includeQandAFilters: true,
});
data.selectedFilter = data.filters.find(filter => filter && filter.selected);
data.terms = helpers.buildTerms(baseUrl, term, query);
data.selectedTerm = data.terms.find(term => term && term.selected);
Expand Down
4 changes: 3 additions & 1 deletion src/controllers/unread.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ unreadController.get = async function (req, res) {
data.showCategorySelectLabel = true;
data.selectedTag = tagData.selectedTag;
data.selectedTags = tagData.selectedTags;
data.filters = helpers.buildFilters(baseUrl, filter, req.query);
data.filters = helpers.buildFilters(baseUrl, filter, req.query, {
includeQandAFilters: true,
});
data.selectedFilter = data.filters.find(filter => filter && filter.selected);
data['reputation:disabled'] = meta.config['reputation:disabled'];

Expand Down
10 changes: 10 additions & 0 deletions src/controllers/write/topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ Topics.unlock = async (req, res) => {
helpers.formatApiResponse(200, res);
};

Topics.resolve = async (req, res) => {
await api.topics.resolve(req, { tids: [req.params.tid] });
helpers.formatApiResponse(200, res);
};

Topics.unresolve = async (req, res) => {
await api.topics.unresolve(req, { tids: [req.params.tid] });
helpers.formatApiResponse(200, res);
};

Topics.follow = async (req, res) => {
await api.topics.follow(req, req.params);
helpers.formatApiResponse(200, res);
Expand Down
2 changes: 2 additions & 0 deletions src/routes/write/topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ module.exports = function () {

setupApiRoute(router, 'put', '/:tid/lock', [...middlewares], controllers.write.topics.lock);
setupApiRoute(router, 'delete', '/:tid/lock', [...middlewares], controllers.write.topics.unlock);
setupApiRoute(router, 'put', '/:tid/resolve', [...middlewares], controllers.write.topics.resolve);
setupApiRoute(router, 'delete', '/:tid/resolve', [...middlewares], controllers.write.topics.unresolve);

setupApiRoute(router, 'put', '/:tid/follow', [...middlewares, middleware.assert.topic], controllers.write.topics.follow);
setupApiRoute(router, 'delete', '/:tid/follow', [...middlewares, middleware.assert.topic], controllers.write.topics.unfollow);
Expand Down
2 changes: 2 additions & 0 deletions src/socket.io/topics/tools.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const topics = require('../../topics');
const categories = require('../../categories');
const privileges = require('../../privileges');
const plugins = require('../../plugins');

Expand All @@ -21,6 +22,7 @@ module.exports = function (SocketTopics) {
if (!userPrivileges['topics:read'] || !userPrivileges.view_thread_tools) {
throw new Error('[[error:no-privileges]]');
}
topicData.isQandA = await categories.isQandACategory(topicData.cid);
topicData.privileges = userPrivileges;
const result = await plugins.hooks.fire('filter:topic.thread_tools', {
topic: topicData,
Expand Down
23 changes: 20 additions & 3 deletions src/topics/sorted.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ module.exports = function (Topics) {
}

tids = await privileges.topics.filterTids('topics:read', tids, uid);
let topicData = await Topics.getTopicsFields(tids, ['uid', 'tid', 'cid', 'tags']);
let topicData = await Topics.getTopicsFields(tids, ['uid', 'tid', 'cid', 'tags', 'resolved']);
const topicCids = _.uniq(topicData.map(topic => topic.cid)).filter(Boolean);

async function getIgnoredCids() {
Expand All @@ -263,23 +263,40 @@ module.exports = function (Topics) {
}
return await categories.isIgnored(topicCids, uid);
}
const [ignoredCids, filtered] = await Promise.all([
async function getQandACidsMap() {
const categoryData = await categories.getCategoriesFields(topicCids, ['cid', 'isQandA']);
return _.zipObject(
topicCids,
categoryData.map(category => category && parseInt(category.isQandA, 10) === 1)
);
}
const [ignoredCids, filtered, qandaCidsMap] = await Promise.all([
getIgnoredCids(),
user.blocks.filter(uid, topicData),
getQandACidsMap(),
]);

const isCidIgnored = _.zipObject(topicCids, ignoredCids);
topicData = filtered;

const cids = params.cids && params.cids.map(String);
const { tags } = params;
const filterResolved = filter === 'resolved';
const filterUnresolved = filter === 'unresolved';
tids = topicData.filter(t => (
t &&
t.cid &&
!isCidIgnored[t.cid] &&
(cids || parseInt(t.cid, 10) !== -1) &&
(!cids || cids.includes(String(t.cid))) &&
(!tags.length || tags.every(tag => t.tags.find(topicTag => topicTag.value === tag)))
(!tags.length || tags.every(tag => t.tags.find(topicTag => topicTag.value === tag))) &&
(
(!filterResolved && !filterUnresolved) ||
(qandaCidsMap[t.cid] && (
(filterResolved && parseInt(t.resolved, 10) === 1) ||
(filterUnresolved && parseInt(t.resolved, 10) !== 1)
))
)
)).map(t => t.tid);

const result = await plugins.hooks.fire('filter:topics.filterSortedTids', {
Expand Down
Loading