bug fixes
This commit is contained in:
parent
37faa9b928
commit
7abb09772c
121
index.html
121
index.html
@ -238,7 +238,7 @@
|
|||||||
<path d="M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z"></path>
|
<path d="M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z"></path>
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
<sm-input id="search_chats" type="search" placeholder="Search"></sm-input>
|
<sm-input id="search_chats" type="search" placeholder="Search FLO ID or name"></sm-input>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
<button id="new_message_button" onclick="openPopup('new_message_popup')"
|
<button id="new_message_button" onclick="openPopup('new_message_popup')"
|
||||||
@ -643,6 +643,7 @@
|
|||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
<h4>Compose Mail</h4>
|
<h4>Compose Mail</h4>
|
||||||
|
<p>You can send mail to multiple FLO IDs by entering comma separated IDs </p>
|
||||||
</header>
|
</header>
|
||||||
<sm-form>
|
<sm-form>
|
||||||
<div id="auto_complete_contact" class="flex flex-direction-column">
|
<div id="auto_complete_contact" class="flex flex-direction-column">
|
||||||
@ -1302,7 +1303,11 @@
|
|||||||
case 'time-only':
|
case 'time-only':
|
||||||
return finalHours;
|
return finalHours;
|
||||||
case 'relative':
|
case 'relative':
|
||||||
return relativeTime.from(timestamp)
|
// check if timestamp is older than a day
|
||||||
|
if (Date.now() - new Date(timestamp) < 60 * 60 * 24 * 1000)
|
||||||
|
return `${finalHours}`;
|
||||||
|
else
|
||||||
|
return relativeTime.from(timestamp)
|
||||||
default:
|
default:
|
||||||
return `${month} ${date}, ${year} at ${finalHours}`;
|
return `${month} ${date}, ${year} at ${finalHours}`;
|
||||||
}
|
}
|
||||||
@ -2018,28 +2023,12 @@
|
|||||||
}
|
}
|
||||||
if (type !== 'contact') {
|
if (type !== 'contact') {
|
||||||
//render chat card for newly added contact
|
//render chat card for newly added contact
|
||||||
messenger.getChat(floID).then(chat => {
|
getLastMessage(floID).then(lastMessage => {
|
||||||
|
const { lastText, time } = lastMessage
|
||||||
const chatCard = getRef('chats_list').querySelector(`.chat[data-flo-id="${floID}"], .group[data-flo-id="${floID}"]`)
|
const chatCard = getRef('chats_list').querySelector(`.chat[data-flo-id="${floID}"], .group[data-flo-id="${floID}"]`)
|
||||||
if (chatCard && !chatCard.querySelector('.last-message')) {
|
if (chatCard && !chatCard.querySelector('.last-message')) {
|
||||||
let lastMessage = Object.values(chat).reverse().find(({ message }) => message) || { message: '', time: 0 }
|
|
||||||
if (type === 'group' && lastMessage.time === 0)
|
|
||||||
lastMessage.time = messenger.groups[floID].created
|
|
||||||
const amISender = type === 'chat' && lastMessage.category === 'sent' || type === 'group' && lastMessage.sender === myFloID
|
|
||||||
let lastText = ''
|
|
||||||
if (amISender) {
|
|
||||||
lastText = `You: ${lastMessage.message}`
|
|
||||||
} else {
|
|
||||||
if (type === 'group') {
|
|
||||||
if (lastMessage.sender)
|
|
||||||
lastText = `${getContactName(lastMessage.sender)}: ${lastMessage.message}`
|
|
||||||
else
|
|
||||||
lastText = 'Group created'
|
|
||||||
} else {
|
|
||||||
lastText = lastMessage.message
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const timeAndOptions = html`
|
const timeAndOptions = html`
|
||||||
<time class="time">${lastMessage.time ? getFormattedTime(lastMessage.time, 'relative') : ''}</time>
|
<time class="time">${time ? getFormattedTime(time, 'relative') : ''}</time>
|
||||||
<div class="span-2">
|
<div class="span-2">
|
||||||
<p class="last-message">${lastText}</p>
|
<p class="last-message">${lastText}</p>
|
||||||
<button class="menu">
|
<button class="menu">
|
||||||
@ -2201,6 +2190,41 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getLastMessage(floID) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let type
|
||||||
|
if (messenger.chats[floID])
|
||||||
|
type = 'chat'
|
||||||
|
else if (messenger.groups[floID])
|
||||||
|
type = 'group'
|
||||||
|
messenger.getChat(floID).then(chat => {
|
||||||
|
let lastMessage = Object.values(chat).reverse().find(({ message }) => message) || { message: '', time: 0 }
|
||||||
|
let { message, time, sender, category } = lastMessage
|
||||||
|
if (type === 'group' && time === 0)
|
||||||
|
lastMessage.time = messenger.groups[floID].created
|
||||||
|
const amISender = type === 'chat' && category === 'sent' || type === 'group' && sender === myFloID
|
||||||
|
lastMessage.lastMessage = ''
|
||||||
|
if (messenger.blocked.has(floID)) {
|
||||||
|
lastMessage.lastText = 'Blocked conversation'
|
||||||
|
} else {
|
||||||
|
if (amISender) {
|
||||||
|
lastMessage.lastText = `You: ${lastMessage.message}`
|
||||||
|
} else {
|
||||||
|
if (type === 'group') {
|
||||||
|
if (sender)
|
||||||
|
lastMessage.lastText = `${getContactName(sender)}: ${message}`
|
||||||
|
else
|
||||||
|
lastMessage.lastText = 'Group created'
|
||||||
|
} else {
|
||||||
|
lastMessage.lastText = message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resolve(lastMessage)
|
||||||
|
}).catch(error => reject(error))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const hasURL = text => /[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/.test(text)
|
const hasURL = text => /[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/.test(text)
|
||||||
|
|
||||||
const isEmoji = (txt) => {
|
const isEmoji = (txt) => {
|
||||||
@ -2921,17 +2945,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function renderChatList(chatOrder) {
|
async function renderChatList(chatOrder) {
|
||||||
const chats = []
|
const chats = chatOrder.map(floID => {
|
||||||
chatOrder.forEach(floID => {
|
const markUnread = messenger.marked[floID]?.includes('unread')
|
||||||
if (!messenger.blocked.has(floID)) {
|
let type
|
||||||
const markUnread = messenger.marked[floID]?.includes('unread')
|
if (messenger.chats[floID])
|
||||||
let type
|
type = 'chat'
|
||||||
if (messenger.chats[floID])
|
else if (messenger.groups[floID])
|
||||||
type = 'chat'
|
type = 'group'
|
||||||
else if (messenger.groups[floID])
|
return render.contactCard(floID, { type, markUnread })
|
||||||
type = 'group'
|
|
||||||
chats.push(render.contactCard(floID, { type, markUnread }))
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
renderElem(getRef('chats_list'), html`${chats}`)
|
renderElem(getRef('chats_list'), html`${chats}`)
|
||||||
}
|
}
|
||||||
@ -3254,25 +3275,25 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function markAsUnread() {
|
function markAsUnread() {
|
||||||
clickedContact.chatCard.classList.add('unread')
|
getRef('chats_list').querySelector(`.chat[data-flo-id="${floGlobals.activeFloID}"], .group[data-flo-id="${floGlobals.activeFloID}"]`).classList.add('unread')
|
||||||
messenger.addMark(clickedContact.floID, 'unread')
|
messenger.addMark(floGlobals.activeFloID, 'unread')
|
||||||
closePopup()
|
closePopup()
|
||||||
}
|
}
|
||||||
|
|
||||||
function markAsRead() {
|
function markAsRead() {
|
||||||
clickedContact.chatCard.classList.remove('unread')
|
const chatCard = getRef('chats_list').querySelector(`.chat[data-flo-id="${floGlobals.activeFloID}"], .group[data-flo-id="${floGlobals.activeFloID}"]`);
|
||||||
messenger.removeMark(clickedContact.floID, 'unread')
|
chatCard.classList.remove('unread')
|
||||||
|
messenger.removeMark(floGlobals.activeFloID, 'unread')
|
||||||
closePopup()
|
closePopup()
|
||||||
}
|
}
|
||||||
|
|
||||||
function blockUser() {
|
function blockUser() {
|
||||||
getConfirmation('Block this FLO ID?', { message: `Are you sure to block this FLO ID?`, confirmText: 'Block', cancelText: 'Cancel' }).then(confirmed => {
|
getConfirmation('Block this FLO ID?', { message: `Are you sure to block this FLO ID?`, confirmText: 'Block', cancelText: 'Cancel' }).then(confirmed => {
|
||||||
if (confirmed) {
|
if (confirmed) {
|
||||||
messenger.blockUser(clickedContact.floID).then(result => {
|
messenger.blockUser(floGlobals.activeFloID).then(result => {
|
||||||
clickedContact.chatCard.remove()
|
const chatCard = getRef('chats_list').querySelector(`.chat[data-flo-id="${floGlobals.activeFloID}"], .group[data-flo-id="${floGlobals.activeFloID}"]`);
|
||||||
clickedContact.chatCard = ''
|
chatCard.querySelector('.last-message').textContent = 'This user is blocked'
|
||||||
closePopup()
|
closePopup()
|
||||||
getRef('chat_view').classList.add('hide')
|
|
||||||
notify('FLO ID blocked', 'success')
|
notify('FLO ID blocked', 'success')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -3281,8 +3302,16 @@
|
|||||||
function unblockUser(floID) {
|
function unblockUser(floID) {
|
||||||
getConfirmation('Unblock this FLO ID?', { message: `Are you sure to unblock this FLO ID?`, confirmText: 'Unblock', cancelText: 'Cancel' }).then(confirmed => {
|
getConfirmation('Unblock this FLO ID?', { message: `Are you sure to unblock this FLO ID?`, confirmText: 'Unblock', cancelText: 'Cancel' }).then(confirmed => {
|
||||||
if (confirmed) {
|
if (confirmed) {
|
||||||
messenger.unblockUser(floID || clickedContact.floID).then(result => {
|
messenger.unblockUser(floID || floGlobals.activeFloID).then(result => {
|
||||||
|
const chatCard = getRef('chats_list').querySelector(`.chat[data-flo-id="${floGlobals.activeFloID}"], .group[data-flo-id="${floGlobals.activeFloID}"]`);
|
||||||
|
getLastMessage(floGlobals.activeFloID).then(({ lastText }) => {
|
||||||
|
chatCard.querySelector('.last-message').textContent = lastText
|
||||||
|
}).catch(error => {
|
||||||
|
console.log(error)
|
||||||
|
})
|
||||||
|
chatCard.querySelector('.last-message').textContent = 'This user is unblocked'
|
||||||
notify('FLo ID unblocked', 'success')
|
notify('FLo ID unblocked', 'success')
|
||||||
|
closePopup()
|
||||||
render.blockedList()
|
render.blockedList()
|
||||||
renderChatList(messenger.getChatOrder())
|
renderChatList(messenger.getChatOrder())
|
||||||
})
|
})
|
||||||
@ -3297,8 +3326,8 @@
|
|||||||
function clearChat() {
|
function clearChat() {
|
||||||
getConfirmation('Clear chat?', { message: `Are you sure to clear this chat?`, confirmText: 'Clear', cancelText: 'Cancel' }).then(confirmed => {
|
getConfirmation('Clear chat?', { message: `Are you sure to clear this chat?`, confirmText: 'Clear', cancelText: 'Cancel' }).then(confirmed => {
|
||||||
if (confirmed) {
|
if (confirmed) {
|
||||||
messenger.clearChat(clickedContact.floID).then(result => {
|
messenger.clearChat(floGlobals.activeFloID).then(result => {
|
||||||
let chatCard = getRef('chats_list').querySelector(`.chat[data-flo-id="${clickedContact.floID}"], .group[data-flo-id="${clickedContact.floID}"]`)
|
let chatCard = getRef('chats_list').querySelector(`.chat[data-flo-id="${floGlobals.activeFloID}"], .group[data-flo-id="${floGlobals.activeFloID}"]`)
|
||||||
if (chatCard) {
|
if (chatCard) {
|
||||||
chatCard.querySelector('.last-message').textContent = ''
|
chatCard.querySelector('.last-message').textContent = ''
|
||||||
chatCard.querySelector('.time').textContent = ''
|
chatCard.querySelector('.time').textContent = ''
|
||||||
@ -3314,9 +3343,9 @@
|
|||||||
function deleteChat() {
|
function deleteChat() {
|
||||||
getConfirmation('Delete chat', { message: `Are you sure to delete this chat?`, confirmText: 'Delete', cancelText: 'No' }).then(confirmed => {
|
getConfirmation('Delete chat', { message: `Are you sure to delete this chat?`, confirmText: 'Delete', cancelText: 'No' }).then(confirmed => {
|
||||||
if (confirmed) {
|
if (confirmed) {
|
||||||
messenger.rmChat(clickedContact.floID).then(result => {
|
messenger.rmChat(floGlobals.activeFloID).then(result => {
|
||||||
clickedContact.chatCard.remove()
|
const chatCard = getRef('chats_list').querySelector(`.chat[data-flo-id="${floGlobals.activeFloID}"], .group[data-flo-id="${floGlobals.activeFloID}"]`);
|
||||||
clickedContact.chatCard = ''
|
chatCard.remove()
|
||||||
closePopup()
|
closePopup()
|
||||||
getRef('chat_view').classList.add('hide')
|
getRef('chat_view').classList.add('hide')
|
||||||
notify('Chat deleted', 'success')
|
notify('Chat deleted', 'success')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user