shogun-core 3.2.0 → 3.2.1
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.
|
@@ -408,43 +408,61 @@ class SHIP_01 {
|
|
|
408
408
|
const userPub = currentUser.is.pub;
|
|
409
409
|
const username = currentUser.is.alias;
|
|
410
410
|
const allMessages = [];
|
|
411
|
+
console.log(`[SHIP-01] Getting history between ${username} (${userPub.substring(0, 20)}...) and ${withUsername}`);
|
|
411
412
|
// Ottieni il userPub dell'altro utente
|
|
412
413
|
const otherUserData = await this.shogun.db.getUserByAlias(withUsername);
|
|
413
414
|
const otherUserPub = otherUserData?.userPub;
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
415
|
+
console.log(`[SHIP-01] Other user pub: ${otherUserPub?.substring(0, 20) || 'not found'}...`);
|
|
416
|
+
// Use .map() instead of .then() to iterate all messages
|
|
417
|
+
return new Promise((resolve) => {
|
|
418
|
+
const messages = [];
|
|
419
|
+
let messageCount = 0;
|
|
420
|
+
this.shogun.db.gun.get('messages').map().once(async (msgData, messageId) => {
|
|
421
|
+
// Skip metadata fields
|
|
422
|
+
if (!msgData || typeof msgData !== 'object' || messageId === '_') {
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
messageCount++;
|
|
426
|
+
console.log(`[SHIP-01] Checking message ${messageId}:`, {
|
|
427
|
+
from: msgData.from?.substring(0, 20),
|
|
428
|
+
to: msgData.to,
|
|
429
|
+
hasContent: !!msgData.content
|
|
430
|
+
});
|
|
431
|
+
try {
|
|
432
|
+
// Check if message is part of this conversation
|
|
422
433
|
const isSentToTarget = msgData.from === userPub && msgData.to === withUsername;
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
}
|
|
434
|
+
const isReceivedFromTarget = msgData.to === username && msgData.from === otherUserPub;
|
|
435
|
+
console.log(`[SHIP-01] Message ${messageId} match:`, {
|
|
436
|
+
isSentToTarget,
|
|
437
|
+
isReceivedFromTarget,
|
|
438
|
+
fromMatch: msgData.from === userPub,
|
|
439
|
+
toMatch: msgData.to === withUsername,
|
|
440
|
+
receivedToMatch: msgData.to === username,
|
|
441
|
+
receivedFromMatch: msgData.from === otherUserPub
|
|
442
|
+
});
|
|
443
|
+
if (isSentToTarget || isReceivedFromTarget) {
|
|
444
|
+
// Decrypt message
|
|
445
|
+
const decryptedContent = await this.decryptMessage(msgData.content, msgData.from);
|
|
446
|
+
messages.push({
|
|
447
|
+
from: msgData.from,
|
|
448
|
+
to: msgData.to,
|
|
449
|
+
content: decryptedContent,
|
|
450
|
+
timestamp: parseInt(msgData.timestamp)
|
|
451
|
+
});
|
|
452
|
+
console.log(`[SHIP-01] ✅ Decrypted message from ${msgData.from.substring(0, 20)}...`);
|
|
442
453
|
}
|
|
443
454
|
}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
455
|
+
catch (error) {
|
|
456
|
+
console.error(`[SHIP-01] ❌ Error processing message ${messageId}:`, error);
|
|
457
|
+
}
|
|
458
|
+
});
|
|
459
|
+
// Wait a bit for GunDB to return all messages, then resolve
|
|
460
|
+
setTimeout(() => {
|
|
461
|
+
console.log(`[SHIP-01] Found ${messages.length} messages out of ${messageCount} total`);
|
|
462
|
+
const sorted = messages.sort((a, b) => a.timestamp - b.timestamp);
|
|
463
|
+
resolve(sorted);
|
|
464
|
+
}, 2000);
|
|
465
|
+
});
|
|
448
466
|
}
|
|
449
467
|
// ========================================================================
|
|
450
468
|
// 7. UTILITY FUNCTIONS
|