forked from textileio/go-textile
/
contacts.go
65 lines (55 loc) · 1.31 KB
/
contacts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package mobile
import (
"github.com/pkg/errors"
"github.com/textileio/textile-go/core"
)
// AddContact calls core AddContact
func (m *Mobile) AddContact(id string, address string, username string) error {
return m.node.AddContact(id, address, username)
}
// Contact calls core Contact
func (m *Mobile) Contact(id string) (string, error) {
if !m.node.Started() {
return "", core.ErrStopped
}
contact := m.node.Contact(id)
if contact != nil {
return toJSON(contact)
}
return "", errors.New("contact not found")
}
// Contacts calls core Contacts
func (m *Mobile) Contacts() (string, error) {
if !m.node.Started() {
return "", core.ErrStopped
}
contacts, err := m.node.Contacts()
if err != nil {
return "", err
}
if len(contacts) == 0 {
contacts = make([]core.ContactInfo, 0)
}
return toJSON(contacts)
}
// ContactUsername calls core ContactUsername
func (m *Mobile) ContactUsername(id string) string {
if !m.node.Started() {
return ""
}
return m.node.ContactUsername(id)
}
// ContactThreads calls core ContactThreads
func (m *Mobile) ContactThreads(id string) (string, error) {
if !m.node.Started() {
return "", core.ErrStopped
}
infos, err := m.node.ContactThreads(id)
if err != nil {
return "", err
}
if len(infos) == 0 {
infos = make([]core.ThreadInfo, 0)
}
return toJSON(infos)
}