|
1518 | 1518 | if (!wakuMessage.payload || !wakuMessage.payload.length || !this.Chat2Message) return; |
1519 | 1519 |
|
1520 | 1520 | // Check if this message's hash matches any missing message retrieval hints |
| 1521 | + // The retrieval hint should be the message ID itself |
| 1522 | + const messageId = ReliableChannel.getMessageId(wakuMessage.payload) |
| 1523 | + const messageIdHex = this.bytesToHex(messageId); |
| 1524 | + |
| 1525 | + // Mark this message as recovered if it was in the missing messages list |
| 1526 | + this.markMissingMessageAsReceived(messageIdHex); |
| 1527 | + |
| 1528 | + // Also check if wakuMessage has a hash property for alternative matching |
1521 | 1529 | if (wakuMessage.hash) { |
1522 | 1530 | const hashHex = this.bytesToHex(wakuMessage.hash); |
1523 | 1531 | this.markMissingMessageAsReceived(hashHex); |
1524 | 1532 | } |
1525 | 1533 |
|
1526 | | - // Abusing an API :] |
1527 | | - const messageId = ReliableChannel.getMessageId(wakuMessage.payload) |
1528 | 1534 | // We already processed this message |
1529 | 1535 | if (this.seenMessages.has(messageId)) return; |
1530 | 1536 |
|
|
1772 | 1778 | this.chatContainer.scrollTop = this.chatContainer.scrollHeight; |
1773 | 1779 | } |
1774 | 1780 |
|
1775 | | - markMissingMessageAsReceived(hashHex) { |
1776 | | - // Check if we have a missing message with this retrieval hint |
1777 | | - const messageElement = this.missingMessagesByHint.get(hashHex); |
| 1781 | + markMissingMessageAsReceived(messageIdHex) { |
| 1782 | + // Check if we have this message ID in our seen missing messages set |
| 1783 | + if (this.seenMissingMessages.has(messageIdHex)) { |
| 1784 | + // Find the message element by iterating through the missing messages |
| 1785 | + const messageElements = this.missingMessagesContent.querySelectorAll('.missing-messages-window-message'); |
| 1786 | + for (const messageElement of messageElements) { |
| 1787 | + if (messageElement.dataset.fullId === messageIdHex && !messageElement.classList.contains('received')) { |
| 1788 | + // Cross out the message |
| 1789 | + messageElement.classList.add('received'); |
| 1790 | + this.recoveredMessagesCount++; |
| 1791 | + |
| 1792 | + // Update window title with new counts |
| 1793 | + this.updateMissingMessagesTitle(); |
| 1794 | + |
| 1795 | + // Log for debugging |
| 1796 | + console.log(`Missing message received: ${messageIdHex.substring(0, 12)}...`); |
| 1797 | + this.addSystemMessage(`Missing message recovered: ${messageIdHex.substring(0, 12)}...`); |
| 1798 | + break; |
| 1799 | + } |
| 1800 | + } |
| 1801 | + } |
| 1802 | + |
| 1803 | + // Also check by retrieval hint (backwards compatibility) |
| 1804 | + const messageElement = this.missingMessagesByHint.get(messageIdHex); |
1778 | 1805 | if (messageElement && !messageElement.classList.contains('received')) { |
1779 | 1806 | // Cross out the message |
1780 | 1807 | messageElement.classList.add('received'); |
|
1784 | 1811 | this.updateMissingMessagesTitle(); |
1785 | 1812 |
|
1786 | 1813 | // Log for debugging |
1787 | | - console.log(`Missing message received: ${hashHex.substring(0, 12)}...`); |
1788 | | - this.addSystemMessage(`Missing message recovered: ${hashHex.substring(0, 12)}...`); |
| 1814 | + console.log(`Missing message received via hint: ${messageIdHex.substring(0, 12)}...`); |
| 1815 | + this.addSystemMessage(`Missing message recovered via hint: ${messageIdHex.substring(0, 12)}...`); |
1789 | 1816 | } |
1790 | 1817 | } |
1791 | 1818 |
|
|
0 commit comments