move gotd fork into repo. (#111)

- 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
This commit is contained in:
Adam Van Ymeren
2025-06-27 20:03:37 -07:00
committed by GitHub
parent 0952df0244
commit 7a04f298d2
19264 changed files with 1539697 additions and 84 deletions
+122
View File
@@ -0,0 +1,122 @@
package peers
import (
"go.mau.fi/mautrix-telegram/pkg/gotd/constant"
"go.mau.fi/mautrix-telegram/pkg/gotd/tg"
)
func userPeerID(id int64) (r constant.TDLibPeerID) {
r.User(id)
return r
}
func chatPeerID(id int64) (r constant.TDLibPeerID) {
r.Chat(id)
return r
}
func channelPeerID(id int64) (r constant.TDLibPeerID) {
r.Channel(id)
return r
}
func peerIDFromPeerClass(p tg.PeerClass) constant.TDLibPeerID {
switch p := p.(type) {
case *tg.PeerUser:
return userPeerID(p.UserID)
case *tg.PeerChat:
return chatPeerID(p.ChatID)
case *tg.PeerChannel:
return channelPeerID(p.ChannelID)
}
return 0
}
func (m *Manager) updated(ids ...constant.TDLibPeerID) {
m.needUpdateMux.Lock()
defer m.needUpdateMux.Unlock()
m.needUpdate.delete(ids...)
}
func (m *Manager) updatedFull(id constant.TDLibPeerID) {
m.needUpdateMux.Lock()
defer m.needUpdateMux.Unlock()
m.needUpdateFull.delete(id)
}
func (m *Manager) needsUpdate(id constant.TDLibPeerID) bool {
m.needUpdateMux.Lock()
defer m.needUpdateMux.Unlock()
return m.needUpdate.has(id)
}
func (m *Manager) needsUpdateFull(id constant.TDLibPeerID) bool {
m.needUpdateMux.Lock()
defer m.needUpdateMux.Unlock()
return m.needUpdateFull.has(id)
}
func (m *Manager) applyUpdates(updates []tg.UpdateClass) {
// TODO(tdakkota): support partial updates in storage
m.needUpdateMux.Lock()
defer m.needUpdateMux.Unlock()
appendBoth := func(p ...constant.TDLibPeerID) {
m.needUpdate.add(p...)
m.needUpdateFull.add(p...)
}
for _, update := range updates {
switch update := update.(type) {
case *tg.UpdateChatParticipants:
p, ok := update.Participants.(*tg.ChatParticipants)
if ok {
appendBoth(chatPeerID(p.ChatID))
}
case *tg.UpdateUserStatus:
m.needUpdate.add(userPeerID(update.UserID))
case *tg.UpdateUserName:
m.needUpdate.add(userPeerID(update.UserID))
case *tg.UpdateUser:
m.needUpdate.add(userPeerID(update.UserID))
case *tg.UpdateUserPhone:
m.needUpdate.add(userPeerID(update.UserID))
case *tg.UpdateChatParticipantAdd:
appendBoth(userPeerID(update.UserID), chatPeerID(update.ChatID))
case *tg.UpdateChatParticipantDelete:
appendBoth(userPeerID(update.UserID), chatPeerID(update.ChatID))
case *tg.UpdateNotifySettings:
if p, ok := update.Peer.(*tg.NotifyPeer); ok {
m.needUpdate.add(peerIDFromPeerClass(p.Peer))
}
case *tg.UpdateChannel:
m.needUpdate.add(channelPeerID(update.ChannelID))
case *tg.UpdateChatParticipantAdmin:
m.needUpdate.add(userPeerID(update.UserID), chatPeerID(update.ChatID))
case *tg.UpdateChatDefaultBannedRights:
appendBoth(peerIDFromPeerClass(update.Peer))
case *tg.UpdatePeerSettings:
m.needUpdate.add(peerIDFromPeerClass(update.Peer))
case *tg.UpdatePeerBlocked:
case *tg.UpdateChat:
m.needUpdate.add(chatPeerID(update.ChatID))
case *tg.UpdatePeerHistoryTTL:
m.needUpdate.add(peerIDFromPeerClass(update.Peer))
case *tg.UpdateChatParticipant:
m.needUpdate.add(userPeerID(update.UserID), chatPeerID(update.ChatID))
case *tg.UpdateChannelParticipant:
m.needUpdate.add(userPeerID(update.UserID), channelPeerID(update.ChannelID))
case *tg.UpdateBotStopped:
case *tg.UpdateBotCommands:
m.needUpdate.add(userPeerID(update.BotID))
case *tg.UpdatePendingJoinRequests:
m.needUpdate.add(peerIDFromPeerClass(update.Peer))
case *tg.UpdateBotChatInviteRequester:
}
}
}