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
- // Recupera tutti i messaggi dal nodo 'messages' e filtra
415
- const allMessagesNode = await this.shogun.db.gun.get('messages').then();
416
- if (allMessagesNode) {
417
- for (const [messageId, data] of Object.entries(allMessagesNode)) {
418
- if (typeof data === 'object' && data !== null) {
419
- const msgData = data;
420
- // Filtra messaggi tra questo utente e withUsername
421
- // Messaggi inviati da me a loro
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
- // Messaggi ricevuti da loro
424
- const isReceivedFromTarget = msgData.to === username &&
425
- (msgData.from === otherUserPub ||
426
- msgData.from);
427
- if ((isSentToTarget || isReceivedFromTarget) && msgData.content && msgData.messageId) {
428
- try {
429
- // Decripta ogni messaggio
430
- const decryptedContent = await this.decryptMessage(msgData.content, msgData.from);
431
- allMessages.push({
432
- from: msgData.from,
433
- to: msgData.to,
434
- content: decryptedContent,
435
- timestamp: parseInt(msgData.timestamp)
436
- });
437
- }
438
- catch (error) {
439
- console.error(`❌ Errore decrittazione messaggio ${messageId}:`, error);
440
- // Salta messaggi che non possono essere decriptati
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
- // Ordina per timestamp
447
- return allMessages.sort((a, b) => a.timestamp - b.timestamp);
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shogun-core",
3
- "version": "3.2.0",
3
+ "version": "3.2.1",
4
4
  "description": "SHOGUN CORE - Core library for Shogun Ecosystem",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",