From 52734ba854f9eb05fb6b9dede7eb334d12e0d390 Mon Sep 17 00:00:00 2001 From: Bruno Michel Date: Thu, 10 Oct 2024 17:22:37 +0200 Subject: [PATCH] Fix the myself contact at instance creation - add the displayName - add the index.byFamilyNameGivenNameEmailCozyUrl In theory, there is a service from the contacts webapp that adds them, launched via an `@vevent` trigger on the io.cozy.contacts. But, the stack creates the myself contact before installing the contacts webapp at instance creation. Thus, the service is not launched. The easy fix is to just add the missing field when creating the myself contact. --- model/contact/contacts.go | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/model/contact/contacts.go b/model/contact/contacts.go index b076912da10..a1afa2212b4 100644 --- a/model/contact/contacts.go +++ b/model/contact/contacts.go @@ -260,16 +260,33 @@ func FindByEmail(db prefixer.Prefixer, email string) (*Contact, error) { func CreateMyself(inst *instance.Instance, settings *couchdb.JSONDoc) (*Contact, error) { doc := New() doc.JSONDoc.M["me"] = true - if name, ok := settings.M["public_name"]; ok { - doc.JSONDoc.M["fullname"] = name - } - if email, ok := settings.M["email"]; ok { + email, ok := settings.M["email"].(string) + if ok { doc.JSONDoc.M["email"] = []map[string]interface{}{ {"address": email, "primary": true}, } } + name, _ := settings.M["public_name"].(string) + displayName := name + if name == "" { + parts := strings.SplitN(email, "@", 2) + name = parts[0] + displayName = email + } + if name != "" { + doc.JSONDoc.M["fullname"] = name + doc.JSONDoc.M["displayName"] = displayName + } + cozyURL := inst.PageURL("", nil) doc.JSONDoc.M["cozy"] = []map[string]interface{}{ - {"url": inst.PageURL("", nil), "primary": true}, + {"url": cozyURL, "primary": true}, + } + index := email + if index == "" { + index = cozyURL + } + doc.JSONDoc.M["indexes"] = map[string]interface{}{ + "byFamilyNameGivenNameEmailCozyUrl": index, } if err := couchdb.CreateDoc(inst, doc); err != nil { return nil, err