feat(topic-events): client-side handling on topic event log

v1.18.x
Julian Lam 4 years ago
parent df2fdd56ba
commit 8e93bf7362

@ -5,8 +5,9 @@ define('forum/topic/threadTools', [
'components',
'translator',
'handleBack',
'forum/topic/posts',
'api',
], function (components, translator, handleBack, api) {
], function (components, translator, handleBack, posts, api) {
var ThreadTools = {};
ThreadTools.init = function (tid, topicContainer) {
@ -271,6 +272,8 @@ define('forum/topic/threadTools', [
$('.topic-header [component="topic/locked"]').toggleClass('hidden', !data.isLocked);
$('[component="post/tools"] .dropdown-menu').html('');
ajaxify.data.locked = data.isLocked;
posts.addTopicEvents(data.events);
};
ThreadTools.setDeleteState = function (data) {
@ -302,6 +305,8 @@ define('forum/topic/threadTools', [
threadEl.toggleClass('deleted', data.isDelete);
ajaxify.data.deleted = data.isDelete ? 1 : 0;
posts.addTopicEvents(data.events);
};
@ -322,6 +327,8 @@ define('forum/topic/threadTools', [
);
}
ajaxify.data.pinned = data.pinned;
posts.addTopicEvents(data.events);
};
function setFollowState(state) {

@ -44,7 +44,7 @@ module.exports = function (Topics) {
} else {
await Topics.restore(data.topicData.tid);
}
await Topics.events.log(tid, { type: isDelete ? 'delete' : 'restore', uid });
const events = await Topics.events.log(tid, { type: isDelete ? 'delete' : 'restore', uid });
data.topicData.deleted = data.isDelete ? 1 : 0;
@ -60,6 +60,7 @@ module.exports = function (Topics) {
isDelete: data.isDelete,
uid: data.uid,
user: userData,
events,
};
}
@ -95,7 +96,7 @@ module.exports = function (Topics) {
throw new Error('[[error:no-privileges]]');
}
await Topics.setTopicField(tid, 'locked', lock ? 1 : 0);
await Topics.events.log(tid, { type: lock ? 'lock' : 'unlock', uid });
topicData.events = await Topics.events.log(tid, { type: lock ? 'lock' : 'unlock', uid });
topicData.isLocked = lock; // deprecate in v2.0
topicData.locked = lock;
@ -175,10 +176,11 @@ module.exports = function (Topics) {
topicData.pinExpiryISO = undefined;
}
await Promise.all(promises);
const results = await Promise.all(promises);
topicData.isPinned = pin; // deprecate in v2.0
topicData.pinned = pin;
topicData.events = results[1];
plugins.hooks.fire('action:topic.pin', { topic: _.clone(topicData), uid });

Loading…
Cancel
Save