refactor: reuse getConversations in messages, prevent duplicate favorites on sync
This commit is contained in:
@@ -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) {
|
||||||
|
|||||||
@@ -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: {
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user