mirror of
https://github.com/Qortal/qortal-ui.git
synced 2025-02-11 17:55:51 +00:00
Reworked get latest symmetric keyfile
This commit is contained in:
parent
e9ab20a451
commit
6debf5fd72
@ -2866,13 +2866,15 @@ class GroupManagement extends LitElement {
|
|||||||
|
|
||||||
let data
|
let data
|
||||||
let supArray = []
|
let supArray = []
|
||||||
|
let allSymKeys = []
|
||||||
let gAdmin = ''
|
let gAdmin = ''
|
||||||
let gAddress = ''
|
let gAddress = ''
|
||||||
|
let keysToOld = "Wait until an admin re-encrypts the keys. Only unencrypted messages will be displayed."
|
||||||
|
|
||||||
const symIdentifier = 'symmetric-qchat-group-' + groupId
|
const symIdentifier = 'symmetric-qchat-group-' + groupId
|
||||||
const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node]
|
const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node]
|
||||||
const nodeUrl = myNode.protocol + '://' + myNode.domain + ':' + myNode.port
|
const nodeUrl = myNode.protocol + '://' + myNode.domain + ':' + myNode.port
|
||||||
const getNameUrl = `${nodeUrl}/arbitrary/resources?service=DOCUMENT_PRIVATE&identifier=${symIdentifier}&limit=1&reverse=true`
|
const getNameUrl = `${nodeUrl}/arbitrary/resources?service=DOCUMENT_PRIVATE&identifier=${symIdentifier}&limit=0&reverse=true`
|
||||||
const getAdminUrl = `${nodeUrl}/groups/members/${groupId}?onlyAdmins=true&limit=20`
|
const getAdminUrl = `${nodeUrl}/groups/members/${groupId}?onlyAdmins=true&limit=20`
|
||||||
|
|
||||||
supArray = await fetch(getNameUrl).then(response => {
|
supArray = await fetch(getNameUrl).then(response => {
|
||||||
@ -2882,10 +2884,21 @@ class GroupManagement extends LitElement {
|
|||||||
if (this.isEmptyArray(supArray) || groupId === 0) {
|
if (this.isEmptyArray(supArray) || groupId === 0) {
|
||||||
console.log("No Symetric Key")
|
console.log("No Symetric Key")
|
||||||
} else {
|
} else {
|
||||||
supArray.map(item => {
|
supArray.forEach(item => {
|
||||||
gAdmin = item.name
|
const symInfoObj = {
|
||||||
|
name: item.name,
|
||||||
|
identifier: item.identifier,
|
||||||
|
timestamp: item.updated ? item.updated : item.created
|
||||||
|
}
|
||||||
|
allSymKeys.push(symInfoObj)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let allSymKeysSorted = allSymKeys.sort(function(a, b) {
|
||||||
|
return b.timestamp - a.timestamp
|
||||||
|
})
|
||||||
|
|
||||||
|
gAdmin = allSymKeysSorted[0].name
|
||||||
|
|
||||||
const addressUrl = `${nodeUrl}/names/${gAdmin}`
|
const addressUrl = `${nodeUrl}/names/${gAdmin}`
|
||||||
|
|
||||||
let addressObject = await fetch(addressUrl).then(response => {
|
let addressObject = await fetch(addressUrl).then(response => {
|
||||||
@ -2913,14 +2926,19 @@ class GroupManagement extends LitElement {
|
|||||||
data = await res.text()
|
data = await res.text()
|
||||||
|
|
||||||
const decryptedKey = await this.decryptGroupEncryption(data)
|
const decryptedKey = await this.decryptGroupEncryption(data)
|
||||||
const dataint8Array = base64ToUint8Array(decryptedKey.data)
|
|
||||||
const decryptedKeyToObject = uint8ArrayToObject(dataint8Array)
|
|
||||||
|
|
||||||
if (!validateSecretKey(decryptedKeyToObject)) {
|
if (decryptedKey === undefined) {
|
||||||
throw new Error("SecretKey is not valid")
|
parentEpml.request('showSnackBar', `${keysToOld}`)
|
||||||
|
} else {
|
||||||
|
const dataint8Array = base64ToUint8Array(decryptedKey.data)
|
||||||
|
const decryptedKeyToObject = uint8ArrayToObject(dataint8Array)
|
||||||
|
|
||||||
|
if (!validateSecretKey(decryptedKeyToObject)) {
|
||||||
|
throw new Error("SecretKey is not valid")
|
||||||
|
}
|
||||||
|
|
||||||
|
this.secretKeys = decryptedKeyToObject
|
||||||
}
|
}
|
||||||
|
|
||||||
this.secretKeys = decryptedKeyToObject
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3080,7 +3098,7 @@ class GroupManagement extends LitElement {
|
|||||||
let getEditedArray = await parentEpml.request('apiCall', {
|
let getEditedArray = await parentEpml.request('apiCall', {
|
||||||
url: `/chat/messages?txGroupId=${involved}&haschatreference=true&encoding=BASE64&limit=0&reverse=false`
|
url: `/chat/messages?txGroupId=${involved}&haschatreference=true&encoding=BASE64&limit=0&reverse=false`
|
||||||
})
|
})
|
||||||
|
|
||||||
chaEditedArray = getEditedArray
|
chaEditedArray = getEditedArray
|
||||||
|
|
||||||
// Replace messages which got edited in the chatMessageArray
|
// Replace messages which got edited in the chatMessageArray
|
||||||
@ -3143,7 +3161,7 @@ class GroupManagement extends LitElement {
|
|||||||
if (this.shadowRoot.getElementById('chat-container').innerHTML === '') {
|
if (this.shadowRoot.getElementById('chat-container').innerHTML === '') {
|
||||||
this.shadowRoot.getElementById('chat-container').innerHTML = ''
|
this.shadowRoot.getElementById('chat-container').innerHTML = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isEmptyArray(renderArray)) {
|
if (this.isEmptyArray(renderArray)) {
|
||||||
const chatEmpty = document.createElement('div')
|
const chatEmpty = document.createElement('div')
|
||||||
chatEmpty.classList.add('no-messages')
|
chatEmpty.classList.add('no-messages')
|
||||||
@ -5778,4 +5796,4 @@ class GroupManagement extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.customElements.define('group-management', GroupManagement)
|
window.customElements.define('group-management', GroupManagement)
|
||||||
|
@ -447,6 +447,7 @@ class Chat extends LitElement {
|
|||||||
|
|
||||||
let data
|
let data
|
||||||
let supArray = []
|
let supArray = []
|
||||||
|
let allSymKeys = []
|
||||||
let gAdmin = ''
|
let gAdmin = ''
|
||||||
let gAddress = ''
|
let gAddress = ''
|
||||||
let currentGroupId = url.substring(6)
|
let currentGroupId = url.substring(6)
|
||||||
@ -456,7 +457,7 @@ class Chat extends LitElement {
|
|||||||
|
|
||||||
const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node]
|
const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node]
|
||||||
const nodeUrl = myNode.protocol + '://' + myNode.domain + ':' + myNode.port
|
const nodeUrl = myNode.protocol + '://' + myNode.domain + ':' + myNode.port
|
||||||
const getNameUrl = `${nodeUrl}/arbitrary/resources?service=DOCUMENT_PRIVATE&identifier=${symIdentifier}&limit=1&reverse=true`
|
const getNameUrl = `${nodeUrl}/arbitrary/resources?service=DOCUMENT_PRIVATE&identifier=${symIdentifier}&limit=0&reverse=true`
|
||||||
const getAdminUrl = `${nodeUrl}/groups/members/${currentGroupId}?onlyAdmins=true&limit=20`
|
const getAdminUrl = `${nodeUrl}/groups/members/${currentGroupId}?onlyAdmins=true&limit=20`
|
||||||
|
|
||||||
if (localStorage.getItem("symKeysCurrent") === null) {
|
if (localStorage.getItem("symKeysCurrent") === null) {
|
||||||
@ -473,10 +474,21 @@ class Chat extends LitElement {
|
|||||||
} else {
|
} else {
|
||||||
parentEpml.request('showSnackBar', `${locateString}`)
|
parentEpml.request('showSnackBar', `${locateString}`)
|
||||||
|
|
||||||
supArray.map(item => {
|
supArray.forEach(item => {
|
||||||
gAdmin = item.name
|
const symInfoObj = {
|
||||||
|
name: item.name,
|
||||||
|
identifier: item.identifier,
|
||||||
|
timestamp: item.updated ? item.updated : item.created
|
||||||
|
}
|
||||||
|
allSymKeys.push(symInfoObj)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let allSymKeysSorted = allSymKeys.sort(function(a, b) {
|
||||||
|
return b.timestamp - a.timestamp
|
||||||
|
})
|
||||||
|
|
||||||
|
gAdmin = allSymKeysSorted[0].name
|
||||||
|
|
||||||
const addressUrl = `${nodeUrl}/names/${gAdmin}`
|
const addressUrl = `${nodeUrl}/names/${gAdmin}`
|
||||||
|
|
||||||
let addressObject = await fetch(addressUrl).then(response => {
|
let addressObject = await fetch(addressUrl).then(response => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user