peer

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2021 License: MIT Imports: 6 Imported by: 30

Documentation

Overview

Package peer conatains some peer resolving and extracting helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DialogKey added in v0.27.0

type DialogKey struct {
	Kind       Kind
	ID         int
	AccessHash int64
}

DialogKey is a generic peer key.

func (*DialogKey) FromInputPeer added in v0.27.0

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

FromInputPeer fills key using given peer.

func (*DialogKey) FromPeer added in v0.27.0

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

FromPeer fills key using given peer.

type Entities

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

Entities is simple peer entities storage.

func EntitiesFromResult

func EntitiesFromResult(r EntitySearchResult) Entities

EntitiesFromResult fills Entities struct using given context.

func EntitiesFromUpdate

func EntitiesFromUpdate(uctx tg.UpdateContext) Entities

EntitiesFromUpdate fills Entities struct using given context.

func NewEntities

func NewEntities(
	users map[int]*tg.User,
	chats map[int]*tg.Chat,
	channels map[int]*tg.Channel,
) Entities

NewEntities creates new Entities struct.

func (Entities) ExtractPeer

func (ent Entities) ExtractPeer(peerID tg.PeerClass) (tg.InputPeerClass, error)

ExtractPeer finds and creates InputPeerClass using given PeerClass.

func (Entities) Fill

func (ent Entities) Fill(
	users map[int]*tg.User,
	chats map[int]*tg.Chat,
	channels map[int]*tg.Channel,
)

Fill adds and updates all entities from given maps.

func (Entities) FillFromResult

func (ent Entities) FillFromResult(r EntitySearchResult)

FillFromResult adds and updates all entities from given result.

func (Entities) FillFromUpdate

func (ent Entities) FillFromUpdate(uctx tg.UpdateContext)

FillFromUpdate adds and updates all entities from given updates.

type EntitySearchResult

type EntitySearchResult interface {
	MapChats() tg.ChatClassArray
	MapUsers() tg.UserClassArray
}

EntitySearchResult is abstraction for different RPC responses which contains entities.

type Kind added in v0.27.0

type Kind int

Kind represents peer kind.

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

type LRUResolver

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

LRUResolver is simple decorator for Resolver to cache result in LRU.

func NewLRUResolver

func NewLRUResolver(next Resolver, capacity int) *LRUResolver

NewLRUResolver creates new LRUResolver.

func (*LRUResolver) Resolve

func (l *LRUResolver) Resolve(ctx context.Context, domain string) (tg.InputPeerClass, error)

Resolve implements Resolver.

type Promise added in v0.27.0

type Promise func(ctx context.Context) (tg.InputPeerClass, error)

Promise is a peer promise.

func Resolve added in v0.27.0

func Resolve(r Resolver, from string) Promise

Resolve uses given text to create new message builder. It resolves peer of message using Sender's PeerResolver. Input examples:

@telegram
telegram
t.me/telegram
https://t.me/telegram
tg:resolve?domain=telegram
tg://resolve?domain=telegram
func ResolveDeeplink(r Resolver, deeplink string) Promise

ResolveDeeplink uses given deeplink to create new message builder. Deeplink is a URL like https://t.me/telegram. It resolves peer of message using Sender's PeerResolver. Input examples:

t.me/telegram
https://t.me/telegram
tg:resolve?domain=telegram
tg://resolve?domain=telegram

func ResolveDomain added in v0.27.0

func ResolveDomain(r Resolver, domain string) Promise

ResolveDomain uses given domain to create new message builder. It resolves peer of message using Sender's PeerResolver. Can has prefix with @ or not. Input examples:

@telegram
telegram

type Resolver

type Resolver interface {
	Resolve(ctx context.Context, domain string) (tg.InputPeerClass, error)
}

Resolver is a abstraction to resolve domains and Telegram deeplinks

func DefaultResolver

func DefaultResolver(raw *tg.Client) Resolver

DefaultResolver creates and returns default resolver.

type ResolverFunc

type ResolverFunc func(ctx context.Context, domain string) (tg.InputPeerClass, error)

ResolverFunc is a functional adapter for Resolver.

func (ResolverFunc) Resolve

func (p ResolverFunc) Resolve(ctx context.Context, domain string) (tg.InputPeerClass, error)

Resolve implements Resolver.

Jump to

Keyboard shortcuts

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