Fix syncMesToSwipe checks

Ported from #3634
This commit is contained in:
Cohee
2025-03-08 22:33:26 +02:00
parent 50a0f41736
commit ca14352972

View File

@@ -6148,13 +6148,17 @@ export function syncMesToSwipe(messageId = null) {
} }
const targetMessageId = messageId ?? chat.length - 1; const targetMessageId = messageId ?? chat.length - 1;
if (chat.length > targetMessageId || targetMessageId < 0) { if (targetMessageId >= chat.length || targetMessageId < 0) {
console.warn(`[syncMesToSwipe] Invalid message ID: ${messageId}`); console.warn(`[syncMesToSwipe] Invalid message ID: ${messageId}`);
return false; return false;
} }
const targetMessage = chat[targetMessageId]; const targetMessage = chat[targetMessageId];
if (!targetMessage) {
return false;
}
// No swipe data there yet, exit out // No swipe data there yet, exit out
if (typeof targetMessage.swipe_id !== 'number') { if (typeof targetMessage.swipe_id !== 'number') {
return false; return false;