To help you log all the data received by the agregarMensajeAlChat function with concise descriptors, you can populate the logInfo object with one-word keys representing each parameter. Here's how you can modify your code:
function agregarMensajeAlChat(mensajeTexto, clase, fecha, listaMensajes = document.querySelector('.listaMensajes'), fechaAnterior = null, insertAtTop = false, adjunto = null, temp_id = null, msgEmisor = null, isFirstMessageOfThread = false, userInfo = null, tipoMensaje = null, mensajeLeido = false) {
const fechaMensaje = new Date(fecha);
fechaAnterior = fechaAnterior || obtenerFechaAnterior(listaMensajes, insertAtTop);
manejarFecha(fechaMensaje, fechaAnterior, listaMensajes, insertAtTop);
const esUsuarioActual = msgEmisor === emisor;
const esColabPrimerMensaje = tipoMensaje === 'Colab' && isFirstMessageOfThread && userInfo && !esUsuarioActual;
const messageBlock = crearElemento('div', 'messageBlock');
const messageContainer = crearElemento('div', 'messageContainer');
const logInfo = {
mensaje: mensajeTexto,
clase: clase,
fecha: fecha,
lista: listaMensajes,
fechaAnt: fechaAnterior,
top: insertAtTop,
adjunto: adjunto,
tempId: temp_id,
emisorMsg: msgEmisor,
primerMsg: isFirstMessageOfThread,
usuario: userInfo,
tipo: tipoMensaje,
leido: mensajeLeido
};
console.log('[[agregarMensajeAlChat]]', logInfo);
// Rest of your function...
}
Explanation:
- mensaje: The text of the message (
mensajeTexto).
- clase: The class or CSS class associated with the message (
clase).
- fecha: The date when the message was sent (
fecha).
- lista: The list of messages or the container where messages are displayed (
listaMensajes).
- fechaAnt: The previous message’s date (
fechaAnterior).
- top: A boolean indicating whether to insert at the top (
insertAtTop).
- adjunto: Any attachments included with the message (
adjunto).
- tempId: A temporary ID for the message (
temp_id).
- emisorMsg: The sender of the message (
msgEmisor).
- primerMsg: A boolean indicating if this is the first message of a thread (
isFirstMessageOfThread).
- usuario: Information about the user (
userInfo).
- tipo: The type of message (
tipoMensaje).
- leido: A boolean indicating if the message has been read (
mensajeLeido).
This way, the logInfo object neatly summarizes all the inputs to the function with concise, one-word keys. The console.log statement will output all the key information, which is helpful for debugging or tracking the function's behavior.
Example Output in Console:
[[agregarMensajeAlChat]] {
mensaje: "Esto es un mensaje de ejemplo",
clase: "mensaje-usuario",
fecha: "2023-10-05T14:48:00.000Z",
lista: NodeList[...],
fechaAnt: null,
top: false,
adjunto: null,
tempId: null,
emisorMsg: "usuario123",
primerMsg: false,
usuario: { nombre: "Juan", id: "usuario123" },
tipo: "texto",
leido: true
}
Make sure to replace the placeholders and adjust the keys if needed to match your specific requirements or naming conventions.