From a2e85eb1f0ef751f85404cf0194a019b9c36a51d Mon Sep 17 00:00:00 2001 From: Yuichi Oneda Date: Fri, 16 Aug 2024 00:01:35 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20fix:=20Bookmark=20Order=20Adjust?= =?UTF-8?q?ment=20When=20Moving=20Up=20(#3634)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/models/ConversationTag.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/api/models/ConversationTag.js b/api/models/ConversationTag.js index 0293ea83c31a..d64dcfa52137 100644 --- a/api/models/ConversationTag.js +++ b/api/models/ConversationTag.js @@ -133,14 +133,21 @@ const adjustPositions = async (user, oldPosition, newPosition) => { } const update = oldPosition < newPosition ? { $inc: { position: -1 } } : { $inc: { position: 1 } }; + const position = + oldPosition < newPosition + ? { + $gt: Math.min(oldPosition, newPosition), + $lte: Math.max(oldPosition, newPosition), + } + : { + $gte: Math.min(oldPosition, newPosition), + $lt: Math.max(oldPosition, newPosition), + }; await ConversationTag.updateMany( { user, - position: { - $gt: Math.min(oldPosition, newPosition), - $lte: Math.max(oldPosition, newPosition), - }, + position, }, update, );