fix: auto-open chat with conversation ID, show listing title and time in messages

This commit is contained in:
2026-02-10 07:58:16 +01:00
parent 73769d6af2
commit 8479fa2071
11 changed files with 73 additions and 22 deletions

View File

@@ -12,7 +12,7 @@ import { reputationService } from '../services/reputation.js'
class ChatWidget extends HTMLElement {
static get observedAttributes() {
return ['listing-id', 'recipient-name', 'seller-public-key']
return ['listing-id', 'recipient-name', 'seller-public-key', 'conversation-id']
}
constructor() {
@@ -33,6 +33,7 @@ class ChatWidget extends HTMLElement {
this.listingId = this.getAttribute('listing-id')
this.recipientName = this.getAttribute('recipient-name') || 'Seller'
this.sellerPublicKey = this.getAttribute('seller-public-key')
this.conversationId = this.getAttribute('conversation-id')
this.render()
}
@@ -45,6 +46,7 @@ class ChatWidget extends HTMLElement {
if (this._initialized) return
this._initialized = true
this.conversationId = this.getAttribute('conversation-id') || this.conversationId
await cryptoService.ready
if (!cryptoService.getPublicKey()) {
@@ -68,26 +70,39 @@ class ChatWidget extends HTMLElement {
async initConversation() {
try {
if (!this.sellerPublicKey) {
this.error = 'no-seller-key'
this.loading = false
this.render()
return
}
if (this.conversationId) {
this.conversation = await conversationsService.getConversation(this.conversationId)
if (!this.conversation) {
this.error = 'init-failed'
this.loading = false
this.render()
return
}
this.mySecretKey = await conversationsService.getMySecretKeyForConversation(this.conversation)
await this.loadMessages()
await this.loadDealState()
} else {
if (!this.sellerPublicKey) {
this.error = 'no-seller-key'
this.loading = false
this.render()
return
}
const pinStatus = keyPinningService.check(this.listingId, this.sellerPublicKey)
if (pinStatus === 'changed') {
this.keyWarning = true
this.loading = false
this.render()
this.setupEventListeners()
return
}
const pinStatus = keyPinningService.check(this.listingId, this.sellerPublicKey)
if (pinStatus === 'changed') {
this.keyWarning = true
this.loading = false
this.render()
this.setupEventListeners()
return
}
this.conversation = await conversationsService.startOrGetConversation(this.listingId, this.sellerPublicKey)
this.mySecretKey = await conversationsService.getMySecretKeyForConversation(this.conversation)
await this.loadMessages()
await this.loadDealState()
this.conversation = await conversationsService.startOrGetConversation(this.listingId, this.sellerPublicKey)
this.mySecretKey = await conversationsService.getMySecretKeyForConversation(this.conversation)
await this.loadMessages()
await this.loadDealState()
}
} catch (e) {
console.error('Failed to init conversation:', e)
this.error = 'init-failed'