Allow swipe right to generate first message in non-pristine chats Fixes #4074
| @@ -9377,13 +9377,13 @@ export function swipe_left(_event, { source, repeated } = {}) { | |||
| 9377 | 9377 | ||
| 9378 | /** | 9378 | /** |
| 9379 | * Handles the swipe to the right event. | 9379 | * Handles the swipe to the right event. |
| 9380 | * @param {JQuery.Event} _event Event. | 9380 | * @param {JQuery.Event} [_event] Event. |
| 9381 | * @param {object} params Additional parameters. | 9381 | * @param {object} params Additional parameters. |
| 9382 | * @param {string} [params.source] The source of the swipe event. | 9382 | * @param {string} [params.source] The source of the swipe event. |
| 9383 | * @param {boolean} [params.repeated] Is the swipe event repeated. | 9383 | * @param {boolean} [params.repeated] Is the swipe event repeated. |
| 9384 | */ | 9384 | */ |
| 9385 | //MARK: swipe_right | 9385 | //MARK: swipe_right |
| 9386 | export function swipe_right(_event, { source, repeated } = {}) { | 9386 | export function swipe_right(_event = null, { source, repeated } = {}) { |
| 9387 | if (chat.length - 1 === Number(this_edit_mes_id)) { | 9387 | if (chat.length - 1 === Number(this_edit_mes_id)) { |
| 9388 | closeMessageEditor(); | 9388 | closeMessageEditor(); |
| 9389 | } | 9389 | } |
| @@ -9395,6 +9395,7 @@ export function swipe_right(_event, { source, repeated } = {}) { | |||
| 9395 | // Make sure ad-hoc changes to extras are saved before swiping away | 9395 | // Make sure ad-hoc changes to extras are saved before swiping away |
| 9396 | syncMesToSwipe(); | 9396 | syncMesToSwipe(); |
| 9397 | 9397 | ||
| 9398 | const isPristine = !chat_metadata?.tainted; | ||
| 9398 | const swipe_duration = 200; | 9399 | const swipe_duration = 200; |
| 9399 | const swipe_range = 700; | 9400 | const swipe_range = 700; |
| 9400 | //console.log(swipe_range); | 9401 | //console.log(swipe_range); |
| @@ -9413,14 +9414,16 @@ export function swipe_right(_event, { source, repeated } = {}) { | |||
| 9413 | }; | 9414 | }; |
| 9414 | //assign swipe info array with last message from chat | 9415 | //assign swipe info array with last message from chat |
| 9415 | } | 9416 | } |
| 9416 | 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 | 9417 | // if swipe_right is called on the last alternate greeting in pristine chats, loop back around |
| 9418 | if (chat.length === 1 && chat[0]['swipe_id'] !== undefined && chat[0]['swipe_id'] === chat[0]['swipes'].length - 1 && isPristine) { | ||
| 9417 | chat[0]['swipe_id'] = 0; | 9419 | chat[0]['swipe_id'] = 0; |
| 9418 | } else { | 9420 | } else { |
| 9419 | // If the user is holding down the key and we're at the last swipe, don't do anything | 9421 | // If the user is holding down the key and we're at the last swipe, don't do anything |
| 9420 | if (source === 'keyboard' && repeated && chat[chat.length - 1].swipe_id === chat[chat.length - 1].swipes.length - 1) { | 9422 | if (source === 'keyboard' && repeated && chat[chat.length - 1].swipe_id === chat[chat.length - 1].swipes.length - 1) { |
| 9421 | return; | 9423 | return; |
| 9422 | } | 9424 | } |
| 9423 | chat[chat.length - 1]['swipe_id']++; // make new slot in array | 9425 | // make new slot in array |
| 9426 | chat[chat.length - 1]['swipe_id']++; | ||
| 9424 | } | 9427 | } |
| 9425 | if (chat[chat.length - 1].extra) { | 9428 | if (chat[chat.length - 1].extra) { |
| 9426 | // if message has memory attached - remove it to allow regen | 9429 | // if message has memory attached - remove it to allow regen |
| @@ -9435,8 +9438,8 @@ export function swipe_right(_event, { source, repeated } = {}) { | |||
| 9435 | if (!Array.isArray(chat[chat.length - 1]['swipe_info'])) { | 9438 | if (!Array.isArray(chat[chat.length - 1]['swipe_info'])) { |
| 9436 | chat[chat.length - 1]['swipe_info'] = []; | 9439 | chat[chat.length - 1]['swipe_info'] = []; |
| 9437 | } | 9440 | } |
| 9438 | //console.log(chat[chat.length-1]['swipes']); | 9441 | //if swipe id of last message is the same as the length of the 'swipes' array and not the greeting |
| 9439 | 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 | 9442 | if (parseInt(chat[chat.length - 1]['swipe_id']) === chat[chat.length - 1]['swipes'].length && (chat.length !== 1 || !isPristine)) { |
| 9440 | delete chat[chat.length - 1].gen_started; | 9443 | delete chat[chat.length - 1].gen_started; |
| 9441 | delete chat[chat.length - 1].gen_finished; | 9444 | delete chat[chat.length - 1].gen_finished; |
| 9442 | run_generate = true; | 9445 | run_generate = true; |