refactor: reuse getConversations in messages, prevent duplicate favorites on sync
This commit is contained in:
@@ -48,31 +48,8 @@ class PageMessages extends HTMLElement {
|
||||
return
|
||||
}
|
||||
|
||||
// Load conversations for current user (matched by participant hash)
|
||||
const userHash = await auth.hashString(user.id)
|
||||
|
||||
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.conversations = await directus.getConversations(userHash) || []
|
||||
this.loading = false
|
||||
this.updateContent()
|
||||
} catch (err) {
|
||||
|
||||
@@ -630,6 +630,7 @@ class DirectusService {
|
||||
'*',
|
||||
'listing_id.id',
|
||||
'listing_id.title',
|
||||
'listing_id.status',
|
||||
'listing_id.images.directus_files_id.id'
|
||||
],
|
||||
filter: {
|
||||
|
||||
@@ -108,6 +108,12 @@ class FavoritesService {
|
||||
async addRemote(listingId) {
|
||||
const user = await auth.getUser()
|
||||
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', {
|
||||
user: user.id,
|
||||
listing: listingId
|
||||
|
||||
Reference in New Issue
Block a user