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
67 lines
1.2 KiB
Go
67 lines
1.2 KiB
Go
package dialogs
|
|
|
|
import (
|
|
"github.com/go-faster/errors"
|
|
|
|
"go.mau.fi/mautrix-telegram/pkg/gotd/tg"
|
|
)
|
|
|
|
// PeerKind represents peer kind.
|
|
type PeerKind int
|
|
|
|
const (
|
|
// User is a private chat with user.
|
|
User PeerKind = iota
|
|
// Chat is a legacy chat.
|
|
Chat
|
|
// Channel is a supergroup/channel.
|
|
Channel
|
|
)
|
|
|
|
// DialogKey is a generic peer key.
|
|
type DialogKey struct {
|
|
Kind PeerKind
|
|
ID int64
|
|
AccessHash int64
|
|
}
|
|
|
|
// FromInputPeer fills key using given peer.
|
|
func (d *DialogKey) FromInputPeer(peer tg.InputPeerClass) error {
|
|
switch v := peer.(type) {
|
|
case *tg.InputPeerUser:
|
|
d.Kind = User
|
|
d.ID = v.UserID
|
|
d.AccessHash = v.AccessHash
|
|
case *tg.InputPeerChat:
|
|
d.Kind = Chat
|
|
d.ID = v.ChatID
|
|
case *tg.InputPeerChannel:
|
|
d.Kind = Channel
|
|
d.ID = v.ChannelID
|
|
d.AccessHash = v.AccessHash
|
|
default:
|
|
return errors.Errorf("unexpected type %T", peer)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// FromPeer fills key using given peer.
|
|
func (d *DialogKey) FromPeer(peer tg.PeerClass) error {
|
|
switch v := peer.(type) {
|
|
case *tg.PeerUser:
|
|
d.Kind = User
|
|
d.ID = v.UserID
|
|
case *tg.PeerChat:
|
|
d.Kind = Chat
|
|
d.ID = v.ChatID
|
|
case *tg.PeerChannel:
|
|
d.Kind = Channel
|
|
d.ID = v.ChannelID
|
|
default:
|
|
return errors.Errorf("unexpected type %T", peer)
|
|
}
|
|
|
|
return nil
|
|
}
|