7a04f298d2
- update to latest telegram layer - remove some references to fields in tg.Entities that don't exist in the schema - originally added here: https://github.com/beeper/td/commit/820929062a2ba0104397bc01235ab58a9cff780e - referenced here - https://github.com/mautrix/telegramgo/commit/124f0967ed195b5a380c9bd02e170ada9710dde3 - https://github.com/mautrix/telegramgo/commit/4205047aab2e0639217148b5d125bfaab668bd8e
82 lines
1.8 KiB
Go
82 lines
1.8 KiB
Go
package e2e
|
|
|
|
import "go.mau.fi/mautrix-telegram/pkg/gotd/tg"
|
|
|
|
// Entities contains update entities.
|
|
type Entities struct {
|
|
Users map[int64]*tg.User
|
|
Chats map[int64]*tg.Chat
|
|
Channels map[int64]*tg.Channel
|
|
ChannelsForbidden map[int64]*tg.ChannelForbidden
|
|
}
|
|
|
|
// NewEntities creates new Entities.
|
|
func NewEntities() *Entities {
|
|
return &Entities{
|
|
Users: map[int64]*tg.User{},
|
|
Chats: map[int64]*tg.Chat{},
|
|
Channels: map[int64]*tg.Channel{},
|
|
ChannelsForbidden: map[int64]*tg.ChannelForbidden{},
|
|
}
|
|
}
|
|
|
|
// Merge merges entities.
|
|
func (e *Entities) Merge(from *Entities) {
|
|
if from == nil {
|
|
return
|
|
}
|
|
|
|
for userID, user := range from.Users {
|
|
e.Users[userID] = user
|
|
}
|
|
|
|
for chanID, chat := range from.Chats {
|
|
e.Chats[chanID] = chat
|
|
}
|
|
|
|
for channelID, channel := range from.Channels {
|
|
e.Channels[channelID] = channel
|
|
}
|
|
|
|
for channelID, channel := range from.ChannelsForbidden {
|
|
e.ChannelsForbidden[channelID] = channel
|
|
}
|
|
}
|
|
|
|
// FromUpdates method.
|
|
func (e *Entities) FromUpdates(u interface {
|
|
tg.UpdatesClass
|
|
MapUsers() tg.UserClassArray
|
|
MapChats() tg.ChatClassArray
|
|
}) *Entities {
|
|
u.MapChats().FillChatMap(e.Chats)
|
|
u.MapChats().FillChannelMap(e.Channels)
|
|
u.MapChats().FillChannelForbiddenMap(e.ChannelsForbidden)
|
|
u.MapUsers().FillUserMap(e.Users)
|
|
return e
|
|
}
|
|
|
|
// AsUsers returns users as tg.UserClass slice.
|
|
func (e *Entities) AsUsers() []tg.UserClass {
|
|
var users []tg.UserClass
|
|
for _, u := range e.Users {
|
|
users = append(users, u)
|
|
}
|
|
return users
|
|
}
|
|
|
|
// AsChats returns chats as tg.ChatClass slice.
|
|
func (e *Entities) AsChats() []tg.ChatClass {
|
|
var chats []tg.ChatClass
|
|
for _, c := range e.Chats {
|
|
chats = append(chats, c)
|
|
}
|
|
for _, c := range e.Channels {
|
|
chats = append(chats, c)
|
|
}
|
|
for _, c := range e.ChannelsForbidden {
|
|
chats = append(chats, c)
|
|
}
|
|
return chats
|
|
}
|