feedfollower

package
v0.0.0-...-f31bb51 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2023 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TelegramBotApiBotOnce = &sync.Once{}
View Source
var TelegramBotApiSingleton *tgbotapi.BotAPI

Telegram Bot api instance should be created only once to avoid duplicate messagees

View Source
var TelegramSendMessageLock = &sync.Mutex{}

Functions

func DeleteRssSubscription

func DeleteRssSubscription(url string, identifier string)

func GetSubscriptions

func GetSubscriptions(identifier string) []string

func NewRssSubscription

func NewRssSubscription(url string, identifier string)

func NewTelegramMessage

func NewTelegramMessage(
	title string,
	description string,
	url string,
	feedTitle string,
	feedLink string,
) string

func NewTelegramNotificationChannel

func NewTelegramNotificationChannel(identifier string)

func ProcessChannelEventUntilContextDone

func ProcessChannelEventUntilContextDone(processor func(), ctx context.Context)

func Run

func Run()

func RunPeriodically

func RunPeriodically(toRun func(), interval time.Duration, wg *sync.WaitGroup, ctx context.Context)

Types

type Configuration

type Configuration struct {
	PostgresUser                   string
	PostgresIamUser                string
	PostgresInstanceConnectionName string
	PostgresPassword               string
	PostgresDatabase               string
	PostgresConnectionName         string
	TelegramBotApiKey              string
}

type Feed

type Feed struct {
	Id      uint   `gorm:"primaryKey"`
	Type    string `gorm:"index:idx_type_url,unique"` // TODO: Actually enum
	Url     string `gorm:"index:idx_type_url,unique"`
	Options string // TODO: JSON
}

type FeedProcessor

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

func (*FeedProcessor) Close

func (feedProcessor *FeedProcessor) Close()

func (*FeedProcessor) FetchUpdates

func (feedProcessor *FeedProcessor) FetchUpdates()

func (*FeedProcessor) NotifySubscribers

func (feedProcessor *FeedProcessor) NotifySubscribers(feedProcessorUpdate FeedUpdate)

func (*FeedProcessor) Run

func (feedProcessor *FeedProcessor) Run()

func (*FeedProcessor) Subscribe

func (feedProcessor *FeedProcessor) Subscribe(observer Observer) bool

func (*FeedProcessor) SyncUserProcessors

func (feedProcessor *FeedProcessor) SyncUserProcessors()

func (*FeedProcessor) Unsubscribe

func (feedProcessor *FeedProcessor) Unsubscribe(observer Observer)

type FeedProcessors

type FeedProcessors struct {
	Processors *sync.Map
	// contains filtered or unexported fields
}

func (*FeedProcessors) Update

func (feedProcessors *FeedProcessors) Update()

type FeedUpdate

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

A single instance of a feed update, which is generated by the update generator and later passed all the way to the notification channel

func (*FeedUpdate) Hash

func (feedUpdate *FeedUpdate) Hash() string

type FeedUpdateGenerator

type FeedUpdateGenerator interface {
	Run()
	UpdatesChannel() chan FeedUpdate
	Close()
}

type History

type History struct {
	// TODO: first 4 - primary key
	// TODO: needs index
	UserId                uint   `gorm:"primaryKey"`
	FeedId                uint   `gorm:"primaryKey"`
	NotificationChannedId uint   `gorm:"primaryKey"`
	ItemHash              string `gorm:"primaryKey"`
	State                 string // TODO: should be enum
}

type NotificationChannel

type NotificationChannel struct {
	Id         uint `gorm:"primaryKey"`
	UserId     uint
	Type       string `gorm:"index:idx_type_identifier,unique"`
	Identifier string `gorm:"index:idx_type_identifier,unique"`
	AuthData   string // TODO: JSON
}

type Observable

type Observable interface {
	Subscribe(observer Observer)
	Unsubscribe(observer Observer) bool
	NotifySubscribers(feedProcessorUpdate FeedUpdate)
}

Abstract observable object interface for observer pattern

type Observer

type Observer interface {
	Id() uint
	Notify(feedProcessorUpdate FeedUpdate)
}

Abstract observer pattern interface

type RssFeedUpdateGenerator

type RssFeedUpdateGenerator struct {
	FeedId  uint
	Updates chan FeedUpdate
	// contains filtered or unexported fields
}

Implements FeedUpdateGenerator

func (*RssFeedUpdateGenerator) Close

func (rssFeedUpdateGenerator *RssFeedUpdateGenerator) Close()

func (*RssFeedUpdateGenerator) Run

func (rssFeedUpdateGenerator *RssFeedUpdateGenerator) Run()

func (*RssFeedUpdateGenerator) UpdatesChannel

func (rssFeedUpdateGenerator *RssFeedUpdateGenerator) UpdatesChannel() chan FeedUpdate

type TelegramBotAPI

type TelegramBotAPI struct {
	Bot *tgbotapi.BotAPI
}

func (*TelegramBotAPI) HandleUpdates

func (api *TelegramBotAPI) HandleUpdates(ctx context.Context)

func (*TelegramBotAPI) SendMessage

func (api *TelegramBotAPI) SendMessage(idString string, message string) error

func (*TelegramBotAPI) Start

func (api *TelegramBotAPI) Start(token string, debug bool) error

func (*TelegramBotAPI) Stop

func (api *TelegramBotAPI) Stop()

type TelegramNotificationChannel

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

Concrete observer for updates from user processor

func (*TelegramNotificationChannel) Close

func (notificationChannel *TelegramNotificationChannel) Close()

func (*TelegramNotificationChannel) Id

func (notificationChannel *TelegramNotificationChannel) Id() uint

func (*TelegramNotificationChannel) Notify

func (notificationChannel *TelegramNotificationChannel) Notify(feedProcessorUpdate FeedUpdate)

func (*TelegramNotificationChannel) Run

func (notificationChannel *TelegramNotificationChannel) Run()

type User

type User struct {
	Id uint `gorm:"primaryKey"`
}

TODO: add foreign keys

type UserFeed

type UserFeed struct {
	// TODO: first 2 primary key
	// TODO: needs index on user id and feed id
	UserId  uint   `gorm:"primaryKey"`
	FeedId  uint   `gorm:"primaryKey"`
	Options string // TODO: JSON
}

type UserProcessor

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

Observer and observable concrete implementation for the user processor. It will listen for the feed updates and once received, will notify all the subscribed notification channels

func (*UserProcessor) Close

func (userProcessor *UserProcessor) Close()

func (*UserProcessor) Id

func (userProcessor *UserProcessor) Id() uint

func (*UserProcessor) Notify

func (userProcessor *UserProcessor) Notify(feedProcessorUpdate FeedUpdate)

func (*UserProcessor) NotifySubscribers

func (userProcessor *UserProcessor) NotifySubscribers(feedProcessorUpdate FeedUpdate)

func (*UserProcessor) Run

func (userProcessor *UserProcessor) Run()

func (*UserProcessor) Subscribe

func (userProcessor *UserProcessor) Subscribe(observer Observer) bool

func (*UserProcessor) SyncNotificationChannels

func (userProcessor *UserProcessor) SyncNotificationChannels()

func (*UserProcessor) Unsubscribe

func (userProcessor *UserProcessor) Unsubscribe(observer Observer)

Jump to

Keyboard shortcuts

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