From 436ed84a7ff6a09cb32277b8e0b54ec3fe0bebe0 Mon Sep 17 00:00:00 2001 From: "aaron@nanu-c.org" Date: Wed, 31 Aug 2022 13:09:31 +0200 Subject: [PATCH] expose get profile by uuid --- profiles/profile.go | 4 ++-- server.go | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/profiles/profile.go b/profiles/profile.go index 4f79773..ab80e2d 100644 --- a/profiles/profile.go +++ b/profiles/profile.go @@ -360,7 +360,7 @@ func GetProfileE164(tel string) (contacts.Contact, error) { } // GetProfileUUID get a profile by a phone number -func GetProfileUUID(uuid string) (*contacts.Contact, error) { +func GetProfileUUID(uuid string) (*Profile, error) { c := contacts.Contacts[uuid] profile := &Profile{} var err error @@ -440,5 +440,5 @@ func GetProfileUUID(uuid string) (*contacts.Contact, error) { } contacts.Contacts[c.UUID] = c contacts.WriteContactsToPath() - return &c, nil + return profile, nil } diff --git a/server.go b/server.go index ff1308c..81b516e 100644 --- a/server.go +++ b/server.go @@ -370,8 +370,18 @@ func GetProfile(uuid string, profileKey []byte) (*profiles.Profile, error) { } return profile, nil } +func GetProfileByUUID(uuid string) (*profiles.Profile, error) { + profile, err := profiles.GetProfileUUID(uuid) + if err != nil { + return nil, err + } + return profile, nil +} func GetProfileAndCredential(uuid string, profileKey []byte) (*profiles.Profile, error) { + if uuid == "" || len(profileKey) == 0 { + return nil, fmt.Errorf("uuid or profileKey is empty") + } profile, err := profiles.GetProfileAndCredential(uuid, profileKey) if err != nil { return nil, err