dialogs

package
v0.0.0-...-3ee0582 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package dialogs contains dialog iteration helper.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DialogKey

type DialogKey struct {
	Kind       PeerKind
	ID         int64
	AccessHash int64
}

DialogKey is a generic peer key.

func (*DialogKey) FromInputPeer

func (d *DialogKey) FromInputPeer(peer tg.InputPeerClass) error

FromInputPeer fills key using given peer.

func (*DialogKey) FromPeer

func (d *DialogKey) FromPeer(peer tg.PeerClass) error

FromPeer fills key using given peer.

type Elem

type Elem struct {
	Dialog   tg.DialogClass
	Peer     tg.InputPeerClass
	Last     tg.NotEmptyMessage
	Entities peer.Entities
}

Elem is a dialog iterator element.

func (Elem) Deleted

func (e Elem) Deleted() bool

Deleted denotes that dialog is deleted.

func (Elem) Messages

func (e Elem) Messages(raw *tg.Client) *messages.GetHistoryQueryBuilder

Messages returns new messages history query builder for current dialog.

func (Elem) Participants

func (e Elem) Participants(raw *tg.Client) (*participants.GetParticipantsQueryBuilder, bool)

Participants returns new channel participants query builder for current dialog. If peer is not channel, returns false.

func (Elem) RecentLocations

func (e Elem) RecentLocations(raw *tg.Client) *messages.GetRecentLocationsQueryBuilder

RecentLocations returns new live location history query builder for current dialog.

func (Elem) Replies

func (e Elem) Replies(raw *tg.Client) *messages.GetRepliesQueryBuilder

Replies returns new replies query builder for current dialog.

func (Elem) Search

func (e Elem) Search(raw *tg.Client) *messages.SearchQueryBuilder

Search returns new search query builder for current dialog.

func (Elem) UnreadMentions

func (e Elem) UnreadMentions(raw *tg.Client) *messages.GetUnreadMentionsQueryBuilder

UnreadMentions returns new unread mentions query builder for current dialog.

func (Elem) UserPhotos

func (e Elem) UserPhotos(raw *tg.Client) (*photos.GetUserPhotosQueryBuilder, bool)

UserPhotos returns new user photo query builder for current dialog. If peer is not user, returns false.

type GetDialogsQueryBuilder

type GetDialogsQueryBuilder struct {
	// contains filtered or unexported fields
}

GetDialogsQueryBuilder is query builder of MessagesGetDialogs.

func (*GetDialogsQueryBuilder) BatchSize

func (b *GetDialogsQueryBuilder) BatchSize(batchSize int) *GetDialogsQueryBuilder

BatchSize sets buffer of message loaded from one request. Be carefully, when set this limit, because Telegram does not return error if limit is too big, so results can be incorrect.

func (*GetDialogsQueryBuilder) Collect

func (b *GetDialogsQueryBuilder) Collect(ctx context.Context) ([]Elem, error)

Collect creates iterator and collects all elements to slice.

func (*GetDialogsQueryBuilder) Count

func (b *GetDialogsQueryBuilder) Count(ctx context.Context) (int, error)

Count fetches remote state to get number of elements.

func (*GetDialogsQueryBuilder) FolderID

func (b *GetDialogsQueryBuilder) FolderID(paramFolderID int) *GetDialogsQueryBuilder

FolderID sets FolderID field of GetDialogs query.

func (*GetDialogsQueryBuilder) ForEach

func (b *GetDialogsQueryBuilder) ForEach(ctx context.Context, cb func(context.Context, Elem) error) error

ForEach calls given callback on each iterator element.

func (*GetDialogsQueryBuilder) Iter

func (b *GetDialogsQueryBuilder) Iter() *Iterator

Iter returns iterator using built query.

func (*GetDialogsQueryBuilder) OffsetDate

func (b *GetDialogsQueryBuilder) OffsetDate(offsetDate int) *GetDialogsQueryBuilder

OffsetDate sets offsetDate from which iterate start.

func (*GetDialogsQueryBuilder) OffsetID

func (b *GetDialogsQueryBuilder) OffsetID(offsetID int) *GetDialogsQueryBuilder

OffsetID sets offsetID from which iterate start.

func (*GetDialogsQueryBuilder) Query

Query implements Query interface.

type Iterator

type Iterator struct {
	// contains filtered or unexported fields
}

Iterator is a dialog stream iterator.

func NewIterator

func NewIterator(query Query, limit int) *Iterator

NewIterator creates new iterator.

func (*Iterator) Err

func (m *Iterator) Err() error

Err returns the error, if any, that was encountered during iteration.

func (*Iterator) FetchTotal

func (m *Iterator) FetchTotal(ctx context.Context) (int, error)

FetchTotal fetches and returns count of elements.

func (*Iterator) Next

func (m *Iterator) Next(ctx context.Context) bool

Next prepares the next message for reading with the Value method. It returns true on success, or false if there is no next message or an error happened while preparing it. Err should be consulted to distinguish between the two cases.

func (*Iterator) OffsetDate

func (m *Iterator) OffsetDate(offsetDate int) *Iterator

OffsetDate sets OffsetDate request parameter.

func (*Iterator) OffsetID

func (m *Iterator) OffsetID(offsetID int) *Iterator

OffsetID sets OffsetID request parameter.

func (*Iterator) OffsetPeer

func (m *Iterator) OffsetPeer(offsetPeer tg.InputPeerClass) *Iterator

OffsetPeer sets OffsetPeer request parameter.

func (*Iterator) Total

func (m *Iterator) Total(ctx context.Context) (int, error)

Total returns last fetched count of elements. If count was not fetched before, it requests server using FetchTotal.

func (*Iterator) Value

func (m *Iterator) Value() Elem

Value returns current message.

type PeerKind

type PeerKind int

PeerKind represents peer kind.

const (
	// User is a private chat with user.
	User PeerKind = iota
	// Chat is a legacy chat.
	Chat
	// Channel is a supergroup/channel.
	Channel
)

type Query

type Query interface {
	Query(ctx context.Context, req Request) (tg.MessagesDialogsClass, error)
}

Query is an abstraction for dialogs request. NB: iterator mutates returned data (sorts, at least).

type QueryBuilder

type QueryBuilder struct {
	// contains filtered or unexported fields
}

QueryBuilder is a helper to create message queries.

func NewQueryBuilder

func NewQueryBuilder(raw *tg.Client) *QueryBuilder

NewQueryBuilder creates new QueryBuilder.

func (*QueryBuilder) GetDialogs

func (q *QueryBuilder) GetDialogs() *GetDialogsQueryBuilder

GetDialogs creates query builder of MessagesGetDialogs.

type QueryFunc

type QueryFunc func(ctx context.Context, req Request) (tg.MessagesDialogsClass, error)

QueryFunc is a function adapter for Query.

func (QueryFunc) Query

Query implements Query interface.

type Request

type Request struct {
	OffsetDate int
	OffsetID   int
	OffsetPeer tg.InputPeerClass
	Limit      int
}

Request is a parameter for Query.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL