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
88 lines
1.6 KiB
Go
88 lines
1.6 KiB
Go
package updates
|
|
|
|
import (
|
|
"github.com/go-faster/errors"
|
|
|
|
"go.mau.fi/mautrix-telegram/pkg/gotd/tg"
|
|
)
|
|
|
|
func validatePts(pts, ptsCount int) error {
|
|
if pts < 0 {
|
|
return errors.Errorf("invalid pts value: %d", pts)
|
|
}
|
|
|
|
if ptsCount < 0 {
|
|
return errors.Errorf("invalid ptsCount value: %d", ptsCount)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func validateQts(qts int) error {
|
|
if qts < 0 {
|
|
return errors.Errorf("invalid qts value: %d", qts)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func validateSeq(seq, seqStart int) error {
|
|
if seq < 0 {
|
|
return errors.Errorf("invalid seq value: %d", seq)
|
|
}
|
|
|
|
if seqStart < 0 {
|
|
return errors.Errorf("invalid seqStart value: %d", seq)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func getDialogPts(dialog tg.DialogClass) (int, error) {
|
|
d, ok := dialog.(*tg.Dialog)
|
|
if !ok {
|
|
return 0, errors.Errorf("unexpected dialog type: %T", dialog)
|
|
}
|
|
|
|
pts, ok := d.GetPts()
|
|
if !ok {
|
|
return 0, errors.New("dialog has no pts field")
|
|
}
|
|
|
|
return pts, nil
|
|
}
|
|
|
|
func msgsToUpdates(msgs []tg.MessageClass, channel bool) []tg.UpdateClass {
|
|
updates := make([]tg.UpdateClass, 0, len(msgs))
|
|
for _, msg := range msgs {
|
|
if channel {
|
|
updates = append(updates, &tg.UpdateNewChannelMessage{
|
|
Message: msg,
|
|
Pts: -1,
|
|
PtsCount: -1,
|
|
})
|
|
continue
|
|
}
|
|
|
|
updates = append(updates, &tg.UpdateNewMessage{
|
|
Message: msg,
|
|
Pts: -1,
|
|
PtsCount: -1,
|
|
})
|
|
}
|
|
|
|
return updates
|
|
}
|
|
|
|
func encryptedMsgsToUpdates(msgs []tg.EncryptedMessageClass) []tg.UpdateClass {
|
|
updates := make([]tg.UpdateClass, 0, len(msgs))
|
|
for _, msg := range msgs {
|
|
updates = append(updates, &tg.UpdateNewEncryptedMessage{
|
|
Message: msg,
|
|
Qts: -1,
|
|
})
|
|
}
|
|
|
|
return updates
|
|
}
|