From a6964449785f302a8f1c10604f881c06516aaa1e Mon Sep 17 00:00:00 2001 From: AlphaX-Qortal Date: Fri, 17 Jan 2025 16:17:30 +0100 Subject: [PATCH] fix reactions from qortal-hub --- plugins/plugins/core/components/ChatPage.js | 3 +- plugins/plugins/core/q-chat/q-chat.src.js | 40 ++++++++++++--------- plugins/plugins/utils/functions.js | 4 +-- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/plugins/plugins/core/components/ChatPage.js b/plugins/plugins/core/components/ChatPage.js index de1406f3..6c53c9a9 100644 --- a/plugins/plugins/core/components/ChatPage.js +++ b/plugins/plugins/core/components/ChatPage.js @@ -2257,9 +2257,10 @@ class ChatPage extends LitElement { } async addToUpdateMessageHashmap(array) { + const withoutHubReactions = array.filter(({decodedMessage}) => !decodedMessage.includes('isReaction')) const newObj = {} - array.forEach((item) => { + withoutHubReactions.forEach((item) => { const signature = item.originalSignature || item.signature newObj[signature] = item }) diff --git a/plugins/plugins/core/q-chat/q-chat.src.js b/plugins/plugins/core/q-chat/q-chat.src.js index 0f8b2c50..7f4ede43 100644 --- a/plugins/plugins/core/q-chat/q-chat.src.js +++ b/plugins/plugins/core/q-chat/q-chat.src.js @@ -451,6 +451,7 @@ class Chat extends LitElement { let currentGroupId = url.substring(6) let symIdentifier = 'symmetric-qchat-group-' + currentGroupId let locateString = "Downloading and decrypt keys ! Please wait..." + let keysToOld = "Wait until an admin re-encrypts the keys. Only unencrypted messages will be displayed." const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node] const nodeUrl = myNode.protocol + '://' + myNode.domain + ':' + myNode.port @@ -502,24 +503,31 @@ class Chat extends LitElement { data = await res.text() const decryptedKey = await this.decryptGroupEncryption(data) - const dataint8Array = base64ToUint8Array(decryptedKey.data) - const decryptedKeyToObject = uint8ArrayToObject(dataint8Array) - if (!validateSecretKey(decryptedKeyToObject)) { - throw new Error("SecretKey is not valid") + if (decryptedKey === undefined) { + parentEpml.request('showSnackBar', `${keysToOld}`) + this.activeChatHeadUrl = url + this.requestUpdate() + } else { + const dataint8Array = base64ToUint8Array(decryptedKey.data) + const decryptedKeyToObject = uint8ArrayToObject(dataint8Array) + + if (!validateSecretKey(decryptedKeyToObject)) { + throw new Error("SecretKey is not valid") + } + + localStorage.removeItem("symKeysCurrent") + localStorage.setItem("symKeysCurrent", "") + let oldSymIdentifier = JSON.parse(localStorage.getItem("symKeysCurrent") || "[]") + oldSymIdentifier.push(decryptedKeyToObject) + localStorage.setItem("symKeysCurrent", JSON.stringify(oldSymIdentifier)) + + let arraySecretKeys = JSON.parse(localStorage.getItem("symKeysCurrent") || "[]") + + this.secretKeys = arraySecretKeys[0] + this.activeChatHeadUrl = url + this.requestUpdate() } - - localStorage.removeItem("symKeysCurrent") - localStorage.setItem("symKeysCurrent", "") - let oldSymIdentifier = JSON.parse(localStorage.getItem("symKeysCurrent") || "[]") - oldSymIdentifier.push(decryptedKeyToObject) - localStorage.setItem("symKeysCurrent", JSON.stringify(oldSymIdentifier)) - - let arraySecretKeys = JSON.parse(localStorage.getItem("symKeysCurrent") || "[]") - - this.secretKeys = arraySecretKeys[0] - this.activeChatHeadUrl = url - this.requestUpdate() } else { this.activeChatHeadUrl = url this.requestUpdate() diff --git a/plugins/plugins/utils/functions.js b/plugins/plugins/utils/functions.js index 775083cc..f94cc32c 100644 --- a/plugins/plugins/utils/functions.js +++ b/plugins/plugins/utils/functions.js @@ -164,10 +164,10 @@ export const replaceMessagesEdited = async ({ decodedMessages, parentEpml, isRec } const sortedMessages = decodedMessages.sort((a, b) => b.timestamp - a.timestamp) - const result = sortedMessages.filter(({decodedMessage}) => !name.includes('isReaction')) + const withoutHubReactions = sortedMessages.filter(({decodedMessage}) => !decodedMessage.includes('isReaction')) // Execute the functions with concurrency limit - const updatedMessages = await executeWithConcurrencyLimit(result, findUpdatedMessage) + const updatedMessages = await executeWithConcurrencyLimit(withoutHubReactions, findUpdatedMessage) addToUpdateMessageHashmap(updatedMessages) return updatedMessages