This repository was archived by the owner on Mar 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathinvites.go
97 lines (74 loc) · 1.76 KB
/
invites.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package mobile
import (
"github.com/golang/protobuf/proto"
"github.com/mr-tron/base58/base58"
"github.com/textileio/go-textile/core"
)
// AddInvite call core AddInvite
func (m *Mobile) AddInvite(threadId string, address string) error {
if !m.node.Started() {
return core.ErrStopped
}
err := m.node.AddInvite(threadId, address)
if err != nil {
return err
}
m.node.FlushCafes()
return nil
}
// AddExternalInvite generates a new external invite link to a thread
func (m *Mobile) AddExternalInvite(threadId string) ([]byte, error) {
if !m.node.Started() {
return nil, core.ErrStopped
}
invite, err := m.node.AddExternalInvite(threadId)
if err != nil {
return nil, err
}
m.node.FlushCafes()
return proto.Marshal(invite)
}
// Invites calls core Invites
func (m *Mobile) Invites() ([]byte, error) {
return proto.Marshal(m.node.Invites())
}
// AcceptInvite calls core AcceptInvite
func (m *Mobile) AcceptInvite(id string) (string, error) {
if !m.node.Online() {
return "", core.ErrOffline
}
hash, err := m.node.AcceptInvite(id)
if err != nil {
return "", err
}
m.node.FlushCafes()
return hash.B58String(), nil
}
// AcceptExternalInvite calls core AcceptExternalInvite
func (m *Mobile) AcceptExternalInvite(id string, key string) (string, error) {
if !m.node.Online() {
return "", core.ErrOffline
}
keyb, err := base58.Decode(key)
if err != nil {
return "", err
}
hash, err := m.node.AcceptExternalInvite(id, keyb)
if err != nil {
return "", err
}
m.node.FlushCafes()
return hash.B58String(), nil
}
// IgnoreInvite calls core IgnoreInvite
func (m *Mobile) IgnoreInvite(id string) error {
if !m.node.Started() {
return core.ErrStopped
}
err := m.node.IgnoreInvite(id)
if err != nil {
return err
}
m.node.FlushCafes()
return nil
}