-
Notifications
You must be signed in to change notification settings - Fork 12
/
manager_chat.go
144 lines (136 loc) · 3.52 KB
/
manager_chat.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
package mtproto
import (
"fmt"
"reflect"
)
const (
CHAT_TYPE_EMPTY = "EMPTY"
CHAT_TYPE_CHAT = "CHAT"
CHAT_TYPE_CHAT_FORBIDDEN = "CHAT_FORBIDDEN"
)
type ChatProfilePhoto struct {
PhotoSmall FileLocation
PhotoBig FileLocation
}
type Chat struct {
flags int32
Type string
ID int32
Username string
Title string
Photo *ChatProfilePhoto
Participants int32
Members []ChatMember
Date int32
Left bool
Version int32
AccessHash int64
Address string
Venue string
CheckedIn bool
}
type ChatMember struct {
UserID int32
InviterID int32
Date int32
}
type ChannelParticipantFilter struct{}
func (ch *Chat) GetPeer() TL {
switch ch.Type {
case CHAT_TYPE_CHAT, CHAT_TYPE_CHAT_FORBIDDEN:
return TL_peerChat{
Chat_id: ch.ID,
}
default:
return nil
}
}
func (ch *Chat) GetInputPeer() TL {
switch ch.Type {
case CHAT_TYPE_CHAT, CHAT_TYPE_CHAT_FORBIDDEN:
return TL_inputPeerChat{
Chat_id: ch.ID,
}
default:
return nil
}
}
// NewChatProfilePhoto
// input :
// 1. TL_chatPhotoEmpty
// 2. TL_chatPhoto
func NewChatProfilePhoto(input TL) (photo *ChatProfilePhoto) {
photo = new(ChatProfilePhoto)
switch p := input.(type) {
case TL_chatPhotoEmpty:
return nil
case TL_chatPhoto:
switch big := p.Photo_big.(type) {
case TL_fileLocationUnavailable:
case TL_fileLocation:
photo.PhotoBig.DC = big.Dc_id
photo.PhotoBig.LocalID = big.Local_id
photo.PhotoBig.Secret = big.Secret
photo.PhotoBig.VolumeID = big.Volume_id
}
switch small := p.Photo_small.(type) {
case TL_fileLocationUnavailable:
case TL_fileLocation:
photo.PhotoSmall.DC = small.Dc_id
photo.PhotoSmall.LocalID = small.Local_id
photo.PhotoSmall.Secret = small.Secret
photo.PhotoSmall.VolumeID = small.Volume_id
}
}
return photo
}
// NewChat
// input:
// 1. TL_chatEmpty
// 2. TL_chatForbidden
// 3. TL_chat
// 4. TL_chatFull:
func NewChat(input TL) (chat *Chat) {
chat = new(Chat)
chat.Members = []ChatMember{}
switch ch := input.(type) {
case TL_chatEmpty:
chat.Type = CHAT_TYPE_EMPTY
chat.ID = ch.Id
case TL_chatForbidden:
chat.Type = CHAT_TYPE_CHAT_FORBIDDEN
chat.ID = ch.Id
chat.Title = ch.Title
case TL_chat:
chat.flags = ch.Flags
chat.Type = CHAT_TYPE_CHAT
chat.ID = ch.Id
chat.Title = ch.Title
chat.Date = ch.Date
chat.Photo = NewChatProfilePhoto(ch.Photo)
chat.Version = ch.Version
chat.Participants = ch.Participants_count
case TL_chatFull:
chat.ID = ch.Id
participants := ch.Participants.(TL_chatParticipants)
chat.Version = participants.Version
for _, tl := range ch.Participants.(TL_chatParticipants).Participants {
m := tl.(TL_chatParticipant)
chat.Members = append(chat.Members, ChatMember{m.User_id, m.Inviter_id, m.Date})
}
default:
fmt.Println(reflect.TypeOf(ch).String())
return nil
}
return chat
}
func NewChatInputPeer(chatID int32) TL_inputPeerChat {
return TL_inputPeerChat{
Chat_id: chatID,
}
}
func NewChatPeer(chatID int32) TL_peerChat {
return TL_peerChat{
Chat_id: chatID,
}
}