diff --git a/public/src/client/topic/threadTools.js b/public/src/client/topic/threadTools.js index 6a6b03d372..44ab7a170c 100644 --- a/public/src/client/topic/threadTools.js +++ b/public/src/client/topic/threadTools.js @@ -311,10 +311,17 @@ define('forum/topic/threadTools', [ return; } - components.get('topic/pin').toggleClass('hidden', data.isPinned).parent().attr('hidden', data.isPinned ? '' : null); - components.get('topic/unpin').toggleClass('hidden', !data.isPinned).parent().attr('hidden', !data.isPinned ? '' : null); - $('.topic-header [component="topic/pinned"]').toggleClass('hidden', !data.isPinned); - ajaxify.data.pinned = data.isPinned; + components.get('topic/pin').toggleClass('hidden', data.pinned).parent().attr('hidden', data.pinned ? '' : null); + components.get('topic/unpin').toggleClass('hidden', !data.pinned).parent().attr('hidden', !data.pinned ? '' : null); + var icon = $('.topic-header [component="topic/pinned"]'); + icon.toggleClass('hidden', !data.pinned); + if (data.pinned) { + icon.translateAttr('title', data.pinExpiry && data.pinExpiryISO ? + '[[topic:pinned-with-expiry, ' + data.pinExpiryISO + ']]' : + '[[topic:pinned]]' + ); + } + ajaxify.data.pinned = data.pinned; }; function setFollowState(state) { diff --git a/src/controllers/write/topics.js b/src/controllers/write/topics.js index 81b06d01a0..0e16f0ebc5 100644 --- a/src/controllers/write/topics.js +++ b/src/controllers/write/topics.js @@ -37,12 +37,11 @@ Topics.purge = async (req, res) => { }; Topics.pin = async (req, res) => { - await api.topics.pin(req, { tids: [req.params.tid] }); - // Pin expiry was not available w/ sockets hence not included in api lib method if (req.body.expiry) { - topics.tools.setPinExpiry(req.params.tid, req.body.expiry, req.uid); + await topics.tools.setPinExpiry(req.params.tid, req.body.expiry, req.uid); } + await api.topics.pin(req, { tids: [req.params.tid] }); helpers.formatApiResponse(200, res); }; diff --git a/src/topics/tools.js b/src/topics/tools.js index 5ddad97c01..c25e5c6bc0 100644 --- a/src/topics/tools.js +++ b/src/topics/tools.js @@ -168,6 +168,8 @@ module.exports = function (Topics) { ['cid:' + topicData.cid + ':tids:posts', topicData.postcount, tid], ['cid:' + topicData.cid + ':tids:votes', parseInt(topicData.votes, 10) || 0, tid], ])); + topicData.pinExpiry = undefined; + topicData.pinExpiryISO = undefined; } await Promise.all(promises);