This repository has been archived by the owner on Jul 3, 2022. It is now read-only.
forked from Arman92/go-tdlib
/
userStatus.go
227 lines (184 loc) · 6.41 KB
/
userStatus.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
package tdlib
import (
"encoding/json"
"fmt"
)
// UserStatus Describes the last time the user was online
type UserStatus interface {
GetUserStatusEnum() UserStatusEnum
}
// UserStatusEnum Alias for abstract UserStatus 'Sub-Classes', used as constant-enum here
type UserStatusEnum string
// UserStatus enums
const (
UserStatusEmptyType UserStatusEnum = "userStatusEmpty"
UserStatusOnlineType UserStatusEnum = "userStatusOnline"
UserStatusOfflineType UserStatusEnum = "userStatusOffline"
UserStatusRecentlyType UserStatusEnum = "userStatusRecently"
UserStatusLastWeekType UserStatusEnum = "userStatusLastWeek"
UserStatusLastMonthType UserStatusEnum = "userStatusLastMonth"
)
func unmarshalUserStatus(rawMsg *json.RawMessage) (UserStatus, error) {
if rawMsg == nil {
return nil, nil
}
var objMap map[string]interface{}
err := json.Unmarshal(*rawMsg, &objMap)
if err != nil {
return nil, err
}
switch UserStatusEnum(objMap["@type"].(string)) {
case UserStatusEmptyType:
var userStatusEmpty UserStatusEmpty
err := json.Unmarshal(*rawMsg, &userStatusEmpty)
return &userStatusEmpty, err
case UserStatusOnlineType:
var userStatusOnline UserStatusOnline
err := json.Unmarshal(*rawMsg, &userStatusOnline)
return &userStatusOnline, err
case UserStatusOfflineType:
var userStatusOffline UserStatusOffline
err := json.Unmarshal(*rawMsg, &userStatusOffline)
return &userStatusOffline, err
case UserStatusRecentlyType:
var userStatusRecently UserStatusRecently
err := json.Unmarshal(*rawMsg, &userStatusRecently)
return &userStatusRecently, err
case UserStatusLastWeekType:
var userStatusLastWeek UserStatusLastWeek
err := json.Unmarshal(*rawMsg, &userStatusLastWeek)
return &userStatusLastWeek, err
case UserStatusLastMonthType:
var userStatusLastMonth UserStatusLastMonth
err := json.Unmarshal(*rawMsg, &userStatusLastMonth)
return &userStatusLastMonth, err
default:
return nil, fmt.Errorf("Error UnMarshaling, unknown type:" + objMap["@type"].(string))
}
}
// UserStatusEmpty The user status was never changed
type UserStatusEmpty struct {
tdCommon
}
// MessageType return the string telegram-type of UserStatusEmpty
func (userStatusEmpty *UserStatusEmpty) MessageType() string {
return "userStatusEmpty"
}
// NewUserStatusEmpty creates a new UserStatusEmpty
//
func NewUserStatusEmpty() *UserStatusEmpty {
userStatusEmptyTemp := UserStatusEmpty{
tdCommon: tdCommon{Type: "userStatusEmpty"},
}
return &userStatusEmptyTemp
}
// GetUserStatusEnum return the enum type of this object
func (userStatusEmpty *UserStatusEmpty) GetUserStatusEnum() UserStatusEnum {
return UserStatusEmptyType
}
// UserStatusOnline The user is online
type UserStatusOnline struct {
tdCommon
Expires int32 `json:"expires"` // Point in time (Unix timestamp) when the user's online status will expire
}
// MessageType return the string telegram-type of UserStatusOnline
func (userStatusOnline *UserStatusOnline) MessageType() string {
return "userStatusOnline"
}
// NewUserStatusOnline creates a new UserStatusOnline
//
// @param expires Point in time (Unix timestamp) when the user's online status will expire
func NewUserStatusOnline(expires int32) *UserStatusOnline {
userStatusOnlineTemp := UserStatusOnline{
tdCommon: tdCommon{Type: "userStatusOnline"},
Expires: expires,
}
return &userStatusOnlineTemp
}
// GetUserStatusEnum return the enum type of this object
func (userStatusOnline *UserStatusOnline) GetUserStatusEnum() UserStatusEnum {
return UserStatusOnlineType
}
// UserStatusOffline The user is offline
type UserStatusOffline struct {
tdCommon
WasOnline int32 `json:"was_online"` // Point in time (Unix timestamp) when the user was last online
}
// MessageType return the string telegram-type of UserStatusOffline
func (userStatusOffline *UserStatusOffline) MessageType() string {
return "userStatusOffline"
}
// NewUserStatusOffline creates a new UserStatusOffline
//
// @param wasOnline Point in time (Unix timestamp) when the user was last online
func NewUserStatusOffline(wasOnline int32) *UserStatusOffline {
userStatusOfflineTemp := UserStatusOffline{
tdCommon: tdCommon{Type: "userStatusOffline"},
WasOnline: wasOnline,
}
return &userStatusOfflineTemp
}
// GetUserStatusEnum return the enum type of this object
func (userStatusOffline *UserStatusOffline) GetUserStatusEnum() UserStatusEnum {
return UserStatusOfflineType
}
// UserStatusRecently The user was online recently
type UserStatusRecently struct {
tdCommon
}
// MessageType return the string telegram-type of UserStatusRecently
func (userStatusRecently *UserStatusRecently) MessageType() string {
return "userStatusRecently"
}
// NewUserStatusRecently creates a new UserStatusRecently
//
func NewUserStatusRecently() *UserStatusRecently {
userStatusRecentlyTemp := UserStatusRecently{
tdCommon: tdCommon{Type: "userStatusRecently"},
}
return &userStatusRecentlyTemp
}
// GetUserStatusEnum return the enum type of this object
func (userStatusRecently *UserStatusRecently) GetUserStatusEnum() UserStatusEnum {
return UserStatusRecentlyType
}
// UserStatusLastWeek The user is offline, but was online last week
type UserStatusLastWeek struct {
tdCommon
}
// MessageType return the string telegram-type of UserStatusLastWeek
func (userStatusLastWeek *UserStatusLastWeek) MessageType() string {
return "userStatusLastWeek"
}
// NewUserStatusLastWeek creates a new UserStatusLastWeek
//
func NewUserStatusLastWeek() *UserStatusLastWeek {
userStatusLastWeekTemp := UserStatusLastWeek{
tdCommon: tdCommon{Type: "userStatusLastWeek"},
}
return &userStatusLastWeekTemp
}
// GetUserStatusEnum return the enum type of this object
func (userStatusLastWeek *UserStatusLastWeek) GetUserStatusEnum() UserStatusEnum {
return UserStatusLastWeekType
}
// UserStatusLastMonth The user is offline, but was online last month
type UserStatusLastMonth struct {
tdCommon
}
// MessageType return the string telegram-type of UserStatusLastMonth
func (userStatusLastMonth *UserStatusLastMonth) MessageType() string {
return "userStatusLastMonth"
}
// NewUserStatusLastMonth creates a new UserStatusLastMonth
//
func NewUserStatusLastMonth() *UserStatusLastMonth {
userStatusLastMonthTemp := UserStatusLastMonth{
tdCommon: tdCommon{Type: "userStatusLastMonth"},
}
return &userStatusLastMonthTemp
}
// GetUserStatusEnum return the enum type of this object
func (userStatusLastMonth *UserStatusLastMonth) GetUserStatusEnum() UserStatusEnum {
return UserStatusLastMonthType
}