-
Notifications
You must be signed in to change notification settings - Fork 12
/
manager_user.go
186 lines (179 loc) · 4.8 KB
/
manager_user.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
package mtproto
type UserStatus struct {
Status string
Online bool
Timestamp int32
}
type UserProfilePhoto struct {
ID int64
PhotoSmall FileLocation
PhotoLarge FileLocation
}
type User struct {
Flags UserFlags
ID int32
Username string
FirstName string
LastName string
Phone string
Photo *UserProfilePhoto
Status *UserStatus
Inactive bool
Mutual bool
Verified bool
Restricted bool
AccessHash int64
BotInfoVersion int32
BotInlinePlaceHolser string
RestrictionReason string
}
type UserFlags struct {
Self bool // flags_10?true
Contact bool // flags_11?true
MutualContact bool // flags_12?true
Deleted bool // flags_13?true
Bot bool // flags_14?true
BotChatHistory bool // flags_15?true
BotNochats bool // flags_16?true
Verified bool // flags_17?true
Restricted bool // flags_18?true
Min bool // flags_20?true
BotInlineGeo bool // flags_21?true
}
func (f *UserFlags) loadFlags(flags int32) {
if flags&1<<10 != 0 {
f.Self = true
}
if flags&1<<11 != 0 {
f.Contact = true
}
if flags&1<<12 != 0 {
f.MutualContact = true
}
if flags&1<<13 != 0 {
f.Deleted = true
}
if flags&1<<14 != 0 {
f.Bot = true
}
if flags&1<<15 != 0 {
f.BotChatHistory = true
}
if flags&1<<16 != 0 {
f.BotNochats = true
}
if flags&1<<17 != 0 {
f.Verified = true
}
if flags&1<<18 != 0 {
f.Restricted = true
}
if flags&1<<20 != 0 {
f.Min = true
}
if flags&1<<21 != 0 {
f.BotInlineGeo = true
}
}
func (user *User) GetInputPeer() TL {
if user.Flags.Self {
return TL_inputPeerSelf{}
} else {
return TL_inputPeerUser{
User_id: user.ID,
Access_hash: user.AccessHash,
}
}
}
func (user *User) GetPeer() TL {
return TL_peerUser{
User_id: user.ID,
}
}
func NewUserStatus(userStatus TL) (s *UserStatus) {
s = new(UserStatus)
switch status := userStatus.(type) {
case TL_userStatusEmpty:
return nil
case TL_userStatusOnline:
s.Status = USER_STATUS_ONLINE
s.Online = true
s.Timestamp = status.Expires
case TL_userStatusOffline:
s.Status = USER_STATUS_OFFLINE
s.Online = false
s.Timestamp = status.Was_online
case TL_userStatusRecently:
s.Status = USER_STATUS_RECENTLY
s.Online = false
case TL_userStatusLastWeek:
s.Status = USER_STATUS_LAST_WEEK
case TL_userStatusLastMonth:
s.Status = USER_STATUS_LAST_MONTH
}
return
}
func NewUserProfilePhoto(userProfilePhoto TL) (u *UserProfilePhoto) {
u = new(UserProfilePhoto)
switch pp := userProfilePhoto.(type) {
case TL_userProfilePhotoEmpty:
return nil
case TL_userProfilePhoto:
u.ID = pp.Photo_id
switch big := pp.Photo_big.(type) {
case TL_fileLocationUnavailable:
case TL_fileLocation:
u.PhotoLarge.DC = big.Dc_id
u.PhotoLarge.LocalID = big.Local_id
u.PhotoLarge.Secret = big.Secret
u.PhotoLarge.VolumeID = big.Volume_id
}
switch small := pp.Photo_small.(type) {
case TL_fileLocationUnavailable:
case TL_fileLocation:
u.PhotoSmall.DC = small.Dc_id
u.PhotoSmall.LocalID = small.Local_id
u.PhotoLarge.Secret = small.Secret
u.PhotoSmall.VolumeID = small.Volume_id
}
}
return
}
func NewUser(in TL) (user *User) {
user = new(User)
switch u := in.(type) {
case TL_userEmpty:
user.ID = u.Id
case TL_user:
user.ID = u.Id
user.Username = u.Username
user.FirstName = u.First_name
user.LastName = u.Last_name
user.AccessHash = u.Access_hash
user.BotInfoVersion = u.Bot_info_version
user.BotInlinePlaceHolser = u.Bot_inline_placeholder
user.RestrictionReason = u.Restriction_reason
user.Phone = u.Phone
if u.Flags&1<<5 != 0 {
user.Photo = NewUserProfilePhoto(u.Photo)
}
if u.Flags&1<<6 != 0 {
user.Status = NewUserStatus(u.Status)
}
default:
//fmt.Println(reflect.TypeOf(u).String())
return nil
}
return
}
func NewUserInputPeer(userID int32, accessHash int64) TL_inputPeerUser {
return TL_inputPeerUser{
User_id: userID,
Access_hash: accessHash,
}
}
func NewUserPeer(userID int32) TL_peerUser {
return TL_peerUser{
User_id: userID,
}
}