Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions frontend/src/features/conversation/list/ConversationListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@

<!-- Content container -->
<div class="flex-1 min-w-0 space-y-2">
<!-- Contact name and last message time -->
<!-- Contact name, reference number, and last message time -->
<div class="flex items-center justify-between gap-2">
<h3 class="text-sm font-semibold truncate">
{{ contactFullName }}
</h3>
<div class="flex items-center gap-2 min-w-0">
<h3 class="text-sm font-semibold truncate">
{{ contactFullName }}
</h3>
<span v-if="conversation.reference_number" class="text-xs font-mono text-muted-foreground whitespace-nowrap">
#{{ conversation.reference_number }}
</span>
</div>
<span class="text-xs text-gray-400 whitespace-nowrap" v-if="conversation.last_message_at">
{{ relativeLastMessageTime }}
</span>
Expand Down
1 change: 1 addition & 0 deletions internal/conversation/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type ConversationListItem struct {
CreatedAt time.Time `db:"created_at" json:"created_at"`
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
UUID string `db:"uuid" json:"uuid"`
ReferenceNumber string `db:"reference_number" json:"reference_number"`
WaitingSince null.Time `db:"waiting_since" json:"waiting_since"`
Contact ConversationListContact `db:"contact" json:"contact"`
InboxChannel string `db:"inbox_channel" json:"inbox_channel"`
Expand Down
1 change: 1 addition & 0 deletions internal/conversation/queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ SELECT
conversations.created_at,
conversations.updated_at,
conversations.uuid,
conversations.reference_number,
conversations.waiting_since,
users.created_at as "contact.created_at",
users.updated_at as "contact.updated_at",
Expand Down
23 changes: 16 additions & 7 deletions internal/search/queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@ SELECT
conversations.reference_number,
conversations.subject
FROM conversations
WHERE reference_number::text = $1;
WHERE reference_number::text ILIKE '%' || $1 || '%'
OR subject ILIKE '%' || $1 || '%';

-- name: search-conversations-by-contact-email
SELECT
SELECT DISTINCT ON (conversations.id)
conversations.created_at,
conversations.uuid,
conversations.reference_number,
conversations.subject
COALESCE(conversations.subject, users.first_name || ' ' || users.last_name) as subject
FROM conversations
JOIN users ON conversations.contact_id = users.id
WHERE users.email = $1
ORDER BY conversations.created_at DESC
LIMIT 1000;
WHERE users.email ILIKE '%' || $1 || '%'
OR users.first_name ILIKE '%' || $1 || '%'
OR users.last_name ILIKE '%' || $1 || '%'
OR (users.first_name || ' ' || users.last_name) ILIKE '%' || $1 || '%'
Copy link
Owner

@abhinavxd abhinavxd Dec 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first_name, last_name, subject columns don't have an index. So on large databases this will be super slow.

ORDER BY conversations.id, conversations.created_at DESC
LIMIT 100;

-- name: search-messages
SELECT
Expand All @@ -40,5 +44,10 @@ SELECT
FROM users
WHERE type = 'contact'
AND deleted_at IS NULL
AND email ILIKE '%' || $1 || '%'
AND (
email ILIKE '%' || $1 || '%'
OR first_name ILIKE '%' || $1 || '%'
OR last_name ILIKE '%' || $1 || '%'
OR (first_name || ' ' || last_name) ILIKE '%' || $1 || '%'
)
LIMIT 15;