more sanity checks for bookmark

dont allow setting bookmark higher than topic postcount
This commit is contained in:
Barış Soner Uşaklı
2023-02-15 22:06:00 -05:00
parent 54505e7a47
commit e4446ae14a
3 changed files with 3 additions and 3 deletions

View File

@@ -356,7 +356,7 @@ define('forum/topic', [
)
) {
if (app.user.uid) {
ajaxify.data.bookmark = index;
ajaxify.data.bookmark = Math.min(index, ajaxify.data.postcount);
socket.emit('topics.bookmark', {
tid: ajaxify.data.tid,

View File

@@ -355,7 +355,7 @@ define('navigator', ['forum/pagination', 'components', 'hooks', 'alerts', 'trans
return;
}
index = Math.max(index, ajaxify.data.bookmark);
index = Math.max(index, Math.min(ajaxify.data.bookmark, ajaxify.data.postcount));
const unreadEl = paginationBlockUnreadEl.get(0);
const trackEl = unreadEl.parentNode;
const trackHeight = trackEl.getBoundingClientRect().height;

View File

@@ -35,7 +35,7 @@ SocketTopics.bookmark = async function (socket, data) {
const postcount = await topics.getTopicField(data.tid, 'postcount');
if (data.index > meta.config.bookmarkThreshold && postcount > meta.config.bookmarkThreshold) {
const currentIndex = await db.sortedSetScore(`tid:${data.tid}:bookmarks`, socket.uid);
if (!currentIndex || data.index > currentIndex) {
if (!currentIndex || (data.index > currentIndex && data.index <= postcount) || (currentIndex > postcount)) {
await topics.setUserBookmark(data.tid, socket.uid, data.index);
}
}