Documentation ¶
Overview ¶
Package updates provides a Telegram's internalState synchronization manager.
It guarantees that all internalState-sensitive updates will be performed in correct order.
Limitations:
Manager cannot verify stateless types of updates (tg.UpdatesClass without Seq, or tg.UpdateClass without Pts or Qts).
Due to the fact that updates.getDifference and updates.getChannelDifference do not return event sequences, manager cannot guarantee the correctness of these operations. We rely on the server here.
Manager cannot recover the channel gap if there is a ChannelDifferenceTooLong error. Restoring the internalState in such situation is not the prerogative of this manager. See: https://core.telegram.org/constructor/updates.channelDifferenceTooLong
TODO: Write implementation details.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type API ¶
type API interface { UpdatesGetState(ctx context.Context) (*tg.UpdatesState, error) UpdatesGetDifference(ctx context.Context, request *tg.UpdatesGetDifferenceRequest) (tg.UpdatesDifferenceClass, error) UpdatesGetChannelDifference(ctx context.Context, request *tg.UpdatesGetChannelDifferenceRequest) (tg.UpdatesChannelDifferenceClass, error) }
API is the interface which contains Telegram RPC methods used by manager for internalState synchronization.
type AuthOptions ¶
type ChannelAccessHasher ¶
type ChannelAccessHasher interface { SetChannelAccessHash(ctx context.Context, userID, channelID, accessHash int64) error GetChannelAccessHash(ctx context.Context, userID, channelID int64) (accessHash int64, found bool, err error) }
ChannelAccessHasher stores users channel access hashes.
type Config ¶
type Config struct { // Handler where updates will be passed. Handler telegram.UpdateHandler // Callback called if manager cannot // recover channel gap (optional). OnChannelTooLong func(channelID int64) // State storage. // In-mem used if not provided. Storage StateStorage // Channel access hash storage. // In-mem used if not provided. AccessHasher ChannelAccessHasher // Logger (optional). Logger *zap.Logger // TracerProvider (optional). TracerProvider trace.TracerProvider }
Config of the manager.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager deals with gaps.
Important: Updates produced by this manager may contain negative Pts/Qts/Seq values in tg.UpdateClass/tg.UpdatesClass (does not affects to the tg.MessageClass).
This is because telegram server does not return these sequences for getDifference/getChannelDifference results. You SHOULD NOT use them in update handlers at all.
type StateStorage ¶
type StateStorage interface { GetState(ctx context.Context, userID int64) (state State, found bool, err error) SetState(ctx context.Context, userID int64, state State) error SetPts(ctx context.Context, userID int64, pts int) error SetQts(ctx context.Context, userID int64, qts int) error SetDate(ctx context.Context, userID int64, date int) error SetSeq(ctx context.Context, userID int64, seq int) error SetDateSeq(ctx context.Context, userID int64, date, seq int) error GetChannelPts(ctx context.Context, userID, channelID int64) (pts int, found bool, err error) SetChannelPts(ctx context.Context, userID, channelID int64, pts int) error ForEachChannels(ctx context.Context, userID int64, f func(ctx context.Context, channelID int64, pts int) error) error }
StateStorage is the users internalState storage.
Note: SetPts, SetQts, SetDate, SetSeq, SetDateSeq should return error if user internalState does not exist.