repository

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

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

Go to latest
Published: Sep 19, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearRelay

func ClearRelay(c *RelayConnection)

func ConnectRelay

func ConnectRelay(c *RelayConnection) error

func ExtTagValue

func ExtTagValue(
	tags nostr.Tags,
) []string

func FilterTag

func FilterTag(
	e *nostr.Event,
	tag string,
) nostr.Tags

func FilterTagWithCond

func FilterTagWithCond(
	tags nostr.Tags,
	conditions map[int]string,
) nostr.Tags

ExtractTagWithCond

func GetEventsByAuthor

func GetEventsByAuthor(
	kinds []int,
	authors []domain.UserPubKey,
	options domain.PagingOptions,
) []*nostr.Event

func GetEventsFromString

func GetEventsFromString(
	c StringCacheMap,
	key string,
) []*nostr.Event

GetEventsFromString

func ManageEventsFromString

func ManageEventsFromString(
	c StringCacheMap,
	key string,
	supplier func() []*nostr.Event,
) []*nostr.Event

ManageEventsFromString

func PrintConnectionError

func PrintConnectionError(c *RelayConnection, err error)

func QuerySyncAll

func QuerySyncAll(
	ctx context.Context,
	filters nostr.Filters,
) []*nostr.Event

QuerySyncAll Query all relay servers and retrieve results synchronously

func QuerySyncAllWithOptions

func QuerySyncAllWithOptions(
	ctx context.Context,
	filters nostr.Filters,
	options QueryOptions,
) []*nostr.Event

QuerySyncAllWithOptions Query all relay servers and retrieve results synchronously

func SentEventAll

func SentEventAll(
	ctx context.Context,
	event nostr.Event,
) bool

SentEventAll

func SetEventsFromString

func SetEventsFromString(
	c StringCacheMap,
	key string,
	v []*nostr.Event,
)

SetEventsFromString

func SleepTimeSpan

func SleepTimeSpan(c *RelayConnection)

func StartAllRelayServers

func StartAllRelayServers(urls []string)

StartAllRelayServers Connect to all relay servers.

func StartRelayServer

func StartRelayServer(url string)

StartRelayServer Connect to relay server.

Types

type Event

type Event struct {
	ID        string
	PubKey    string
	Content   string
	CreatedAt int64
}

type PostEvent

type PostEvent struct {
	Event
	RootPostID           *string
	ReplyPostID          *string
	MentionedUserPubKeys []string
}

func MarshalPostEvent

func MarshalPostEvent(e *nostr.Event) (*PostEvent, error)

func (*PostEvent) ToPost

func (e *PostEvent) ToPost() domain.Post

type QueryOptions

type QueryOptions struct {
	RequiredOneEvent   bool
	ExpectedEventCount int
	ExpectedEOSECount  int
	TimeoutSeconds     time.Duration
}

func DefaultQueryOptions

func DefaultQueryOptions() QueryOptions

type ReactionEvent

type ReactionEvent struct {
	Event
	ToPost []string
	ToUser []string
}

func MarshalReactionEvent

func MarshalReactionEvent(e *nostr.Event) (*ReactionEvent, error)

func (*ReactionEvent) ToReaction

func (e *ReactionEvent) ToReaction() domain.Reaction

type RelayConnection

type RelayConnection struct {
	URL      string
	Relay    *nostr.Relay
	Context  *context.Context
	Cancel   *context.CancelFunc
	WaitSpan time.Duration
	Error    chan error
}

func GetConnections

func GetConnections() []*RelayConnection

GetConnections Obtain relay server connection information

type RelayEventsCache

type RelayEventsCache struct {
	Events    []*nostr.Event
	ExpiredAt int64
}

type RelayPostRepository

type RelayPostRepository struct {
	LatestPostCache StringCacheMap
	GetRepliesCache StringCacheMap
}

func NewRelayPostRepository

func NewRelayPostRepository() *RelayPostRepository

NewRelayPostRepository Create a new post repository

func (*RelayPostRepository) GetPost

func (r *RelayPostRepository) GetPost(
	id domain.PostID,
) (*domain.Post, error)

GetPost

func (*RelayPostRepository) GetPosts

func (r *RelayPostRepository) GetPosts(
	pks []domain.UserPubKey,
	options domain.PagingOptions,
) ([]domain.Post, error)

GetPosts

func (*RelayPostRepository) GetPublicPosts

func (r *RelayPostRepository) GetPublicPosts(
	options domain.PagingOptions,
) ([]domain.Post, error)

GetPublicPosts

