refactor: reuse getConversations in messages, prevent duplicate favorites on sync

This commit is contained in:
2026-02-08 10:51:13 +01:00
parent 45e7f9dde7
commit 013d591e75
3 changed files with 8 additions and 24 deletions

View File

@@ -48,31 +48,8 @@ class PageMessages extends HTMLElement {
return return
} }
// Load conversations for current user (matched by participant hash)
const userHash = await auth.hashString(user.id) const userHash = await auth.hashString(user.id)
this.conversations = await directus.getConversations(userHash) || []
const response = await directus.get('/items/conversations', {
fields: [
'id',
'date_created',
'date_updated',
'listing_id.id',
'listing_id.title',
'listing_id.status',
'listing_id.images.directus_files_id.id',
'status'
],
filter: {
_or: [
{ participant_hash_1: { _eq: userHash } },
{ participant_hash_2: { _eq: userHash } }
]
},
sort: ['-date_updated'],
limit: 50
})
this.conversations = response.data || []
this.loading = false this.loading = false
this.updateContent() this.updateContent()
} catch (err) { } catch (err) {

View File

@@ -630,6 +630,7 @@ class DirectusService {
'*', '*',
'listing_id.id', 'listing_id.id',
'listing_id.title', 'listing_id.title',
'listing_id.status',
'listing_id.images.directus_files_id.id' 'listing_id.images.directus_files_id.id'
], ],
filter: { filter: {

View File

@@ -108,6 +108,12 @@ class FavoritesService {
async addRemote(listingId) { async addRemote(listingId) {
const user = await auth.getUser() const user = await auth.getUser()
if (!user) return if (!user) return
const existing = await directus.get('/items/favorites', {
filter: { user: { _eq: user.id }, listing: { _eq: listingId } },
fields: ['id'],
limit: 1
})
if (existing.data?.length > 0) return
await directus.post('/items/favorites', { await directus.post('/items/favorites', {
user: user.id, user: user.id,
listing: listingId listing: listingId