shogun-core 3.2.1 → 3.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -259,7 +259,7 @@ class SHIP_01 {
|
|
|
259
259
|
messageId: messageId
|
|
260
260
|
};
|
|
261
261
|
// Salva sul nodo globale 'messages' per permettere il listener
|
|
262
|
-
await this.shogun.db.gun.get(
|
|
262
|
+
await this.shogun.db.gun.get(SHIP_01.NODES.MESSAGES).get(messageId).put(messageData).then();
|
|
263
263
|
console.log(`✅ Messaggio salvato: ${messageId}`);
|
|
264
264
|
return {
|
|
265
265
|
success: true,
|
|
@@ -323,7 +323,7 @@ class SHIP_01 {
|
|
|
323
323
|
const receivedMessages = new Set();
|
|
324
324
|
// Ascolta messaggi in tempo reale su GunDB
|
|
325
325
|
this.shogun.db.gun
|
|
326
|
-
.get(
|
|
326
|
+
.get(SHIP_01.NODES.MESSAGES)
|
|
327
327
|
.map()
|
|
328
328
|
.on(async (data, key) => {
|
|
329
329
|
// Filtra solo i messaggi destinati a questo utente (per username)
|
|
@@ -417,7 +417,7 @@ class SHIP_01 {
|
|
|
417
417
|
return new Promise((resolve) => {
|
|
418
418
|
const messages = [];
|
|
419
419
|
let messageCount = 0;
|
|
420
|
-
this.shogun.db.gun.get(
|
|
420
|
+
this.shogun.db.gun.get(SHIP_01.NODES.MESSAGES).map().once(async (msgData, messageId) => {
|
|
421
421
|
// Skip metadata fields
|
|
422
422
|
if (!msgData || typeof msgData !== 'object' || messageId === '_') {
|
|
423
423
|
return;
|
|
@@ -430,8 +430,9 @@ class SHIP_01 {
|
|
|
430
430
|
});
|
|
431
431
|
try {
|
|
432
432
|
// Check if message is part of this conversation
|
|
433
|
-
|
|
434
|
-
const
|
|
433
|
+
// Fixed: Handle both username and userPub in matching
|
|
434
|
+
const isSentToTarget = msgData.from === userPub && (msgData.to === withUsername || msgData.to === otherUserPub);
|
|
435
|
+
const isReceivedFromTarget = (msgData.to === username || msgData.to === userPub) && msgData.from === otherUserPub;
|
|
435
436
|
console.log(`[SHIP-01] Message ${messageId} match:`, {
|
|
436
437
|
isSentToTarget,
|
|
437
438
|
isReceivedFromTarget,
|
|
@@ -508,6 +509,12 @@ class SHIP_01 {
|
|
|
508
509
|
}
|
|
509
510
|
}
|
|
510
511
|
exports.SHIP_01 = SHIP_01;
|
|
512
|
+
// GunDB Node Names - Constants for clarity
|
|
513
|
+
SHIP_01.NODES = {
|
|
514
|
+
MESSAGES: 'messages',
|
|
515
|
+
USERS: 'users',
|
|
516
|
+
PUBLIC_KEYS: 'publicKeys'
|
|
517
|
+
};
|
|
511
518
|
// ============================================================================
|
|
512
519
|
// 8. ESEMPIO D'USO COMPLETO
|
|
513
520
|
// ============================================================================
|