Skip to content

Commit

Permalink
feat: add tools to recent/unread (#8477)
Browse files Browse the repository at this point in the history
* feat: add tools to recent/unread

* fix: open api spec

* fix: more api spec
  • Loading branch information
barisusakli committed Jul 8, 2020
1 parent 14eafcb commit 658dd03
Show file tree
Hide file tree
Showing 16 changed files with 139 additions and 50 deletions.
32 changes: 32 additions & 0 deletions public/openapi/read.yaml
Expand Up @@ -3810,6 +3810,10 @@ paths:
type: number
canPost:
type: boolean
showSelect:
type: boolean
showTopicTools:
type: boolean
categories:
type: array
items:
Expand Down Expand Up @@ -3871,6 +3875,8 @@ paths:
type: boolean
filter:
type: string
icon:
type: string
selectedFilter:
type: object
properties:
Expand All @@ -3882,6 +3888,8 @@ paths:
type: boolean
filter:
type: string
icon:
type: string
terms:
type: array
items:
Expand Down Expand Up @@ -3946,6 +3954,8 @@ paths:
properties:
showSelect:
type: boolean
showTopicTools:
type: boolean
nextStart:
type: number
topics:
Expand Down Expand Up @@ -4199,6 +4209,8 @@ paths:
type: boolean
filter:
type: string
icon:
type: string
selectedFilter:
type: object
properties:
Expand All @@ -4210,6 +4222,8 @@ paths:
type: boolean
filter:
type: string
icon:
type: string
- $ref: components/schemas/Pagination.yaml#/Pagination
- $ref: components/schemas/Breadcrumbs.yaml#/Breadcrumbs
- $ref: components/schemas/CommonProps.yaml#/CommonProps
Expand Down Expand Up @@ -5492,6 +5506,10 @@ paths:
type: number
canPost:
type: boolean
showSelect:
type: boolean
showTopicTools:
type: boolean
categories:
type: array
items:
Expand Down Expand Up @@ -5553,6 +5571,8 @@ paths:
type: boolean
filter:
type: string
icon:
type: string
selectedFilter:
type: object
properties:
Expand All @@ -5564,6 +5584,8 @@ paths:
type: boolean
filter:
type: string
icon:
type: string
terms:
type: array
items:
Expand Down Expand Up @@ -5620,6 +5642,10 @@ paths:
type: number
canPost:
type: boolean
showSelect:
type: boolean
showTopicTools:
type: boolean
categories:
type: array
items:
Expand Down Expand Up @@ -5694,6 +5720,8 @@ paths:
type: boolean
filter:
type: string
icon:
type: string
selectedFilter:
type: object
properties:
Expand All @@ -5705,6 +5733,8 @@ paths:
type: boolean
filter:
type: string
icon:
type: string
terms:
type: array
items:
Expand Down Expand Up @@ -5817,6 +5847,8 @@ paths:
type: boolean
showSelect:
type: boolean
showTopicTools:
type: boolean
rssFeedUrl:
type: string
feeds:disableRSS:
Expand Down
12 changes: 1 addition & 11 deletions public/src/client/category.js
Expand Up @@ -4,34 +4,24 @@ define('forum/category', [
'forum/infinitescroll',
'share',
'navigator',
'forum/category/tools',
'topicList',
'sort',
], function (infinitescroll, share, navigator, categoryTools, topicList, sort) {
], function (infinitescroll, share, navigator, topicList, sort) {
var Category = {};

$(window).on('action:ajaxify.start', function (ev, data) {
if (!String(data.url).startsWith('category/')) {
navigator.disable();

removeListeners();
}
});

function removeListeners() {
categoryTools.removeListeners();
topicList.removeListeners();
}

Category.init = function () {
var cid = ajaxify.data.cid;

app.enterRoom('category_' + cid);

share.addShareHandlers(ajaxify.data.name);

categoryTools.init(cid);

topicList.init('category', loadTopicsAfter);

sort.handleSort('categoryTopicSort', 'user.setCategorySort', 'category/' + ajaxify.data.slug);
Expand Down
24 changes: 13 additions & 11 deletions public/src/client/category/tools.js
Expand Up @@ -9,9 +9,7 @@ define('forum/category/tools', [
], function (topicSelect, components, translator) {
var CategoryTools = {};

CategoryTools.init = function (cid) {
CategoryTools.cid = cid;

CategoryTools.init = function () {
topicSelect.init(updateDropdownOptions);

handlePinnedTopicSort();
Expand All @@ -36,7 +34,7 @@ define('forum/category/tools', [
if (!tids.length) {
return app.alertError('[[error:no-topics-selected]]');
}
socket.emit('topics.lock', { tids: tids, cid: CategoryTools.cid }, onCommandComplete);
socket.emit('topics.lock', { tids: tids }, onCommandComplete);
return false;
});

Expand All @@ -45,7 +43,7 @@ define('forum/category/tools', [
if (!tids.length) {
return app.alertError('[[error:no-topics-selected]]');
}
socket.emit('topics.unlock', { tids: tids, cid: CategoryTools.cid }, onCommandComplete);
socket.emit('topics.unlock', { tids: tids }, onCommandComplete);
return false;
});

Expand All @@ -54,7 +52,7 @@ define('forum/category/tools', [
if (!tids.length) {
return app.alertError('[[error:no-topics-selected]]');
}
socket.emit('topics.pin', { tids: tids, cid: CategoryTools.cid }, onCommandComplete);
socket.emit('topics.pin', { tids: tids }, onCommandComplete);
return false;
});

Expand All @@ -63,7 +61,7 @@ define('forum/category/tools', [
if (!tids.length) {
return app.alertError('[[error:no-topics-selected]]');
}
socket.emit('topics.unpin', { tids: tids, cid: CategoryTools.cid }, onCommandComplete);
socket.emit('topics.unpin', { tids: tids }, onCommandComplete);
return false;
});

Expand Down Expand Up @@ -92,13 +90,17 @@ define('forum/category/tools', [
if (!tids.length) {
return app.alertError('[[error:no-topics-selected]]');
}
move.init(tids, cid, onCommandComplete);
move.init(tids, null, onCommandComplete);
});

return false;
});

components.get('topic/move-all').on('click', function () {
var cid = ajaxify.data.cid;
if (!ajaxify.data.template.category) {
return app.alertError('[[error:invalid-data]]');
}
require(['forum/topic/move'], function (move) {
move.init(null, cid, function (err) {
if (err) {
Expand All @@ -110,7 +112,7 @@ define('forum/category/tools', [
});
});

$('.category').on('click', '[component="topic/merge"]', function () {
components.get('topic/merge').on('click', function () {
require(['forum/topic/merge'], function (merge) {
merge.init();
});
Expand Down Expand Up @@ -138,7 +140,7 @@ define('forum/category/tools', [
return;
}

socket.emit('topics.' + command, { tids: tids, cid: CategoryTools.cid }, onDeletePurgeComplete);
socket.emit('topics.' + command, { tids: tids }, onDeletePurgeComplete);
});
});
}
Expand Down Expand Up @@ -259,7 +261,7 @@ define('forum/category/tools', [
return memo;
}, 0);

if (!ajaxify.data.privileges.isAdminOrMod || numPinned < 2) {
if ((!app.user.isAdmin && !app.user.isMod) || numPinned < 2) {
return;
}

Expand Down
6 changes: 5 additions & 1 deletion public/src/modules/topicList.js
Expand Up @@ -5,7 +5,8 @@ define('topicList', [
'handleBack',
'topicSelect',
'categorySearch',
], function (infinitescroll, handleBack, topicSelect, categorySearch) {
'forum/category/tools',
], function (infinitescroll, handleBack, topicSelect, categorySearch, categoryTools) {
var TopicList = {};
var templateName = '';

Expand All @@ -24,6 +25,7 @@ define('topicList', [

$(window).on('action:ajaxify.start', function () {
TopicList.removeListeners();
categoryTools.removeListeners();
});

TopicList.init = function (template, cb) {
Expand All @@ -32,6 +34,8 @@ define('topicList', [
templateName = template;
loadTopicsCallback = cb || loadTopicsAfter;

categoryTools.init();

TopicList.watchForNewPosts();

TopicList.handleCategorySelection();
Expand Down
3 changes: 3 additions & 0 deletions src/categories/delete.js
Expand Up @@ -32,6 +32,9 @@ module.exports = function (Categories) {
'cid:' + cid + ':tids',
'cid:' + cid + ':tids:pinned',
'cid:' + cid + ':tids:posts',
'cid:' + cid + ':tids:votes',
'cid:' + cid + ':tids:lastposttime',
'cid:' + cid + ':recent_tids',
'cid:' + cid + ':pids',
'cid:' + cid + ':read_by_uid',
'cid:' + cid + ':uid:watch:state',
Expand Down
1 change: 1 addition & 0 deletions src/controllers/category.js
Expand Up @@ -95,6 +95,7 @@ categoryController.get = async function (req, res, next) {
categoryData.description = translator.escape(categoryData.description);
categoryData.privileges = userPrivileges;
categoryData.showSelect = userPrivileges.editable;
categoryData.showTopicTools = userPrivileges.editable;
categoryData.rssFeedUrl = nconf.get('url') + '/category/' + categoryData.cid + '.rss';
if (parseInt(req.uid, 10)) {
categories.markAsRead([cid], req.uid);
Expand Down
4 changes: 4 additions & 0 deletions src/controllers/helpers.js
Expand Up @@ -72,21 +72,25 @@ helpers.buildFilters = function (url, filter, query) {
url: url + helpers.buildQueryString(query.cid, '', query.term),
selected: filter === '',
filter: '',
icon: 'fa-book',
}, {
name: '[[unread:new-topics]]',
url: url + helpers.buildQueryString(query.cid, 'new', query.term),
selected: filter === 'new',
filter: 'new',
icon: 'fa-clock-o',
}, {
name: '[[unread:watched-topics]]',
url: url + helpers.buildQueryString(query.cid, 'watched', query.term),
selected: filter === 'watched',
filter: 'watched',
icon: 'fa-bell-o',
}, {
name: '[[unread:unreplied-topics]]',
url: url + helpers.buildQueryString(query.cid, 'unreplied', query.term),
selected: filter === 'unreplied',
filter: 'unreplied',
icon: 'fa-reply',
}];
};

Expand Down
5 changes: 4 additions & 1 deletion src/controllers/recent.js
Expand Up @@ -37,11 +37,12 @@ recentController.getData = async function (req, url, sort) {
states.push(categories.watchStates.ignoring);
}

const [settings, categoryData, rssToken, canPost] = await Promise.all([
const [settings, categoryData, rssToken, canPost, isPrivileged] = await Promise.all([
user.getSettings(req.uid),
helpers.getCategoriesByStates(req.uid, cid, states),
user.auth.getFeedToken(req.uid),
canPostTopic(req.uid),
user.isPrivileged(req.uid),
]);

const start = Math.max(0, (page - 1) * settings.topicsPerPage);
Expand All @@ -60,6 +61,8 @@ recentController.getData = async function (req, url, sort) {
});

data.canPost = canPost;
data.showSelect = isPrivileged;
data.showTopicTools = isPrivileged;
data.categories = categoryData.categories;
data.allCategoriesUrl = url + helpers.buildQueryString('', filter, '');
data.selectedCategory = categoryData.selectedCategory || null;
Expand Down
6 changes: 4 additions & 2 deletions src/controllers/unread.js
Expand Up @@ -22,9 +22,10 @@ unreadController.get = async function (req, res, next) {
if (!filterData.filters[filter]) {
return next();
}
const [watchedCategories, userSettings] = await Promise.all([
const [watchedCategories, userSettings, isPrivileged] = await Promise.all([
getWatchedCategories(req.uid, cid, filter),
user.getSettings(req.uid),
user.isPrivileged(req.uid),
]);

const page = parseInt(req.query.page, 10) || 1;
Expand All @@ -48,7 +49,8 @@ unreadController.get = async function (req, res, next) {
req.query.page = Math.max(1, Math.min(data.pageCount, page));
return helpers.redirect(res, '/unread?' + querystring.stringify(req.query));
}

data.showSelect = isPrivileged;
data.showTopicTools = isPrivileged;
data.categories = watchedCategories.categories;
data.allCategoriesUrl = 'unread' + helpers.buildQueryString('', filter, '');
data.selectedCategory = watchedCategories.selectedCategory;
Expand Down
5 changes: 2 additions & 3 deletions src/socket.io/helpers.js
Expand Up @@ -191,9 +191,8 @@ SocketHelpers.rescindUpvoteNotification = async function (pid, fromuid) {
websockets.in('uid_' + uid).emit('event:notifications.updateCount', count);
};

SocketHelpers.emitToTopicAndCategory = function (event, data) {
websockets.in('topic_' + data.tid).emit(event, data);
websockets.in('category_' + data.cid).emit(event, data);
SocketHelpers.emitToTopicAndCategory = async function (event, data, uids) {
uids.forEach(toUid => websockets.in('uid_' + toUid).emit(event, data));
};

require('../promisify')(SocketHelpers);

0 comments on commit 658dd03

Please sign in to comment.