diff --git a/index.html b/index.html index c5d151f..70b35e6 100644 --- a/index.html +++ b/index.html @@ -1363,7 +1363,7 @@ const contacts = [] const groupID = getRef('edit_group_button').dataset.groupId; for (const contact in floGlobals.contacts) { - if (!messenger.groups[groupID].members.includes(contact) && contact in floGlobals.pubKeys) { + if (!messenger.groups[groupID].members.includes(contact) && hasPubKey(contact)) { contacts.push(render.selectableContact(contact)) } } @@ -1954,7 +1954,7 @@ // class based lazy loading class LazyLoader { constructor(container, elementsToRender, renderFn, options = {}) { - const { batchSize = 10, freshRender, bottomFirst = false, domUpdated } = options + const { batchSize = 10, freshRender, bottomFirst = false, onEnd } = options this.elementsToRender = elementsToRender this.arrayOfElements = (typeof elementsToRender === 'function') ? this.elementsToRender() : elementsToRender || [] @@ -1963,8 +1963,8 @@ this.batchSize = batchSize this.freshRender = freshRender - this.domUpdated = domUpdated this.bottomFirst = bottomFirst + this.onEnd = onEnd this.shouldLazyLoad = false this.lastScrollTop = 0 @@ -1981,6 +1981,10 @@ return this.arrayOfElements } init() { + if (this.mutationObserver) + this.mutationObserver.disconnect() + if (this.intersectionObserver) + this.intersectionObserver.disconnect() this.intersectionObserver = new IntersectionObserver((entries, observer) => { entries.forEach(entry => { if (entry.isIntersecting) { @@ -2048,8 +2052,18 @@ this.lastScrollTop += this.lazyContainer.scrollHeight - this.lastScrollHeight this.lazyContainer.scrollTo({ top: this.lastScrollTop }) this.lastScrollHeight = this.lazyContainer.scrollHeight + if (this.updateStartIndex <= 0 && this.onEnd) { + this.mutationObserver.disconnect() + this.intersectionObserver.disconnect() + this.onEnd() + } } else { this.lazyContainer.append(frag) + if (this.updateEndIndex >= this.arrayOfElements.length && this.onEnd) { + this.mutationObserver.disconnect() + this.intersectionObserver.disconnect() + this.onEnd() + } } if (!lazyLoad && this.bottomFirst) { this.lazyContainer.scrollTop = this.lazyContainer.scrollHeight @@ -3023,6 +3037,12 @@ updateMessageUI(data.messages) } + function hasPubKey(address) { + const floID = floCrypto.toFloID(address) + const btcAddress = btcOperator.convert.legacy2bech(floID) + return floGlobals.pubKeys.hasOwnProperty(btcAddress) || floGlobals.pubKeys.hasOwnProperty(floID) + } + async function updateMessageUI(messagesData, sentByMe = false) { const animOptions = { duration: 300, @@ -3032,6 +3052,8 @@ for (let messageId in messagesData) { const { category, floID, time, message, sender, groupID, admin, name, pipeID, unconfirmed } = messagesData[messageId] const chatAddress = floID || groupID || pipeID + const activeChatFloAdress = floCrypto.toFloID(activeChat.address) + const activeChatBtcAddress = btcOperator.convert.legacy2bech(activeChatFloAdress) // code to run if a chat is opened if (activeChat && (activeChat.address === chatAddress || activeChat.address === floCrypto.toFloID(chatAddress))) { if (!sentByMe && sender && sender === floDapps.user.id) { @@ -3044,7 +3066,7 @@ scrollToBottom() } // remove encryption badge if it exists - if (!groupID && floGlobals.pubKeys[activeChat.address] && floID !== floDapps.user.id) { + if (!groupID && hasPubKey(activeChat.address) && floID !== floDapps.user.id) { document.getElementById('warn_no_encryption')?.remove() } } @@ -3056,7 +3078,7 @@ } // move chat card to top if it is not already there const topChatCard = getRef('chats_list').children[0] - if (chatAddress !== topChatCard.dataset.floAddress || chatAddress !== floCrypto.toFloID(topChatCard.dataset.floAddress)) { + if (chatAddress !== topChatCard.dataset.floAddress && chatAddress !== floCrypto.toFloID(topChatCard.dataset.floAddress)) { const cloneContact = chatCard.cloneNode(true) chatCard.remove() getRef('chats_list').animate([ @@ -3803,7 +3825,7 @@ } for (const floID in floGlobals.contacts) { if (getFloIdType(floID) !== 'plain') continue; - if (floGlobals.pubKeys.hasOwnProperty(floID)) { + if (hasPubKey(floID)) { contacts.push(render.selectableContact(floID)) } else { const hasSentRequest = skipSendingRequest.has(floID) @@ -3885,6 +3907,18 @@ chatLazyLoader = new LazyLoader('#messages_container', chat, render.messageBubble, { bottomFirst: true, batchSize: 20, + onEnd: () => { + if (activeChat.type === 'plain') { + if (hasPubKey(activeChat.address)) { + getRef('messages_container').prepend(html.node` + + Conversation is encrypted + `) + } else { + getRef('messages_container').prepend(html.node`Conversation is not encrypted until receiver replies`) + } + } + } }); } chatLazyLoader.init() @@ -3902,7 +3936,7 @@ } resolve() }).catch(error => { - console.log(error) + console.error(error) reject(error) }) }) @@ -3950,12 +3984,9 @@ getRef('chat_footer').classList.remove('hidden') } lastSender = '' + // fix issue with encryption renderMessages(floID).then(async () => { - if (activeChat.type === 'plain') { - if (!floGlobals.pubKeys[floID]) { - getRef('messages_container').prepend(html.node`Conversation is not encrypted until receiver replies`) - } - } else if (activeChat.type === 'pipeline') { + if (activeChat.type === 'pipeline') { if (!messenger.pipeline[floID].disabled && floGlobals.pipeSigns[floID] && !floGlobals.pipeSigns[floID].has(floDapps.user.id)) { getRef('messages_container').append(html.node`