changes for topic thumbs

This commit is contained in:
Barış Soner Uşaklı 2025-07-06 20:12:28 -04:00
parent 60215ca802
commit ab63f108fd
4 changed files with 17 additions and 40 deletions

View file

@ -201,6 +201,7 @@ define('composer', [
title: data.title || '',
body: data.body || '',
tags: data.tags || [],
thumbs: data.thumbs || [],
modified: !!((data.title && data.title.length) || (data.body && data.body.length)),
isMain: true,
};
@ -417,7 +418,7 @@ define('composer', [
handleHelp(postContainer);
handleSearch(postContainer);
focusElements(postContainer);
if (postData.action === 'posts.edit') {
if (postData.action === 'posts.edit' || postData.action === 'topics.post') {
composer.updateThumbCount(post_uuid, postContainer);
}

@ -736,6 +737,7 @@ define('composer', [
thumb: thumbEl.val() || '',
cid: categoryList.getSelectedCid(),
tags: tags.getTags(post_uuid),
thumbs: postData.thumbs || [],
timestamp: scheduler.getTimestamp(),
};
} else if (action === 'posts.reply') {
@ -756,7 +758,7 @@ define('composer', [
handle: handleEl ? handleEl.val() : undefined,
content: bodyEl.val(),
title: titleEl.val(),
thumb: thumbEl.val() || '',
thumbs: postData.thumbs || [],
tags: tags.getTags(post_uuid),
timestamp: scheduler.getTimestamp(),
};
@ -883,20 +885,12 @@ define('composer', [

composer.updateThumbCount = function (uuid, postContainer) {
const composerObj = composer.posts[uuid];
if (composerObj.action === 'topics.post' || (composerObj.action === 'posts.edit' && composerObj.isMain)) {
const calls = [
topicThumbs.get(uuid),
];
if (composerObj.pid) {
calls.push(topicThumbs.getByPid(composerObj.pid));
}
Promise.all(calls).then((thumbs) => {
const thumbCount = thumbs.flat().length;
const formatEl = postContainer.find('[data-format="thumbs"]');
formatEl.find('.badge')
.text(thumbCount)
.toggleClass('hidden', !thumbCount);
});
if (composerObj && (composerObj.action === 'topics.post' || (composerObj.action === 'posts.edit' && composerObj.isMain))) {
const thumbCount = composerObj.thumbs ? composerObj.thumbs.length : 0;
const formatEl = postContainer.find('[data-format="thumbs"]');
formatEl.find('.badge')
.text(thumbCount)
.toggleClass('hidden', !thumbCount);
}
};


View file

@ -41,7 +41,6 @@ define('composer/drafts', ['api', 'alerts'], function (api, alerts) {
});

drafts.migrateGuest();
drafts.migrateThumbs(...arguments);
};

function getStorage(uid) {
@ -100,6 +99,7 @@ define('composer/drafts', ['api', 'alerts'], function (api, alerts) {
draftData.tags = tags;
draftData.title = title;
draftData.cid = postData.cid;
draftData.thumbs = postData.thumbs || [];
} else if (postData.action === 'posts.reply') {
// new reply only
draftData.title = postData.title;
@ -108,6 +108,7 @@ define('composer/drafts', ['api', 'alerts'], function (api, alerts) {
} else if (postData.action === 'posts.edit') {
draftData.pid = postData.pid;
draftData.title = title || postData.title;
draftData.thumbs = postData.thumbs || [];
}
if (!app.user.uid) {
draftData.handle = postContainer.find('input.handle').val();
@ -208,26 +209,6 @@ define('composer/drafts', ['api', 'alerts'], function (api, alerts) {
}
};

drafts.migrateThumbs = function (postContainer, postData) {
if (!app.uid) {
return;
}

// If any thumbs were uploaded, migrate them to this new composer's uuid
const newUUID = postContainer.attr('data-uuid');
const draft = drafts.get(postData.save_id);

if (draft && draft.uuid) {
api.put(`/topics/${draft.uuid}/thumbs`, {
tid: newUUID,
}).then(() => {
require(['composer'], function (composer) {
composer.updateThumbCount(newUUID, postContainer);
});
});
}
};

drafts.listAvailable = function () {
const available = drafts.getList('available');
return available.map(drafts.get).filter(Boolean);
@ -286,6 +267,7 @@ define('composer/drafts', ['api', 'alerts'], function (api, alerts) {
title: utils.escapeHTML(draft.title),
body: draft.text,
tags: String(draft.tags || '').split(','),
thumbs: draft.thumbs || [],
});
} else if (draft.action === 'posts.reply') {
api.get('/topics/' + draft.tid, {}, function (err, topicObj) {
@ -307,6 +289,7 @@ define('composer/drafts', ['api', 'alerts'], function (api, alerts) {
pid: draft.pid,
title: draft.title ? utils.escapeHTML(draft.title) : undefined,
body: draft.text,
thumbs: draft.thumbs || [],
});
}
});

View file

@ -28,8 +28,8 @@ define('composer/formatting', [
const composerObj = composer.posts[uuid];

if (composerObj.action === 'topics.post' || (composerObj.action === 'posts.edit' && composerObj.isMain)) {
topicThumbs.modal.open({ id: uuid, pid: composerObj.pid }).then(() => {
postContainer.trigger('thumb.uploaded'); // toggle draft save
topicThumbs.modal.open({ id: uuid, postData: composerObj }).then(() => {
postContainer.trigger('thumb.uploaded');

// Update client-side with count
composer.updateThumbCount(uuid, postContainer);

View file

@ -34,7 +34,7 @@ Sockets.push = async function (socket, pid) {
handle: parseInt(meta.config.allowGuestHandles, 10) ? postData.handle : undefined,
body: postData.sourceContent || postData.content,
title: topic.title,
thumb: topic.thumb,
thumbs: topic.thumbs,
tags: topic.tags.map(t => t.value),
isMain: isMain,
timestamp: postData.timestamp,