-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
contacts.go
252 lines (231 loc) · 7.78 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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
// Auto-generated to Go types and interfaces using avdl-compiler v1.4.10 (https://github.com/keybase/node-avdl-compiler)
// Input file: avdl/keybase1/contacts.avdl
package keybase1
import (
"github.com/keybase/go-framed-msgpack-rpc/rpc"
context "golang.org/x/net/context"
"time"
)
type ContactComponent struct {
Label string `codec:"label" json:"label"`
PhoneNumber *RawPhoneNumber `codec:"phoneNumber,omitempty" json:"phoneNumber,omitempty"`
Email *EmailAddress `codec:"email,omitempty" json:"email,omitempty"`
}
func (o ContactComponent) DeepCopy() ContactComponent {
return ContactComponent{
Label: o.Label,
PhoneNumber: (func(x *RawPhoneNumber) *RawPhoneNumber {
if x == nil {
return nil
}
tmp := (*x).DeepCopy()
return &tmp
})(o.PhoneNumber),
Email: (func(x *EmailAddress) *EmailAddress {
if x == nil {
return nil
}
tmp := (*x).DeepCopy()
return &tmp
})(o.Email),
}
}
type Contact struct {
Name string `codec:"name" json:"name"`
Components []ContactComponent `codec:"components" json:"components"`
}
func (o Contact) DeepCopy() Contact {
return Contact{
Name: o.Name,
Components: (func(x []ContactComponent) []ContactComponent {
if x == nil {
return nil
}
ret := make([]ContactComponent, len(x))
for i, v := range x {
vCopy := v.DeepCopy()
ret[i] = vCopy
}
return ret
})(o.Components),
}
}
type ProcessedContact struct {
ContactIndex int `codec:"contactIndex" json:"contactIndex"`
ContactName string `codec:"contactName" json:"contactName"`
Component ContactComponent `codec:"component" json:"component"`
Resolved bool `codec:"resolved" json:"resolved"`
Uid UID `codec:"uid" json:"uid"`
Username string `codec:"username" json:"username"`
FullName string `codec:"fullName" json:"fullName"`
Following bool `codec:"following" json:"following"`
ServiceMap map[string]string `codec:"serviceMap" json:"serviceMap"`
Assertion string `codec:"assertion" json:"assertion"`
DisplayName string `codec:"displayName" json:"displayName"`
DisplayLabel string `codec:"displayLabel" json:"displayLabel"`
}
func (o ProcessedContact) DeepCopy() ProcessedContact {
return ProcessedContact{
ContactIndex: o.ContactIndex,
ContactName: o.ContactName,
Component: o.Component.DeepCopy(),
Resolved: o.Resolved,
Uid: o.Uid.DeepCopy(),
Username: o.Username,
FullName: o.FullName,
Following: o.Following,
ServiceMap: (func(x map[string]string) map[string]string {
if x == nil {
return nil
}
ret := make(map[string]string, len(x))
for k, v := range x {
kCopy := k
vCopy := v
ret[kCopy] = vCopy
}
return ret
})(o.ServiceMap),
Assertion: o.Assertion,
DisplayName: o.DisplayName,
DisplayLabel: o.DisplayLabel,
}
}
type ContactListResolutionResult struct {
NewlyResolved []ProcessedContact `codec:"newlyResolved" json:"newlyResolved"`
Resolved []ProcessedContact `codec:"resolved" json:"resolved"`
}
func (o ContactListResolutionResult) DeepCopy() ContactListResolutionResult {
return ContactListResolutionResult{
NewlyResolved: (func(x []ProcessedContact) []ProcessedContact {
if x == nil {
return nil
}
ret := make([]ProcessedContact, len(x))
for i, v := range x {
vCopy := v.DeepCopy()
ret[i] = vCopy
}
return ret
})(o.NewlyResolved),
Resolved: (func(x []ProcessedContact) []ProcessedContact {
if x == nil {
return nil
}
ret := make([]ProcessedContact, len(x))
for i, v := range x {
vCopy := v.DeepCopy()
ret[i] = vCopy
}
return ret
})(o.Resolved),
}
}
type LookupContactListArg struct {
SessionID int `codec:"sessionID" json:"sessionID"`
Contacts []Contact `codec:"contacts" json:"contacts"`
}
type SaveContactListArg struct {
SessionID int `codec:"sessionID" json:"sessionID"`
Contacts []Contact `codec:"contacts" json:"contacts"`
}
type LookupSavedContactsListArg struct {
SessionID int `codec:"sessionID" json:"sessionID"`
}
type GetContactsForUserRecommendationsArg struct {
SessionID int `codec:"sessionID" json:"sessionID"`
}
type ContactsInterface interface {
LookupContactList(context.Context, LookupContactListArg) ([]ProcessedContact, error)
SaveContactList(context.Context, SaveContactListArg) (ContactListResolutionResult, error)
LookupSavedContactsList(context.Context, int) ([]ProcessedContact, error)
GetContactsForUserRecommendations(context.Context, int) ([]ProcessedContact, error)
}
func ContactsProtocol(i ContactsInterface) rpc.Protocol {
return rpc.Protocol{
Name: "keybase.1.contacts",
Methods: map[string]rpc.ServeHandlerDescription{
"lookupContactList": {
MakeArg: func() interface{} {
var ret [1]LookupContactListArg
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[1]LookupContactListArg)
if !ok {
err = rpc.NewTypeError((*[1]LookupContactListArg)(nil), args)
return
}
ret, err = i.LookupContactList(ctx, typedArgs[0])
return
},
},
"saveContactList": {
MakeArg: func() interface{} {
var ret [1]SaveContactListArg
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[1]SaveContactListArg)
if !ok {
err = rpc.NewTypeError((*[1]SaveContactListArg)(nil), args)
return
}
ret, err = i.SaveContactList(ctx, typedArgs[0])
return
},
},
"lookupSavedContactsList": {
MakeArg: func() interface{} {
var ret [1]LookupSavedContactsListArg
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[1]LookupSavedContactsListArg)
if !ok {
err = rpc.NewTypeError((*[1]LookupSavedContactsListArg)(nil), args)
return
}
ret, err = i.LookupSavedContactsList(ctx, typedArgs[0].SessionID)
return
},
},
"getContactsForUserRecommendations": {
MakeArg: func() interface{} {
var ret [1]GetContactsForUserRecommendationsArg
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[1]GetContactsForUserRecommendationsArg)
if !ok {
err = rpc.NewTypeError((*[1]GetContactsForUserRecommendationsArg)(nil), args)
return
}
ret, err = i.GetContactsForUserRecommendations(ctx, typedArgs[0].SessionID)
return
},
},
},
}
}
type ContactsClient struct {
Cli rpc.GenericClient
}
func (c ContactsClient) LookupContactList(ctx context.Context, __arg LookupContactListArg) (res []ProcessedContact, err error) {
err = c.Cli.Call(ctx, "keybase.1.contacts.lookupContactList", []interface{}{__arg}, &res, 0*time.Millisecond)
return
}
func (c ContactsClient) SaveContactList(ctx context.Context, __arg SaveContactListArg) (res ContactListResolutionResult, err error) {
err = c.Cli.Call(ctx, "keybase.1.contacts.saveContactList", []interface{}{__arg}, &res, 0*time.Millisecond)
return
}
func (c ContactsClient) LookupSavedContactsList(ctx context.Context, sessionID int) (res []ProcessedContact, err error) {
__arg := LookupSavedContactsListArg{SessionID: sessionID}
err = c.Cli.Call(ctx, "keybase.1.contacts.lookupSavedContactsList", []interface{}{__arg}, &res, 0*time.Millisecond)
return
}
func (c ContactsClient) GetContactsForUserRecommendations(ctx context.Context, sessionID int) (res []ProcessedContact, err error) {
__arg := GetContactsForUserRecommendationsArg{SessionID: sessionID}
err = c.Cli.Call(ctx, "keybase.1.contacts.getContactsForUserRecommendations", []interface{}{__arg}, &res, 0*time.Millisecond)
return
}