MGLDZM commited on
Commit
253550d
·
1 Parent(s): fb6bee3
Files changed (1) hide show
  1. static/js/chatHandler.js +12 -4
static/js/chatHandler.js CHANGED
@@ -172,7 +172,7 @@ class ChatGPT{
172
  this.reintentos = 0;
173
  this.enviar(params.ctx, params.ctx.conversacion);
174
  });
175
- $(document).on("chat:salvar", (event, params) => this.salvarChats(params.index, params.conversacion, params.tokens))
176
  $(document).on("chat:eliminar", (event, params) => this.eliminarChat(params.ctx, params.index))
177
  $(document).on("mostrar:opciones", () => this.mostrarOpciones())
178
  $("#nuevoChat").on("click", () => this.crearChat())
@@ -189,12 +189,16 @@ class ChatGPT{
189
  return
190
  }
191
  for(let key in conversaciones){
 
 
 
192
  if(Object.keys(conversaciones[key]).indexOf('conversacion')!=-1){
193
  this.crearChat(key, conversaciones[key].conversacion)
194
  }else{
195
  this.crearChat(key, conversaciones[key])
196
  }
197
  }
 
198
 
199
  }
200
 
@@ -351,11 +355,15 @@ class ChatGPT{
351
 
352
  }
353
 
354
- salvarChats(index, conversacion, usedTokens){
355
  let conversaciones = {}
356
  try{conversaciones = JSON.parse(localStorage.getItem("conversaciones"))||{}}catch{}
357
- conversaciones[index] = conversacion
358
- localStorage.setItem("conversaciones", JSON.stringify(conversaciones))
 
 
 
 
359
  }
360
 
361
 
 
172
  this.reintentos = 0;
173
  this.enviar(params.ctx, params.ctx.conversacion);
174
  });
175
+ $(document).on("chat:salvar", (event, params) => this.salvarChats(params.index, params.conversacion))
176
  $(document).on("chat:eliminar", (event, params) => this.eliminarChat(params.ctx, params.index))
177
  $(document).on("mostrar:opciones", () => this.mostrarOpciones())
178
  $("#nuevoChat").on("click", () => this.crearChat())
 
189
  return
190
  }
191
  for(let key in conversaciones){
192
+ if(!conversaciones[key]){
193
+ continue
194
+ }
195
  if(Object.keys(conversaciones[key]).indexOf('conversacion')!=-1){
196
  this.crearChat(key, conversaciones[key].conversacion)
197
  }else{
198
  this.crearChat(key, conversaciones[key])
199
  }
200
  }
201
+ localStorage.setItem("conversaciones", JSON.stringify(conversaciones))
202
 
203
  }
204
 
 
355
 
356
  }
357
 
358
+ salvarChats(index, conversacion){
359
  let conversaciones = {}
360
  try{conversaciones = JSON.parse(localStorage.getItem("conversaciones"))||{}}catch{}
361
+ let temp = {}
362
+ for (let i in conversaciones){
363
+ temp[i]=conversaciones[i]
364
+ }
365
+ temp[index] = conversacion
366
+ localStorage.setItem("conversaciones", JSON.stringify(temp))
367
  }
368
 
369