feat(search): align conversation identity search
This commit is contained in:
@@ -142,12 +142,13 @@ func timestampPtr(value *int64) int64 {
|
||||
|
||||
func ConversationDocument(conv model.Conversation) SearchDocument {
|
||||
inboxID := conv.InboxID
|
||||
content := conversationSearchContent(conv)
|
||||
doc := SearchDocument{
|
||||
ID: conv.ID,
|
||||
Type: ResultTypeConversation,
|
||||
AccountID: conv.AccountID,
|
||||
Title: fmt.Sprintf("Conversation #%d", conv.ID),
|
||||
Content: conv.Labels,
|
||||
Title: conversationSearchTitle(conv),
|
||||
Content: content,
|
||||
Status: conv.Status,
|
||||
Priority: conv.Priority,
|
||||
Labels: splitLabels(conv.Labels),
|
||||
@@ -165,6 +166,24 @@ func ConversationDocument(conv model.Conversation) SearchDocument {
|
||||
return doc
|
||||
}
|
||||
|
||||
func conversationSearchTitle(conv model.Conversation) string {
|
||||
if conv.DisplayID != nil && *conv.DisplayID != 0 {
|
||||
return fmt.Sprintf("Conversation #%d", *conv.DisplayID)
|
||||
}
|
||||
return fmt.Sprintf("Conversation #%d", conv.ID)
|
||||
}
|
||||
|
||||
func conversationSearchContent(conv model.Conversation) string {
|
||||
parts := make([]string, 0, 5)
|
||||
if conv.DisplayID != nil && *conv.DisplayID != 0 {
|
||||
parts = append(parts, fmt.Sprintf("%d", *conv.DisplayID))
|
||||
}
|
||||
if conv.Contact != nil {
|
||||
parts = append(parts, conv.Contact.Name, conv.Contact.Email, conv.Contact.PhoneNumber, conv.Contact.Identifier)
|
||||
}
|
||||
return strings.TrimSpace(strings.Join(parts, " "))
|
||||
}
|
||||
|
||||
func MessageDocument(msg model.Message) SearchDocument {
|
||||
inboxID := msg.InboxID
|
||||
conversationID := msg.ConversationID
|
||||
|
||||
@@ -48,6 +48,9 @@ func TestDocumentBuildersSetStableUIDAndType(t *testing.T) {
|
||||
conv.InboxID = 7
|
||||
conv.ContactID = 9
|
||||
conv.LastActivityAt = &lastActivity
|
||||
displayID := uint(42)
|
||||
conv.DisplayID = &displayID
|
||||
conv.Contact = &model.Contact{Name: "Ada Lovelace", Email: "ada@example.com", PhoneNumber: "+123", Identifier: "ada-id"}
|
||||
doc := ConversationDocument(conv)
|
||||
|
||||
assert.Equal(t, "3:conversation:12", doc.UID)
|
||||
@@ -55,6 +58,8 @@ func TestDocumentBuildersSetStableUIDAndType(t *testing.T) {
|
||||
assert.Equal(t, uint(3), doc.AccountID)
|
||||
assert.Equal(t, []string{"billing", "urgent"}, doc.Labels)
|
||||
assert.Equal(t, lastActivity, doc.LastActivityAtTS)
|
||||
assert.Equal(t, "Conversation #42", doc.Title)
|
||||
assert.Equal(t, "42 Ada Lovelace ada@example.com +123 ada-id", doc.Content)
|
||||
}
|
||||
|
||||
func TestContactDocumentSetsResolvedScopeFields(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user