-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathstructures.go
161 lines (148 loc) · 3.29 KB
/
structures.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
package mtproto
import (
"log"
"reflect"
)
// Peer
type Peer struct {
Type string
ID int32
}
func NewPeer(in TL) (p *Peer) {
p = new(Peer)
switch x := in.(type) {
case TL_peerChannel:
p.Type = PEER_TYPE_CHANNEL
p.ID = x.Channel_id
case TL_peerChat:
p.Type = PEER_TYPE_CHAT
p.ID = x.Chat_id
case TL_peerUser:
p.Type = PEER_TYPE_USER
p.ID = x.User_id
}
return p
}
type GeoPoint struct {
Longtitude float32
Latitude float32
}
// Photo
type Photo struct {
flags int32
ID int64
AccessHash int64
UserID int32
Date int32
Caption string
Geo *GeoPoint
Sizes []*PhotoSize
}
func NewPhoto(in TL) (photo *Photo) {
photo = new(Photo)
switch x := in.(type) {
case TL_photo:
photo.flags = x.Flags
photo.ID = x.Id
photo.AccessHash = x.Access_hash
photo.Date = x.Date
photo.Sizes = make([]*PhotoSize, 0, len(x.Sizes))
for _, v := range x.Sizes {
photo.Sizes = append(photo.Sizes, NewPhotoSize(v))
}
default:
return nil
}
return
}
// PhotoSize
type PhotoSize struct {
Type string
Location *FileLocation
Width int32
Height int32
Size int32
}
func NewPhotoSize(in TL) (ps *PhotoSize) {
ps = new(PhotoSize)
switch x := in.(type) {
case TL_photoSizeEmpty:
return nil
case TL_photoSize:
ps.Type = x._Type
ps.Size = x.Size
ps.Width = x.W
ps.Height = x.H
ps.Location = NewFileLocation(x.Location)
}
return
}
func (p *PhotoSize) GetInputFileLocation() TL_inputFileLocation {
return TL_inputFileLocation{
p.Location.VolumeID,
p.Location.LocalID,
p.Location.Secret,
}
}
// Document
type Document struct {
ID int64
AccessHash int64
Date int32
Mimetype string
Size int32
Thumb *PhotoSize
DcID int32
Version int32
attributes []TL // DocumentAttribute
}
func NewDocument(in TL) (d *Document) {
d = new(Document)
switch x := in.(type) {
case TL_document:
d.ID = x.Id
d.AccessHash = x.Access_hash
d.Mimetype = x.Mime_type
d.Date = x.Date
d.DcID = x.Dc_id
d.Size = x.Size
d.Thumb = NewPhotoSize(x.Thumb)
//TODO:: Document Attribute
default:
log.Println("NewDocument::", reflect.TypeOf(x).String())
}
return d
}
func (d *Document) GetInputFileLocation() TL_inputDocumentFileLocation {
return TL_inputDocumentFileLocation{
Id: d.ID,
Access_hash: d.AccessHash,
}
}
// FileLocation
type FileLocation struct {
DC int32
VolumeID int64
LocalID int32
Secret int64
}
func NewFileLocation(in TL) (fl *FileLocation) {
fl = new(FileLocation)
switch x := in.(type) {
case TL_fileLocationUnavailable:
return nil
case TL_fileLocation:
fl.DC = x.Dc_id
fl.LocalID = x.Local_id
fl.Secret = x.Secret
fl.VolumeID = x.Volume_id
}
return
}
func (f *FileLocation) GetInputFileLocation() TL_inputFileLocation {
return TL_inputFileLocation{
f.VolumeID,
f.LocalID,
f.Secret,
}
}