-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmanager_contact.go
102 lines (93 loc) · 2.54 KB
/
manager_contact.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
package mtproto
import (
"log"
"fmt"
)
// Contact
type Contact struct {
ClientID int64
Firstname string
Lastname string
Phone string
UserID int32
Mutual bool
}
func (c *Contact) GetInputContact() TL {
return TL_inputPhoneContact{
Client_id: c.ClientID,
First_name: c.Firstname,
Last_name: c.Lastname,
Phone: c.Phone,
}
}
func NewContact(in TL) (contact *Contact) {
contact = new(Contact)
switch c := in.(type) {
case TL_contactLinkContact:
case TL_contact:
contact.UserID = c.User_id
contact.Mutual = toBool(c.Mutual)
case TL_importedContact:
contact.UserID = c.User_id
contact.ClientID = c.Client_id
case TL_inputPhoneContact:
contact.ClientID = c.Client_id
contact.Firstname = c.First_name
contact.Lastname = c.Last_name
contact.Phone = c.Phone
default:
log.Println("GetContact::Error::Invalid Type")
return nil
}
return
}
func (m *MTProto) Contacts_GetContacts(hash int32) ([]Contact, []User, error) {
resp := make(chan TL, 1)
m.queueSend <- packetToSend{TL_contacts_getContacts{
hash},
resp,
}
x := <-resp
list, ok := x.(TL_contacts_contacts)
if !ok {
log.Println(fmt.Sprintf("RPC: %#v", x))
return []Contact{}, []User{}, fmt.Errorf("RPC: %#v", x)
}
TContacts := make([]Contact, 0, len(list.Contacts))
TUsers := make([]User, 0, len(list.Users))
for _, v := range list.Contacts {
TContacts = append(
TContacts,
*NewContact(v),
)
}
for _, v := range list.Users {
switch u := v.(type) {
case TL_user, TL_userEmpty:
TUsers = append(TUsers, *NewUser(u))
case TL_userProfilePhoto:
TUsers[len(TUsers)-1].Photo = NewUserProfilePhoto(u)
case TL_userStatusRecently, TL_userStatusOffline, TL_userStatusOnline, TL_userStatusLastWeek, TL_userStatusLastMonth:
TUsers[len(TUsers)-1].Status = NewUserStatus(u)
}
}
return TContacts, TUsers, nil
}
func (m *MTProto) Contacts_ImportContacts(contacts []TL) {
resp := make(chan TL, 1)
m.queueSend <- packetToSend{
TL_contacts_importContacts{
contacts,
},
resp,
}
x := <-resp
switch r := x.(type) {
case TL_contacts_importedContacts:
//TODO:: must do something with response
log.Println(r)
default:
log.Println(fmt.Sprintf("RPC: %#v", x))
return
}
}