forked from celestix/gotgproto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chat.go
158 lines (129 loc) · 3.41 KB
/
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package types
import "github.com/gotd/td/tg"
// EffectiveChat interface covers the all three types of chats:
// - tg.User
// - tg.Chat
// - tg.Channel
//
// This interface is implemented by the following structs:
// - User: If the chat is a tg.User then this struct will be returned.
// - Chat: if the chat is a tg.Chat then this struct will be returned.
// - Channel: if the chat is a tg.Channel then this struct will be returned.
// - EmptyUC: if the PeerID doesn't match any of the above cases then EmptyUC struct is returned.
type EffectiveChat interface {
// Use this method to get chat id.
GetID() int64
// Use this method to get access hash of the effective chat.
GetAccessHash() int64
// Use this method to check if the effective chat is a channel.
IsAChannel() bool
// Use this method to check if the effective chat is a chat.
IsAChat() bool
// Use this method to check if the effective chat is a user.
IsAUser() bool
}
// EmptyUC implements EffectiveChat interface for empty chats.
type EmptyUC struct{}
// Use this method to get chat id.
// Always 0 for EmptyUC
func (*EmptyUC) GetID() int64 {
return 0
}
// Use this method to get access hash of effective chat.
// Always 0 for EmptyUC
func (*EmptyUC) GetAccessHash() int64 {
return 0
}
// IsAChannel returns true for a channel.
// Always false for EmptyUC
func (*EmptyUC) IsAChannel() bool {
return false
}
// IsAChat returns true for a chat.
// Always false for EmptyUC
func (*EmptyUC) IsAChat() bool {
return false
}
// IsAUser returns true for a user.
// Always false for EmptyUC
func (*EmptyUC) IsAUser() bool {
return false
}
// User implements EffectiveChat interface for tg.User chats.
type User tg.User
// Use this method to get chat id.
func (u *User) GetID() int64 {
return u.ID
}
// Use this method to get access hash of the effective chat.
func (u *User) GetAccessHash() int64 {
return u.AccessHash
}
// IsAChannel returns true for a channel.
func (u *User) IsAChannel() bool {
return false
}
// IsAChat returns true for a chat.
func (u *User) IsAChat() bool {
return false
}
// IsAUser returns true for a user.
func (u *User) IsAUser() bool {
return true
}
func (u *User) Raw() *tg.User {
us := tg.User(*u)
return &us
}
// Channel implements EffectiveChat interface for tg.Channel chats.
type Channel tg.Channel
// Use this method to get chat id.
func (u *Channel) GetID() int64 {
return u.ID
}
// Use this method to get access hash of the effective chat.
func (u *Channel) GetAccessHash() int64 {
return u.AccessHash
}
// IsAChannel returns true for a channel.
func (u *Channel) IsAChannel() bool {
return true
}
// IsAChat returns true for a chat.
func (u *Channel) IsAChat() bool {
return false
}
// IsAUser returns true for a user.
func (u *Channel) IsAUser() bool {
return false
}
func (u *Channel) Raw() *tg.Channel {
us := tg.Channel(*u)
return &us
}
// Chat implements EffectiveChat interface for tg.Chat chats.
type Chat tg.Chat
// Use this method to get chat id.
func (u *Chat) GetID() int64 {
return u.ID
}
// Use this method to get access hash of the effective chat.
func (u *Chat) GetAccessHash() int64 {
return 0
}
// IsAChannel returns true for a channel.
func (u *Chat) IsAChannel() bool {
return true
}
// IsAChat returns true for a chat.
func (u *Chat) IsAChat() bool {
return false
}
// IsAUser returns true for a user.
func (u *Chat) IsAUser() bool {
return false
}
func (u *Chat) Raw() *tg.Chat {
us := tg.Chat(*u)
return &us
}