fix: auto-open chat with conversation ID, show listing title and time in messages
This commit is contained in:
@@ -75,6 +75,16 @@ class PageListing extends HTMLElement {
|
||||
this.render()
|
||||
this.setupEventListeners()
|
||||
this.updateMetaTags()
|
||||
|
||||
if (this.dataset.chat && auth.isLoggedIn()) {
|
||||
const chatWidget = this.querySelector('chat-widget')
|
||||
if (this.dataset.chat !== '1') {
|
||||
chatWidget?.setAttribute('conversation-id', this.dataset.chat)
|
||||
}
|
||||
const dialog = this.querySelector('#contact-dialog')
|
||||
dialog?.showModal()
|
||||
chatWidget?.activate()
|
||||
}
|
||||
}
|
||||
|
||||
updateMetaTags() {
|
||||
|
||||
@@ -51,6 +51,17 @@ class PageMessages extends HTMLElement {
|
||||
|
||||
const conversations = await conversationsService.getMyConversations()
|
||||
this.conversations = conversations || []
|
||||
|
||||
const missing = this.conversations.filter(c => typeof c.listing_id !== 'object')
|
||||
if (missing.length > 0) {
|
||||
await Promise.all(missing.map(async conv => {
|
||||
try {
|
||||
const listing = await directus.getListing(conv.listing_id)
|
||||
if (listing) conv.listing_id = listing
|
||||
} catch { /* listing may not be accessible */ }
|
||||
}))
|
||||
}
|
||||
|
||||
this.loading = false
|
||||
this.updateContent()
|
||||
} catch (err) {
|
||||
@@ -139,11 +150,13 @@ class PageMessages extends HTMLElement {
|
||||
const listingId = listing?.id || conv.listing_id
|
||||
const imageId = listing?.images?.[0]?.directus_files_id?.id
|
||||
const imageUrl = imageId ? directus.getThumbnailUrl(imageId, 80) : ''
|
||||
const title = listing?.status === 'deleted' ? t('messages.listingRemoved') : (listing?.title || t('messages.unknownListing'))
|
||||
const title = listing?.status === 'deleted'
|
||||
? t('messages.listingRemoved')
|
||||
: (listing?.title || t('messages.listing'))
|
||||
const dateStr = this.formatDate(conv.date_updated || conv.date_created)
|
||||
|
||||
return /* html */`
|
||||
<a href="#/listing/${listingId}" class="conversation-item" data-conv-id="${conv.id}">
|
||||
<a href="#/listing/${listingId}?chat=${conv.id}" class="conversation-item" data-conv-id="${conv.id}">
|
||||
<div class="conversation-image">
|
||||
${imageUrl
|
||||
? `<img src="${imageUrl}" alt="" loading="lazy">`
|
||||
@@ -165,7 +178,7 @@ class PageMessages extends HTMLElement {
|
||||
const diffMs = now - date
|
||||
const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24))
|
||||
|
||||
if (diffDays === 0) return t('messages.today')
|
||||
if (diffDays === 0) return `${t('messages.today')}, ${date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}`
|
||||
if (diffDays === 1) return t('messages.yesterday')
|
||||
if (diffDays < 7) return t('messages.daysAgo', { days: diffDays })
|
||||
|
||||
|
||||
Reference in New Issue
Block a user