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.
|
@@ -99547,43 +99547,61 @@ class SHIP_01 {
|
|
|
99547
99547
|
const userPub = currentUser.is.pub;
|
|
99548
99548
|
const username = currentUser.is.alias;
|
|
99549
99549
|
const allMessages = [];
|
|
99550
|
+
console.log(`[SHIP-01] Getting history between ${username} (${userPub.substring(0, 20)}...) and ${withUsername}`);
|
|
99550
99551
|
// Ottieni il userPub dell'altro utente
|
|
99551
99552
|
const otherUserData = await this.shogun.db.getUserByAlias(withUsername);
|
|
99552
99553
|
const otherUserPub = otherUserData?.userPub;
|
|
99553
|
-
|
|
99554
|
-
|
|
99555
|
-
|
|
99556
|
-
|
|
99557
|
-
|
|
99558
|
-
|
|
99559
|
-
|
|
99560
|
-
|
|
99554
|
+
console.log(`[SHIP-01] Other user pub: ${otherUserPub?.substring(0, 20) || 'not found'}...`);
|
|
99555
|
+
// Use .map() instead of .then() to iterate all messages
|
|
99556
|
+
return new Promise((resolve) => {
|
|
99557
|
+
const messages = [];
|
|
99558
|
+
let messageCount = 0;
|
|
99559
|
+
this.shogun.db.gun.get('messages').map().once(async (msgData, messageId) => {
|
|
99560
|
+
// Skip metadata fields
|
|
99561
|
+
if (!msgData || typeof msgData !== 'object' || messageId === '_') {
|
|
99562
|
+
return;
|
|
99563
|
+
}
|
|
99564
|
+
messageCount++;
|
|
99565
|
+
console.log(`[SHIP-01] Checking message ${messageId}:`, {
|
|
99566
|
+
from: msgData.from?.substring(0, 20),
|
|
99567
|
+
to: msgData.to,
|
|
99568
|
+
hasContent: !!msgData.content
|
|
99569
|
+
});
|
|
99570
|
+
try {
|
|
99571
|
+
// Check if message is part of this conversation
|
|
99561
99572
|
const isSentToTarget = msgData.from === userPub && msgData.to === withUsername;
|
|
99562
|
-
|
|
99563
|
-
|
|
99564
|
-
|
|
99565
|
-
|
|
99566
|
-
|
|
99567
|
-
|
|
99568
|
-
|
|
99569
|
-
|
|
99570
|
-
|
|
99571
|
-
|
|
99572
|
-
|
|
99573
|
-
|
|
99574
|
-
|
|
99575
|
-
|
|
99576
|
-
|
|
99577
|
-
|
|
99578
|
-
|
|
99579
|
-
|
|
99580
|
-
}
|
|
99573
|
+
const isReceivedFromTarget = msgData.to === username && msgData.from === otherUserPub;
|
|
99574
|
+
console.log(`[SHIP-01] Message ${messageId} match:`, {
|
|
99575
|
+
isSentToTarget,
|
|
99576
|
+
isReceivedFromTarget,
|
|
99577
|
+
fromMatch: msgData.from === userPub,
|
|
99578
|
+
toMatch: msgData.to === withUsername,
|
|
99579
|
+
receivedToMatch: msgData.to === username,
|
|
99580
|
+
receivedFromMatch: msgData.from === otherUserPub
|
|
99581
|
+
});
|
|
99582
|
+
if (isSentToTarget || isReceivedFromTarget) {
|
|
99583
|
+
// Decrypt message
|
|
99584
|
+
const decryptedContent = await this.decryptMessage(msgData.content, msgData.from);
|
|
99585
|
+
messages.push({
|
|
99586
|
+
from: msgData.from,
|
|
99587
|
+
to: msgData.to,
|
|
99588
|
+
content: decryptedContent,
|
|
99589
|
+
timestamp: parseInt(msgData.timestamp)
|
|
99590
|
+
});
|
|
99591
|
+
console.log(`[SHIP-01] ✅ Decrypted message from ${msgData.from.substring(0, 20)}...`);
|
|
99581
99592
|
}
|
|
99582
99593
|
}
|
|
99583
|
-
|
|
99584
|
-
|
|
99585
|
-
|
|
99586
|
-
|
|
99594
|
+
catch (error) {
|
|
99595
|
+
console.error(`[SHIP-01] ❌ Error processing message ${messageId}:`, error);
|
|
99596
|
+
}
|
|
99597
|
+
});
|
|
99598
|
+
// Wait a bit for GunDB to return all messages, then resolve
|
|
99599
|
+
setTimeout(() => {
|
|
99600
|
+
console.log(`[SHIP-01] Found ${messages.length} messages out of ${messageCount} total`);
|
|
99601
|
+
const sorted = messages.sort((a, b) => a.timestamp - b.timestamp);
|
|
99602
|
+
resolve(sorted);
|
|
99603
|
+
}, 2000);
|
|
99604
|
+
});
|
|
99587
99605
|
}
|
|
99588
99606
|
// ========================================================================
|
|
99589
99607
|
// 7. UTILITY FUNCTIONS
|