Documentation
¶
Overview ¶
Package updates provides a Telegram's state synchronization engine.
It guarantees that all state-sensitive updates will be performed in correct order.
Limitations:
Engine 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, the engine cannot guarantee the correctness of these operations. We rely on the server here.
Engine cannot recover the channel gap if there is a ChannelDifferenceTooLong error. Restoring the state in such situation is not the prerogative of this engine. See: https://core.telegram.org/constructor/updates.channelDifferenceTooLong
TODO: Write implementation details.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrStateNotFound = xerrors.Errorf("state not found")
ErrStateNotFound says that we do not have a local state.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { RawClient RawClient Handler Handler SelfID int IsBot bool // Storage is the place whether the state is stored. // In-mem by default. Storage Storage // Number of workers which handles updates. // Min is 5. Concurrency int Forget bool Logger *zap.Logger }
Config is an engine config.
type DiffUpdate ¶
type DiffUpdate struct { NewMessages []tg.MessageClass NewEncryptedMessages []tg.EncryptedMessageClass OtherUpdates []tg.UpdateClass Users []tg.UserClass Chats []tg.ChatClass Pending []tg.UpdateClass PendingEnts *Entities }
DiffUpdate contains updates received by getDifference.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine deals with gaps.
type Entities ¶
Entities contains Telegram's entities which comes with updates.
type Handler ¶
type Handler interface { HandleDiff(DiffUpdate) error HandleUpdates(Updates) error ChannelTooLong(channelID int) }
Handler interface.
type RawClient ¶
type RawClient 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) }
RawClient interface contains Telegram RPC calls used by the engine for state synchronization.
type Storage ¶
type Storage interface { GetState() (State, error) SetState(s State) error SetPts(pts int) error SetQts(qts int) error SetDateSeq(date, seq int) error SetChannelPts(channelID, pts int) error Channels(iter func(channelID, pts int)) error ForgetAll() error }
Storage interface.
type Updates ¶
type Updates struct { Updates []tg.UpdateClass Ents *Entities }
Updates contains Telegram updates.