From 7ca8c4591f67e7eef3458f2056509340a38c562e Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sat, 31 May 2025 19:02:35 +0300 Subject: [PATCH] Allow swipe right to generate first message in non-pristine chats Fixes #4074 --- public/script.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/public/script.js b/public/script.js index c40a6cf32..10bd33afc 100644 --- a/public/script.js +++ b/public/script.js @@ -9377,13 +9377,13 @@ export function swipe_left(_event, { source, repeated } = {}) { /** * Handles the swipe to the right event. - * @param {JQuery.Event} _event Event. + * @param {JQuery.Event} [_event] Event. * @param {object} params Additional parameters. * @param {string} [params.source] The source of the swipe event. * @param {boolean} [params.repeated] Is the swipe event repeated. */ //MARK: swipe_right -export function swipe_right(_event, { source, repeated } = {}) { +export function swipe_right(_event = null, { source, repeated } = {}) { if (chat.length - 1 === Number(this_edit_mes_id)) { closeMessageEditor(); } @@ -9395,6 +9395,7 @@ export function swipe_right(_event, { source, repeated } = {}) { // Make sure ad-hoc changes to extras are saved before swiping away syncMesToSwipe(); + const isPristine = !chat_metadata?.tainted; const swipe_duration = 200; const swipe_range = 700; //console.log(swipe_range); @@ -9413,14 +9414,16 @@ export function swipe_right(_event, { source, repeated } = {}) { }; //assign swipe info array with last message from chat } - if (chat.length === 1 && chat[0]['swipe_id'] !== undefined && chat[0]['swipe_id'] === chat[0]['swipes'].length - 1) { // if swipe_right is called on the last alternate greeting, loop back around + // if swipe_right is called on the last alternate greeting in pristine chats, loop back around + if (chat.length === 1 && chat[0]['swipe_id'] !== undefined && chat[0]['swipe_id'] === chat[0]['swipes'].length - 1 && isPristine) { chat[0]['swipe_id'] = 0; } else { // If the user is holding down the key and we're at the last swipe, don't do anything if (source === 'keyboard' && repeated && chat[chat.length - 1].swipe_id === chat[chat.length - 1].swipes.length - 1) { return; } - chat[chat.length - 1]['swipe_id']++; // make new slot in array + // make new slot in array + chat[chat.length - 1]['swipe_id']++; } if (chat[chat.length - 1].extra) { // if message has memory attached - remove it to allow regen @@ -9435,8 +9438,8 @@ export function swipe_right(_event, { source, repeated } = {}) { if (!Array.isArray(chat[chat.length - 1]['swipe_info'])) { chat[chat.length - 1]['swipe_info'] = []; } - //console.log(chat[chat.length-1]['swipes']); - if (parseInt(chat[chat.length - 1]['swipe_id']) === chat[chat.length - 1]['swipes'].length && chat.length !== 1) { //if swipe id of last message is the same as the length of the 'swipes' array and not the greeting + //if swipe id of last message is the same as the length of the 'swipes' array and not the greeting + if (parseInt(chat[chat.length - 1]['swipe_id']) === chat[chat.length - 1]['swipes'].length && (chat.length !== 1 || !isPristine)) { delete chat[chat.length - 1].gen_started; delete chat[chat.length - 1].gen_finished; run_generate = true;