diff --git a/index.html b/index.html index 41a3cab..e716942 100644 --- a/index.html +++ b/index.html @@ -426,6 +426,10 @@ Create new group +
+ + Send message to +
@@ -1242,7 +1246,6 @@ floGlobals.groups = data.groups; floGlobals.chats = data.chats floGlobals['marked'] = data.marked - renderContactList(floGlobals.contacts) renderChatList() renderMailList(data.mails, false) renderMarked(data.marked) @@ -1368,7 +1371,7 @@ cardContainer.setAttribute("background-color", color) initial.setAttribute(`style`, `background-color: ${color};`) - if(contactOnly){ + if(contactOnly || type === 'contact'){ if(isAdmin){ let adminTag = document.createElement('p') adminTag.textContent = 'Admin' @@ -1376,13 +1379,7 @@ adminTag.classList.add('admin-tag') cardContainer.append(adminTag) } - return card; } - else if(type === 'contact'){ - let duplicateCard = card.cloneNode(true); - getRef('contacts_container').append(card); - getRef('mail_contact_list').append(duplicateCard); - } else{ //render chat card for newly added contact if(type === 'chat') @@ -1426,17 +1423,12 @@ }) .catch(error => console.error(error)) if(prepend){ - getRef('chat_container').prepend(card); activeChat['floID'] = floID if(activeChat['chatCard']) activeChat['chatCard'].classList.remove('active') - getRef('chat_container').children[0].classList.add('active') - activeChat['chatCard'] = getRef('chat_container').children[0] - } - else{ - getRef('chat_container').append(card); } } + return card }, messageBubble(msg){ let {admin = false, newMembers = [], rmMembers = [], groupID, name, description, sender, floID, message, time: timestamp, category, unconfirmed = false, updateChatCard = false} = msg @@ -1716,7 +1708,7 @@ getRef('search_chats').addEventListener('input', function() { if(this.value.trim !== ''){ for(child of getRef('chat_container').children) { - if(child.getAttribute('name').toUpperCase().indexOf(this.value.toUpperCase()) > -1){ + if(child.getAttribute('name').toLowerCase().includes(this.value.toLowerCase()) || child.getAttribute('flo-id').toLowerCase().includes(this.value.toLowerCase())){ child.classList.remove('hide-completely') } else{ @@ -1726,6 +1718,21 @@ } }) + getRef('search_contacts').addEventListener('input', function() { + const contacts = {} + if(this.value.trim !== ''){ + for(cont in floGlobals.contacts){ + if(cont.toLowerCase().includes(this.value.toLowerCase()) || floGlobals.contacts[cont].toLowerCase().includes(this.value.toLowerCase())) + contacts[cont] = floGlobals.contacts[cont] + } + getRef('contacts_container').innerHTML = '' + renderContactList(contacts) + } + if([...contacts].length){ + + } + }) + document.addEventListener('click', e => { if(e.target.closest('.sidebar-item')){ let target = e.target.closest('.sidebar-item') @@ -1827,8 +1834,6 @@ } else{ createRipple(e, contact) - if(!contact.closest('chat_container')) - contact = getRef('chat_container').querySelector(`[flo-id="${clickedContact['floID']}"]`) contact.classList.remove('unread') if(activeChat['chatCard'] === contact && window.innerWidth > 640) return showChatDetails({show: false, animate: false}) @@ -2086,6 +2091,7 @@ let contactsDrawerAnimation function showContacts(show = true){ if(show){ + renderContactList(floGlobals.contacts) getRef('all_contacts').classList.remove('hide-completely') contactsDrawerAnimation = animateTo(getRef('all_contacts'), [ {transform: 'translateY(2rem)'}, @@ -2104,6 +2110,7 @@ getRef('selected_contacts').classList.add('hide-completely') getRef('create_group_button').classList.add('hide-completely') getRef('show_contact_popup_button').classList.remove('hide-completely') + getRef('contacts_container').innerHTML = '' } } } @@ -2308,7 +2315,9 @@ } else{ messenger.addChat(receiver) - render.contactCard(receiver, {type: 'chat', prepend: true}) + getRef('chat_container').prepend(render.contactCard(receiver, {type: 'chat', prepend: true})) + getRef('chat_container').children[0].classList.add('active') + activeChat['chatCard'] = getRef('chat_container').children[0] } scrollToBottom() if(activeChat.isGroup) @@ -2346,18 +2355,21 @@ return } messenger.storeContact(floID, name).then(result => { - render.contactCard(floID, {name, type: 'contact'}) + getRef('contacts_container').append(render.contactCard(floID, {name, type: 'contact'})) hidePopup() notify(`Added Contact: ${floID}`) }).catch(error => notify(error, "error")); } function renderContactList(contactList = {}) { + const frag = document.createDocumentFragment() for (floID in contactList) - render.contactCard(floID, {type: 'contact'}) + frag.append(render.contactCard(floID, {type: 'contact'})) + getRef('contacts_container').append(frag) } async function renderChatList() { + const frag = document.createDocumentFragment() getRef('chat_container').innerHTML = '' for (floID of messenger.getChatOrder().mixed){ const markUnread = floGlobals.marked[floID]?.[0] === 'unread' ? true : false @@ -2366,8 +2378,9 @@ type = 'chat' else if(floGlobals.groups[floID]) type = 'group' - render.contactCard(floID, {type, markUnread}) + frag.append(render.contactCard(floID, {type, markUnread})) } + getRef('chat_container').append(frag) } function renderMarked(data) { @@ -2827,6 +2840,8 @@ getRef(target).classList.toggle('expand') if(getRef(target).classList.contains('expand')) getRef(target).children[1].focusIn() + else + getRef(target).querySelector('sm-input').value = '' } let isChatDetailsOpen = false