Skip to content

Commit

Permalink
add GetContact method
Browse files Browse the repository at this point in the history
  • Loading branch information
Sagleft committed Jul 18, 2022
1 parent 4778be9 commit 22a7478
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ func (c *UtopiaClient) SendInstantMessage(to string, message string) (int64, err
return c.queryResultToInt("sendInstantMessage", params)
}

// GetContacts - get account contacts
// GetContacts - get account contacts.
// params: filter - contact pubkey or nickname
func (c *UtopiaClient) GetContacts(filter string) ([]ContactData, error) {
// send request
params := map[string]interface{}{}
Expand Down Expand Up @@ -257,6 +258,19 @@ func (c *UtopiaClient) GetContacts(filter string) ([]ContactData, error) {
return contacts, nil
}

// GetContact data
func (c *UtopiaClient) GetContact(pubkeyOrNick string) (ContactData, error) {
contacts, err := c.GetContacts(pubkeyOrNick)
if err != nil {
return ContactData{}, err
}

if len(contacts) == 0 {
return ContactData{}, errors.New("contact not found")
}
return contacts[0], nil
}

// IsOnline - is contact online?
func (d *ContactData) IsOnline() bool {
return d.Status == 4096
Expand Down

0 comments on commit 22a7478

Please sign in to comment.