code refactoring

This commit is contained in:
sairaj mote 2023-03-21 01:49:05 +05:30
parent 4d6ecd0a35
commit 2ff8c0f5d0

View File

@ -1363,7 +1363,7 @@
const contacts = [] const contacts = []
const groupID = getRef('edit_group_button').dataset.groupId; const groupID = getRef('edit_group_button').dataset.groupId;
for (const contact in floGlobals.contacts) { for (const contact in floGlobals.contacts) {
if (!messenger.groups[groupID].members.includes(contact) && hasPubKey(contact)) { if (!messenger.groups[groupID].members.includes(contact) && floDapps.user.get_pubKey(contact)) {
contacts.push(render.selectableContact(contact)) contacts.push(render.selectableContact(contact))
} }
} }
@ -3037,12 +3037,6 @@
updateMessageUI(data.messages) 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) { async function updateMessageUI(messagesData, sentByMe = false) {
const animOptions = { const animOptions = {
duration: 300, duration: 300,
@ -3064,7 +3058,7 @@
scrollToBottom() scrollToBottom()
} }
// remove encryption badge if it exists // remove encryption badge if it exists
if (!groupID && hasPubKey(activeChat.address) && floID !== floDapps.user.id) { if (!groupID && floDapps.user.get_pubKey(activeChat.address) && floID !== floDapps.user.id) {
console.log('removing encryption badge') console.log('removing encryption badge')
if (document.getElementById('warn_no_encryption')) { if (document.getElementById('warn_no_encryption')) {
document.getElementById('warn_no_encryption').after( document.getElementById('warn_no_encryption').after(
@ -3492,7 +3486,7 @@
const selctedPubKeys = [...selectedMembers].map(id => { const selctedPubKeys = [...selectedMembers].map(id => {
if (id === floDapps.user.id) if (id === floDapps.user.id)
return floDapps.user.public return floDapps.user.public
return floGlobals.pubKeys[id] return floDapps.user.get_pubKey(id)
}); });
const minRequired = parseInt(getRef('min_sign_required').value.trim()); const minRequired = parseInt(getRef('min_sign_required').value.trim());
const label = getRef('multisig_label').value.trim(); const label = getRef('multisig_label').value.trim();
@ -3840,7 +3834,7 @@
} }
for (const floID in floGlobals.contacts) { for (const floID in floGlobals.contacts) {
if (getFloIdType(floID) !== 'plain') continue; if (getFloIdType(floID) !== 'plain') continue;
if (hasPubKey(floID)) { if (floDapps.user.get_pubKey(floID)) {
contacts.push(render.selectableContact(floID)) contacts.push(render.selectableContact(floID))
} else { } else {
const hasSentRequest = skipSendingRequest.has(floID) const hasSentRequest = skipSendingRequest.has(floID)
@ -3924,7 +3918,7 @@
batchSize: 20, batchSize: 20,
onEnd: () => { onEnd: () => {
if (activeChat.type === 'plain') { if (activeChat.type === 'plain') {
if (hasPubKey(activeChat.address)) { if (floDapps.user.get_pubKey(activeChat.address)) {
getRef('messages_container').prepend(html.node`<strong class="event-card flex align-center"> getRef('messages_container').prepend(html.node`<strong class="event-card flex align-center">
<svg class="icon margin-right-0-5" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><g fill="none"><path d="M0 0h24v24H0V0z"/><path d="M0 0h24v24H0V0z" opacity=".87"/></g><path d="M18 8h-1V6c0-2.76-2.24-5-5-5S7 3.24 7 6v2H6c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V10c0-1.1-.9-2-2-2zM9 6c0-1.66 1.34-3 3-3s3 1.34 3 3v2H9V6zm9 14H6V10h12v10zm-6-3c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2z"/></svg> <svg class="icon margin-right-0-5" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><g fill="none"><path d="M0 0h24v24H0V0z"/><path d="M0 0h24v24H0V0z" opacity=".87"/></g><path d="M18 8h-1V6c0-2.76-2.24-5-5-5S7 3.24 7 6v2H6c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V10c0-1.1-.9-2-2-2zM9 6c0-1.66 1.34-3 3-3s3 1.34 3 3v2H9V6zm9 14H6V10h12v10zm-6-3c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2z"/></svg>
Conversation is encrypted Conversation is encrypted