func (*RelayPostRepository) GetReplies

func (r *RelayPostRepository) GetReplies(
	id domain.PostID,
) ([]domain.Post, error)

GetReplies

func (*RelayPostRepository) GetUserLatestPosts

func (r *RelayPostRepository) GetUserLatestPosts(
	pk domain.UserPubKey,
) ([]domain.Post, error)

GetUserLatestPosts

func (*RelayPostRepository) SendPost

func (r *RelayPostRepository) SendPost(
	pk domain.UserPubKey,
	sk domain.UserSecretKey,
	text string,
) error

SendPost

type RelayReactionRepository

type RelayReactionRepository struct {
	Cache StringCacheMap
}

func NewRelayReactionRepository

func NewRelayReactionRepository() *RelayReactionRepository

NewRelayReactionRepository Create a new post repository

func (RelayReactionRepository) GetReactions

func (r RelayReactionRepository) GetReactions(
	id domain.PostID,
) ([]domain.Reaction, error)

type RelayRelationShipRepository

type RelayRelationShipRepository struct {
	FollowingsCache StringCacheMap
	FollowersCache  StringCacheMap
}

func NewRelayRelationShipRepository

func NewRelayRelationShipRepository() *RelayRelationShipRepository

NewRelayRelationShipRepository Create a new relay relationship repository

func (*RelayRelationShipRepository) GetFollowers

GetFollowers Get public keys of users specific user is followed by

func (*RelayRelationShipRepository) GetFollowings

func (r *RelayRelationShipRepository) GetFollowings(
	pk domain.UserPubKey,
) ([]domain.UserPubKey, error)

GetFollowings Get public keys of users specific user is following

type RelayRepostRepository

type RelayRepostRepository struct {
	Cache StringCacheMap
}

func NewRelayRepostRepository

func NewRelayRepostRepository() *RelayRepostRepository

NewRelayRepostRepository Create a new post repository

func (RelayRepostRepository) GetReposts

func (r RelayRepostRepository) GetReposts(
	id domain.PostID,
) ([]domain.Repost, error)

type RelayTimelineRepository

type RelayTimelineRepository struct {
}

func NewRelayTimelineRepository

func NewRelayTimelineRepository() *RelayTimelineRepository

NewRelayTimelineRepository Create a new timeline repository

func (*RelayTimelineRepository) GetTimelines

func (r *RelayTimelineRepository) GetTimelines(
	pks []domain.UserPubKey,
	options domain.PagingOptions,
) ([]domain.Timeline, error)

GetTimelines

type RelayUserRepository

type RelayUserRepository struct {
	Cache *lru.Cache[domain.UserPubKey, *UserEventCache]
}

func NewRelayUserRepository

func NewRelayUserRepository() *RelayUserRepository

NewRelayUserRepository Create a new relay user repository

func (*RelayUserRepository) GetUserFromCache

func (r *RelayUserRepository) GetUserFromCache(
	pk domain.UserPubKey,
) *domain.User

GetUserFromCache Retrieve user information from cached data

func (*RelayUserRepository) GetUsers

func (r *RelayUserRepository) GetUsers(
	pks []domain.UserPubKey,
) ([]domain.User, error)

GetUsers Retrieve user information

func (*RelayUserRepository) SetUserCache

func (r *RelayUserRepository) SetUserCache(
	pk domain.UserPubKey,
	event *UserEvent,
)

type RepostEvent

type RepostEvent struct {
	Event
	ToPost []string
	ToUser []string
}

func MarshalRepostEvent

func MarshalRepostEvent(e *nostr.Event) (*RepostEvent, error)

func (*RepostEvent) ToRepost

func (e *RepostEvent) ToRepost() domain.Repost

type StringCacheMap

type StringCacheMap = *lru.Cache[string, *RelayEventsCache]

func NewStringCacheMap

func NewStringCacheMap(size int) StringCacheMap

type UserEvent

type UserEvent struct {
	Event
	Name        string `json:"name"`
	DisplayName string `json:"display_name"`
	About       string `json:"about"`
	Picture     string `json:"picture"`
	Banner      string `json:"banner"`
	Website     string `json:"website"`
	Lud06       string `json:"lud06"`
}

func MarshalUserEvent

func MarshalUserEvent(e *nostr.Event) (*UserEvent, error)

func (*UserEvent) ToUser

func (e *UserEvent) ToUser() *domain.User

type UserEventCache

type UserEventCache struct {
	Event     *UserEvent
	ExpiredAt int64
}

Jump to

Keyboard shortcuts

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