Skip to content

Commit 12511e7

Browse files
siguiente version app fase1
1 parent 2f96eca commit 12511e7

9 files changed

Lines changed: 316 additions & 155 deletions

File tree

backend/repositories/ChatRepository.js

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ChatsRavage } from '../models/Chat.js';
44
import { User } from '../models/User.js';
55
import { MessagesRavage } from '../models/Message.js';
66
import { convertirObjectId } from '../utils/conversores.js';
7-
import { getIDMongodbUsuario, getInvisibleUsuario } from '../STORAGE/Variables_sesion.js';
7+
import { getIDMongodbUsuario, getInvisibleUsuario, setUsuariosSilence, setUsuariosBloqueados, getUsuariosSilence, getUsuariosBloqueados } from '../STORAGE/Variables_sesion.js';
88
import { Añadir_Entrada_Buzon_Usuario } from './BuzonRepository.js';
99
import { descifrarListaMensajes } from '../services/messageCryptoService.js';
1010
import { cifrarConPublica, desencriptarDatosSistema, encriptarDatosSistema } from '../services/cryptoService.js';
@@ -120,7 +120,7 @@ export async function obtener_datos_chat_unico(id_chat, datos_buscar = null) {
120120
// Caso: Pedir chat completo
121121
let chat_a_devolver = { ...cached, mensajes: [...(cached.mensajes || [])] };
122122
const tieneMensajesFull = chat_a_devolver.mensajes.length > 0 && typeof chat_a_devolver.mensajes[0] === 'object';
123-
123+
124124
if (!tieneMensajesFull) {
125125
chat_a_devolver.mensajes = await MessagesRavage.find({ id_chat: id_chat_str }).sort({ data: 1 }).lean();
126126
await descifrarListaMensajes(chat_a_devolver.mensajes, chat_a_devolver);
@@ -754,16 +754,7 @@ export async function rotarClavesChat(id_chat, id_emisor) {
754754
// Reemplazar todas las entradas de este emisor en el array ratchet_keys
755755
await ChatsRavage.updateOne(
756756
{ _id: id_chat_str },
757-
{
758-
$pull: { ratchet_keys: { emisor_id: id_emisor_str } }
759-
}
760-
);
761-
762-
await ChatsRavage.updateOne(
763-
{ _id: id_chat_str },
764-
{
765-
$push: { ratchet_keys: { $each: updates } }
766-
}
757+
{ $set: { ratchet_keys: updates } }
767758
);
768759

769760
// Actualizar cache tras rotación de claves
@@ -790,13 +781,29 @@ export async function SILENCIAR_CHAT_USUARIO(id_chat) {
790781
const currentMuted = usr.chats[index].silenciado || false;
791782
const newMuted = !currentMuted;
792783

793-
await User.updateOne(
794-
{ _id: id_propio, "chats.id": new mongoose.Types.ObjectId(id_chat_str) },
795-
{ $set: { "chats.$.silenciado": newMuted } }
784+
let resultado_silencio = [];
785+
if (newMuted) {
786+
const muteados = getUsuariosSilence();
787+
resultado_silencio = [...muteados, id_chat_str];
788+
setUsuariosSilence(resultado_silencio);
789+
} else {
790+
resultado_silencio = getUsuariosSilence().filter(c => c !== id_chat_str);
791+
setUsuariosSilence(resultado_silencio);
792+
}
793+
794+
const r = await User.updateOne(
795+
{ _id: id_propio },
796+
{
797+
$set: {
798+
"chats.$[chat].silenciado": newMuted,
799+
users_silence: resultado_silencio
800+
}
801+
},
802+
{ arrayFilters: [{ "chat.id": new mongoose.Types.ObjectId(id_chat_str) }] }
796803
);
797804

798805
await actualizarCacheUsuarioPropio();
799-
806+
log.info({ nuevo_estado: newMuted ? "silenciado" : "no silenciado", id_chat: id_chat_str }, "Silenciado");
800807
return { success: true, silenciado: newMuted };
801808
} catch (e) {
802809
log.error(e);
@@ -835,20 +842,31 @@ export async function BLOQUEAR_CHAT_USUARIO(id_chat) {
835842
participantes_bloqueo = chatActual.usuarios || null;
836843
}
837844
}
838-
845+
let resultado_bloque = [];
846+
if (newBlocked) {
847+
const bloqueados = getUsuariosBloqueados();
848+
resultado_bloque = [...bloqueados, id_chat_str];
849+
setUsuariosBloqueados(resultado_bloque);
850+
} else {
851+
resultado_bloque = getUsuariosBloqueados().filter(c => c !== id_chat_str);
852+
setUsuariosBloqueados(resultado_bloque);
853+
}
839854
await User.updateOne(
840-
{ _id: id_propio, "chats.id": new mongoose.Types.ObjectId(id_chat_str) },
855+
{ _id: id_propio },
841856
{
842857
$set: {
843-
"chats.$.bloqueado": newBlocked,
844-
"chats.$.mensaje_bloqueo_id": mensaje_bloqueo_id,
845-
"chats.$.nombre_bloqueo": nombre_bloqueo,
846-
"chats.$.participantes_bloqueo": participantes_bloqueo
858+
"chats.$[chat].bloqueado": newBlocked,
859+
"chats.$[chat].mensaje_bloqueo_id": mensaje_bloqueo_id,
860+
"chats.$[chat].nombre_bloqueo": nombre_bloqueo,
861+
"chats.$[chat].participantes_bloqueo": participantes_bloqueo,
862+
users_bloqueo: resultado_bloque
847863
}
848-
}
864+
},
865+
{ arrayFilters: [{ "chat.id": new mongoose.Types.ObjectId(id_chat_str) }] }
849866
);
850867

851868
await actualizarCacheUsuarioPropio();
869+
log.info({ nuevo_estado: newBlocked ? "bloqueado" : "desbloqueado", id_chat: id_chat_str }, "Bloqueo");
852870

853871
return { success: true, bloqueado: newBlocked };
854872
} catch (e) {

backend/repositories/UserRepository.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { mongoose, createHash, randomBytes, compare } from '../utils/libs.js';
22
import { createLogger } from '../utils/logger.js';
33
import { User } from '../models/User.js';
4+
import { ChatsRavage } from '../models/Chat.js';
45
import { TokenSession } from '../models/Security.js';
56
import { validateToken } from '../services/CreadorTokens.js';
67
import { encriptarDatosSistema, desencriptarDatosSistema, hashDatosSistema } from '../services/cryptoService.js';
@@ -164,8 +165,8 @@ async function _toggleArrayUsuario(id, arrayType, isAdd) {
164165

165166
try {
166167
const correoHash = hashDatosSistema(getCorreoSesion());
167-
const updateOp = isAdd
168-
? { $addToSet: { [field]: idStr } }
168+
const updateOp = isAdd
169+
? { $addToSet: { [field]: idStr } }
169170
: { $pull: { [field]: idStr } };
170171

171172
if (isAdd && arrayType === 'bloq') {
@@ -177,7 +178,7 @@ async function _toggleArrayUsuario(id, arrayType, isAdd) {
177178

178179
if (isAdd) list.push(idStr);
179180
else list.splice(index, 1);
180-
181+
181182
setList(list);
182183
await _syncCache(correoHash);
183184
return true;
@@ -309,13 +310,23 @@ export async function obtener_datos_usuario(id, datos_usar = null) {
309310

310311

311312
export async function obtener_varios_usuarios(ids, datos_usar = null) {
313+
log.info({ "ids": ids, "datos_usar": datos_usar }, "buscar datos usuarios")
312314
if (!Array.isArray(ids) || ids.length === 0) return [];
313315

314-
const normalizedIds = ids.map(_getID).filter(id => id && id !== "[object Object]");
316+
const normalizedIds = ids.map(x => {
317+
if (x?.buffer) return new mongoose.Types.ObjectId(Buffer.from(Object.values(x.buffer)));
318+
return new mongoose.Types.ObjectId(x);
319+
}).filter(Boolean);
320+
315321
const id_propio = getIDMongodbUsuario();
316-
const query_datos = datos_usar || "correo apodo visible idamigo mostrarCorreo";
322+
let query_datos = datos_usar || "correo apodo visible idamigo mostrarCorreo";
317323

318-
const usuarios_db = await User.find({ _id: { $in: normalizedIds } }, query_datos).lean();
324+
let usuarios_db = await User.find({ _id: { $in: normalizedIds } }, query_datos).lean();
325+
if (usuarios_db.length === 0) {
326+
query_datos="nombre";
327+
usuarios_db = await ChatsRavage.find({ _id: { $in: normalizedIds } }, query_datos).lean();
328+
}
329+
if (usuarios_db.length === 0) return [];
319330

320331
return usuarios_db.map(u => {
321332
const procesado = procesarUsuario(u);
@@ -373,7 +384,7 @@ export async function AÑADIR_CONTACTO(id, nombre) {
373384
try {
374385
const idStr = _getID(id);
375386
if (!idStr) return false;
376-
387+
377388
const id_propio = getIDMongodbUsuario();
378389
const mis_bloqueados = getUsuariosBloqueados() || [];
379390

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
import 'dotenv/config';
3-
import { enviarEmail } from './services/MENSAJERIA/Servicio_mensajeria_correo.js';
4-
import * as estructuras from './services/MENSAJERIA/Estructuras_correos.js';
3+
import { enviarEmail } from '../services/MENSAJERIA/Servicio_mensajeria_correo.js';
4+
import * as estructuras from '../services/MENSAJERIA/Estructuras_correos.js';
55

66
const DESTINO = [EMAIL_ADDRESS]
77
const CODIGO = '123456';

frontend/home/home.html

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<link rel="stylesheet" href="../notificaciones/notificaciones.css">
2323
<link rel="stylesheet" href="./styles/css_archivos.css">
2424
<link rel="stylesheet" href="./styles/historial.css">
25-
25+
<link rel="stylesheet" href="./styles/ajustes.css">
2626

2727
</head>
2828

@@ -34,7 +34,7 @@
3434
<img src="../recursos/cruz.png" alt="cerrar" draggable="false">
3535
</div>
3636
<div class="menu-navegacion-ajustes">
37-
<div id="bt-menu-navegacion-ajustes-cuenta">Cuenta</div>
37+
<div id="bt-menu-navegacion-ajustes-cuenta" class="active">Cuenta</div>
3838
<div id="bt-menu-navegacion-ajustes-general">General</div>
3939
<div id="bt-menu-navegacion-ajustes-noti">Notificaciones</div>
4040
<div id="bt-menu-navegacion-ajustes-soporte">Soporte</div>
@@ -43,29 +43,32 @@
4343
<div class="cuerpo-menu-ajustes">
4444
<div class="menu-ajustes-sub flex-display" id="cuerpo-ajustes-cuenta">
4545
<div class="label">
46-
<span id="text-cuenta-apodo">Apodo: Usuario</span>
46+
<span id="text-cuenta-apodo">Apodo: <font>Usuario</font></span>
4747
<button id="bt-cambiar-apodo">Cambiar Apodo</button>
4848
<span class="text-avisar-espera-bloqueo" id="bt-fecha-bloqueo-apodo"></span>
4949
</div>
5050
<div class="label">
51-
<span id="text-cuenta-correo">Correo electrónico: usuario@gmail.com</span>
51+
<span id="text-cuenta-correo">Correo electrónico: <font>usuario@gmail.com</font></span>
5252
<button id="bt-cambiar-correo">Cambiar Correo</button>
5353
<span class="text-avisar-espera-bloqueo" id="bt-fecha-bloqueo-correo"></span>
5454
</div>
5555
<div class="label">
56-
<span>Contraseña:</span>
56+
<span>Contraseña: <font>🤷‍♀️</font></span>
5757
<button id="bt-cambiar-contraseña">Cambiar Contraseña</button>
5858
<span class="text-avisar-espera-bloqueo" id="bt-fecha-bloqueo-contraseña"></span>
5959
</div>
6060
<div class="label">
61+
<span>Sesión: </span>
6162
<button id="bt-cerrar-sesion">Cerrar Sesión</button>
6263
</div>
6364
<span id="text-cuenta-creada-fecha">*Cuenta creada el xx/xx/xx</span>
6465
<div class="label">
65-
<button id="bt-ver-chats-silenciados">Ver chats silenciados</button>
66+
<span>Chats silenciados: </span>
67+
<button id="bt-ver-chats-silenciados">Ver</button>
6668
</div>
6769
<div class="label">
68-
<button id="bt-ver-chats-bloqueados">Ver chats bloqueados</button>
70+
<span>Chats bloqueados: </span>
71+
<button id="bt-ver-chats-bloqueados">Ver</button>
6972
</div>
7073
</div>
7174
<div class="menu-ajustes-sub ocultar-display" id="cuerpo-ajustes-general">
@@ -234,18 +237,14 @@ <h2>Cambiar Datos Cuenta</h2>
234237
<img src="../recursos/cruz.png" alt="cerrar" draggable="false">
235238
</div>
236239
<h2>LISTA USUARIOS BLOQUEADOS</h2>
237-
<div id="principal-lista-usuarios-bloqueados">
238-
239-
</div>
240+
<div id="principal-lista-usuarios-bloqueados" class="display-none"></div>
240241
</div>
241242
<div class="lista-bloqueados ocultar-display" id="lista-usuarios-silenciados">
242243
<div id="bt-cerrar-menu-lista-silenciados">
243244
<img src="../recursos/cruz.png" alt="cerrar" draggable="false">
244245
</div>
245246
<h2>LISTA USUARIOS SILENCIADOS</h2>
246-
<div id="principal-lista-usuarios-silenciados">
247-
248-
</div>
247+
<div id="principal-lista-usuarios-silenciados" class="display-none"></div>
249248
</div>
250249
</div>
251250
<!--CHATS-->

frontend/home/styles/ajustes.css

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#cuerpo-ajustes-cuenta .label span font {
2+
font-weight: 700;
3+
overflow-x: auto;
4+
}
5+
6+
#principal-lista-usuarios-bloqueados,
7+
#principal-lista-usuarios-silenciados {
8+
position: absolute;
9+
top: 0;
10+
left: 0;
11+
width: 100%;
12+
height: 100%;
13+
display: flex;
14+
flex-direction: column;
15+
align-items: center;
16+
justify-content: left;
17+
overflow-y: auto;
18+
z-index: 100;
19+
}
20+
21+
#principal-lista-usuarios-bloqueados .usuario-bloqueado,
22+
#principal-lista-usuarios-silenciados .usuario-silenciado {
23+
width: 95%;
24+
height: 50px;
25+
display: flex;
26+
flex-direction: row;
27+
align-items: center;
28+
justify-content: space-between;
29+
margin: 5px;
30+
padding: 5px;
31+
border: 1px solid #ccc;
32+
border-radius: 5px;
33+
z-index: 100;
34+
}

frontend/home/styles/style.css

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ input[type="number"]::-webkit-outer-spin-button {
189189
position: fixed;
190190
top: 0;
191191
left: 0;
192-
width: 100vw;
193-
height: 100vh;
192+
width: 100%;
193+
height: 100%;
194194
background: rgba(10, 10, 15, 0.8);
195195
backdrop-filter: blur(40px);
196196
-webkit-backdrop-filter: blur(40px);
@@ -265,16 +265,17 @@ input[type="number"]::-webkit-outer-spin-button {
265265
.cuerpo-menu-ajustes {
266266
flex: 1;
267267
height: 100%;
268+
width: 100%;
268269
overflow-y: auto;
269-
padding: 60px 10%;
270+
padding: 60px 9%;
270271
display: flex !important; /* Ensure it's flex regardless of parent display type */
271272
flex-direction: column;
272273
align-items: flex-start;
273274
}
274275

275276
.menu-ajustes-sub {
276277
width: 100%;
277-
max-width: 600px;
278+
max-width: 100%;
278279
display: none; /* Let the utility classes (flex-display) control this */
279280
flex-direction: column;
280281
gap: 32px;
@@ -287,12 +288,14 @@ input[type="number"]::-webkit-outer-spin-button {
287288
.menu-ajustes-sub .label {
288289
display: flex;
289290
align-items: center;
290-
justify-content: space-between;
291+
gap: 10px;
291292
padding: 16px 20px;
292293
background: rgba(255, 255, 255, 0.02);
293294
border: 1px solid rgba(255, 255, 255, 0.05);
294295
border-radius: 12px;
295296
margin-bottom: 2px;
297+
max-width: calc(100% - 20px);
298+
min-width: fit-content;
296299
}
297300

298301
.menu-ajustes-sub .label span {
@@ -310,6 +313,8 @@ input[type="number"]::-webkit-outer-spin-button {
310313
font-weight: 600;
311314
cursor: pointer;
312315
transition: all 0.2s ease;
316+
margin-left: auto;
317+
margin-right: 8px;
313318
}
314319

315320
.menu-ajustes-sub .label button:hover {
@@ -582,9 +587,9 @@ input[type="number"]::-webkit-outer-spin-button {
582587

583588
.text-avisar-espera-bloqueo {
584589
color: rgb(105, 72, 138);
585-
font-size: 13px !important;
590+
font-size: 13.5px !important;
586591
font-style: oblique;
587-
margin-left: 2px;
592+
margin-right: 8px;
588593
}
589594

590595
/*navegacion*/
@@ -1729,4 +1734,12 @@ input[type="number"]::-webkit-outer-spin-button {
17291734
100% {
17301735
transform: rotate(360deg);
17311736
}
1737+
}
1738+
1739+
.chat-spinner {
1740+
position: absolute;
1741+
left: 50%;
1742+
top:1%;
1743+
transform: translate(-50%, -50%);
1744+
z-index: 10000;
17321745
}

0 commit comments

Comments
 (0)