models

package
v0.80.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: AGPL-3.0 Imports: 57 Imported by: 0

Documentation

Overview

Package models provides primitives to interact with the openapi HTTP API.

Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.6.0 DO NOT EDIT.

Package models contains objects and fields representing common schema within the application.

Index

Constants

View Source
const (
	ParamObjectType = "object"
	ParamObjectID   = "id"
	// ParamCategories is a list of category names, of any single object type (subscription or article).
	ParamCategories = "categories"
	// ParamCount is the number of results to show, where multiple results can be displayed.
	ParamCount = "count"
	// ParamPagination is the encoded pagination value, used to fetch the next set of results when paginating through a
	// list of objects.
	ParamPagination = "pagination"
	// ParamSort is the sort option to apply to a set of results.
	ParamSort = "sort"
	// ParamView is the view filter to apply to a set of results.
	ParamView = "view"
	// ParamMark is a mark to apply to either an object or set of objects in the request.
	ParamMark = "mark"
	// ParamFeedID identifies a single feed by its id.
	ParamFeedID = "feed_id"
	// ParamItemID identifies a single item by its id.
	ParamItemID = "item_id"
	// ParamSubscriptionID identifies a single subscription by its id.
	ParamSubscriptionID   = "subscription_id"
	ParamSubscriptionName = "subscription_name"
	// ParamSubscriptions is a list of subscription ids.
	ParamSubscriptions      = "subscriptions"
	ParamFullArticleContent = "show_full_content"
	ParamOnlyFavorites      = "only_favorites"
	// ParamPlanID is the ID of the subscription plan the user has chosen.
	ParamPlanID = "plan_id"
	// ParamThumbnail is a thumbnail image uploaded by the user.
	ParamThumbnail = "thumbnail"
)
View Source
const (
	RouteHome = "/home"

	RouteSignup             = "/signup"
	RouteCheckout           = "/checkout"
	RouteCheckoutChoosePlan = "/checkout/choose-plan"

	RouteListSubscriptions = "/list/subscriptions"
	RouteListArticles      = "/list/articles"
	RouteListFavorites     = "/list/favorites"

	RouteUserAccountIssue              = "/user/account-issue"
	RouteUserDeactivateAccount         = "/user/deactivate"
	RouteUserCancelDeactivationAccount = "/user/deactivate/cancel"
)
View Source
const (
	// DefaultUserTheme is the default theme for the app.
	DefaultUserTheme = "greenhouse"
	// DefaultMaxHistory is a default maximum history value for when the user has not specified one.
	DefaultMaxHistory = 31 * 24 * time.Hour
	// DefaultUpdateInterval is the default interval on which to check for updates.
	DefaultUpdateInterval = 5 * time.Minute
	// MaxSubscriptions is the maxiumum number of subscriptions a user can have.
	MaxSubscriptions = 3000
)
View Source
const (
	// DefaultPaginationSize is the default number of docs to fetch when paginating through results from elasticsearch.
	DefaultPaginationSize = 5000
)

Variables

View Source
var (
	// ErrNotFound indicates the backend API returned no results.
	ErrNotFound = &APIError{
		InternalError: errors.New("not found"),
		StatusCode:    http.StatusNotFound,
	}
	// ErrInvalidAPIResult indicates that the backend API returned unexpected, invalid or an otherwise incorrect response.
	ErrInvalidAPIResult = &APIError{
		InternalError: errors.New("invalid backend API result"),
		StatusCode:    http.StatusInternalServerError,
	}
	// ErrInvalidParams indicates that invalid parameters were received or generated.
	ErrInvalidParams = &APIError{
		InternalError: errors.New("invalid parameters"),
		StatusCode:    http.StatusUnprocessableEntity,
	}
)
View Source
var CommonCategoryFilters = []string{
	"Post",
	"Posts",
	"News",
	"Article",
	"Articles",
	"Links",
	"Uncategorized",
	"Featured",
	"Headline",
	"Home Feed",
}

CommonCategoryFilters is slice of categories that are so general or inclusive that they are ultimately useless for queries or aggregations.

Regular expressions are supported. See:

https://www.elastic.co/docs/reference/query-languages/query-dsl/regexp-syntax

View Source
var ErrCtxValueNotFound = &APIError{
	InternalError: errors.New("context value not found"),
	StatusCode:    http.StatusInternalServerError,
}
View Source
var ErrFileTooLarge = errors.New("file is too large")

ErrFileTooLarge can be used to indicate a file upload had a size greater than a set limit.

View Source
var ErrInvalidDateTimeFormat = errors.New("datetime is invalid")
View Source
var ErrInvalidMimeType = errors.New("invalid mime type")

ErrInvalidMimeType indicates that the mime type is not valid.

View Source
var ErrNoFilters = &APIError{
	InternalError: errors.New("no filters found"),
	StatusCode:    http.StatusNotFound,
}
View Source
var ErrUnknown = errors.New("an unknown error occurred")
View Source
var (
	ErrUserAlreadyFavorited = errors.New("already a favorite")
)
View Source
var UnixEpoch = time.Unix(0, 0)

Functions

func AddFeedStatus added in v0.46.0

func AddFeedStatus(ctx context.Context, status *FeedStatus) error

AddFeedStatus adds a FeedStatus document to the index.

func AddItems added in v0.25.0

func AddItems(ctx context.Context, items ...Item) error

AddItems wraps an elastic bulk update to index items.

func AddSubscriptions

func AddSubscriptions(ctx context.Context, subscriptions ...*Subscription) error

AddSubscriptions adds the given subscriptions to a user.

func ArticleFiltersQueryClause added in v0.60.0

func ArticleFiltersQueryClause(source ItemSource) query.BoolOption

func BuildItemQueries added in v0.26.0

func BuildItemQueries(
	user *User,
	view View,
	subscriptions Subscriptions,
) []query.Option

BuildItemQueries generates a slices of queries for the given subscriptions, based on the given filters.

func BuildItemsQuery

func BuildItemsQuery(
	ctx context.Context,
	filters Filters,
	subscriptionIDs ...SubscriptionID,
) (query.Option, error)

BuildItemsQuery generates a query to fetch the Items that match the given Filters from the given Subscriptions.

func BuildSearchResultsQuery

func BuildSearchResultsQuery(
	ctx context.Context,
	user *User,
	request *SearchRequest,
	clause query.BoolOption,
) (query.Option, error)

BuildSearchResultsQuery generates a query that can be used to fetch appropriate results for a given SearchRequest criteria.

func CountItems

func CountItems(ctx context.Context, query query.Option) (int64, error)

CountItems returns a count of items that match the given query.

func CreateFeedSubscriptions

func CreateFeedSubscriptions(ctx context.Context, results ...*AddFeedSubscriptionResult) error

CreateFeedSubscriptions will create new FeedSubscriptions for the user from the given requests.

func CreateSearchSubscriptions

func CreateSearchSubscriptions(ctx context.Context, requests ...*SearchSubscriptionRequest) error

CreateSearchSubscriptions will create new SearchSubscriptions for the user from the given requests.

func ElasticsearchToAPIError added in v0.51.0

func ElasticsearchToAPIError(err error) error

ElasticsearchToAPIError will extract and wrap a types.ElasticsearchError from the given error, in a APIError containing its pertinent information. If the given error does not contain types.ElasticsearchError, the given error is wrapped in a generic APIError is created.

func FeedURLParser added in v0.54.0

func FeedURLParser(ctx context.Context, urlStr string) (*url.URL, error)

FeedURLParser parses the given URL string into a url.URL object, applying some additional rules for known domains on where to find their feeds.

func FilterArticles

func FilterArticles(
	ctx context.Context,
	request *ListRequest,
) (Articles, Pagination, error)

FilterArticles returns Articles filtered by the given filters and paginated by the given pagination.

func FilterMap

func FilterMap[K comparable, V any](m map[K]V, fn func(K, V) bool) iter.Seq2[K, V]

FilterMap will filter a map by the given function.

func FilterMapValues

func FilterMapValues[K comparable, V any](s map[K]V, fn func(V) bool) iter.Seq[V]

FilterMapValues will filter map values by the given function.

func FilterSlice

func FilterSlice[E any](s []E, fn func(E) bool) iter.Seq[E]

FilterSlice will filter a slice returning an iter with elements that return true for the given filter function.

func FilterSubscriptions

func FilterSubscriptions(
	ctx context.Context,
	request *ListRequest,
) (Subscriptions, Pagination, error)

FilterSubscriptions returns subscriptions filtered by the given filters and paginated by the given pagination. Dynamic information for subscriptions will also be added.

func FindAllHTMLNodes added in v0.77.0

func FindAllHTMLNodes(n *html.Node, tag string) []*html.Node

FindAllHTMLNodes returns all nodes matching the tag within n.

func FindFeedImage added in v0.57.0

func FindFeedImage(ctx context.Context, feed *Feed) error

FindFeedImage will try to find an image to represent the feed. Useful to call if the feed does not define an image itself.

func FindHTMLNode added in v0.77.0

func FindHTMLNode(n *html.Node, tag string) *html.Node

FindHTMLNode does a depth-first search for the first node matching the tag.

func GetSubscriptionsByCategories

func GetSubscriptionsByCategories(categories ...Category) subscriptionsRequestOption

GetSubscriptionsByCategories option adds a filter to the query to get subscriptions by category.

func GetSubscriptionsByFavorite

func GetSubscriptionsByFavorite(value bool) subscriptionsRequestOption

GetSubscriptionsByFavorite option adds a filter to the query to get favorite subscriptions only.

func GetSubscriptionsByFeedIDs

func GetSubscriptionsByFeedIDs(ids ...FeedID) subscriptionsRequestOption

GetSubscriptionsByFeedIDs option adds a filter to the query to get subscriptions by their feed ids.

func GetSubscriptionsByIDs

func GetSubscriptionsByIDs(ids ...SubscriptionID) subscriptionsRequestOption

GetSubscriptionsByIDs option adds a filter to the query to get subscriptions by their ids.

func GetSubscriptionsDynamicInfo

func GetSubscriptionsDynamicInfo(value bool) subscriptionsRequestOption

GetSubscriptionsDynamicInfo option will fill in the dynamic info (i.e., stats) after fetching.

func GetUserTheme

func GetUserTheme(ctx context.Context) string

GetUserTheme returns the current user's theme or the default theme if no user theme is set.

func HTTPStatus

func HTTPStatus(err error) int

HTTPStatus returns the HTTP status included in err. If err is nil, this function returns 0. If err is non-nil, and does not include an HTTP status, a default value of net/http.StatusInternalServerError is returned.

func IgnoreSubscriptions added in v0.54.0

func IgnoreSubscriptions(ids ...SubscriptionID) subscriptionsRequestOption

func IsHTML added in v0.61.0

func IsHTML(s string) bool

IsHTML returns a boolean indicating whether the given string contains HTML. It can detect both a full HTML document or partial HTML content.

func IsHTMLElement added in v0.67.0

func IsHTMLElement(str, tag string) bool

IsHTMLElement returns a boolean indicating whether the given string is the given HTML element.

func ItemsAggregation

func ItemsAggregation(
	ctx context.Context,
	query query.Option,
	size int,
	aggregations aggregations.Aggs,
) (*search.Response, error)

ItemsAggregation performs an aggregation-only (i.e., search request with no hits returned) using the given query as the set of documents and performing the given aggregations across the documents.

func MarkSubscriptions

func MarkSubscriptions(
	ctx context.Context,
	mark Mark,
	subscriptionIDs ...SubscriptionID,
) error

MarkSubscriptions will mark as appropriate all the given subscriptions. Marking a subscription includes updating the subscription data in the user object and clearing any individual item states for a subscription.

func MarkdownToHTML added in v0.61.0

func MarkdownToHTML(input []byte) ([]byte, error)

MarkdownToHTML treats the given string data input as markdown formatted plain-text and returns an appropriate HTML representation.

func PageFiltersToCtx

func PageFiltersToCtx(ctx context.Context, path string, filters Filters) context.Context

PageFiltersToCtx stores the current page display filters in the context.

func PathFromCtx

func PathFromCtx(ctx context.Context) string

PathFromCtx retrieves the URL path from the context.

func PathToCtx

func PathToCtx(ctx context.Context, path string) context.Context

PathToCtx stores the URL path in the context.

func ProcessSubscriptionRequest

func ProcessSubscriptionRequest(
	ctx context.Context,
	request *AddFeedSubscriptionRequest,
	resultsCh chan AddFeedSubscriptionResult,
)

ProcessSubscriptionRequest manages parsing a subscription request and turning it into a subscription that can be added to a user. It handles finding a existing matching feed or creating a new one, checking the user isn't already subscribed and generating an appropriate subscription object. It returns an object that includes the request and new subscription data, or the request and an error if subscription data could not be generated.

func RemoveSubscriptions

func RemoveSubscriptions(ctx context.Context, ids ...SubscriptionID) error

RemoveSubscriptions removes subscriptions with the given ID from a user.

func SearchItems

func SearchItems(
	ctx context.Context,
	query query.Option,
	count int,
	sort *Sort,
	pagination *Pagination,
) (Items, Pagination, error)

SearchItems will search the items index for items matching the given query. Count, sort and pagination values are optional.

func SearchResultsClause

func SearchResultsClause(search *SearchRequest) query.BoolOption

func SearchSubscriptions

func SearchSubscriptions(
	ctx context.Context,
	query query.Option,
	options ...searchSubscriptionsOption,
) (Subscriptions, Pagination, error)

func SearchSuggestionsClause

func SearchSuggestionsClause(search *SearchRequest) query.BoolOption

func SliceToMap

func SliceToMap[K comparable, V any, S any](s []S, mapFn func(S) (K, V)) map[K]V

SliceToMap generates a map from slice content by mapping key-value pairs from the slice with the given map function.

func SubscriptionsToCtx

func SubscriptionsToCtx(ctx context.Context, subscriptions Subscriptions) context.Context

SubscriptionsToCtx stores the slice of Subscriptions in the context. Useful for pre-fetching/generating subscriptions for later usage.

func UpdateFavoriteSubscription

func UpdateFavoriteSubscription(ctx context.Context, id SubscriptionID, favorite bool) error

UpdateFavoriteSubscription changes the favorite status of a subscription by updating the user object to flag the subscription as appropriate.

func UpdateFeed added in v0.25.0

func UpdateFeed(ctx context.Context, id FeedID, updates map[string]any) error

UpdateFeed applies the given updates to a Feed.

func UpdateSubscriptions

func UpdateSubscriptions(
	ctx context.Context,
	subscriptions ...*Subscription,
) (map[SubscriptionID]*bulk.OperationResponse, error)

UpdateSubscriptions will bulk update the given subscriptions in Elasticsearch.

func UpdateUser

func UpdateUser(ctx context.Context, userID UserID, updates map[string]any) error

UpdateUser will apply the given updates to the user.

func UserToCtx

func UserToCtx(ctx context.Context, user *User) context.Context

UserToCtx stores a user in the context.

Types

type APIError

type APIError struct {
	// InternalError is the low-level, internal error.
	InternalError error `json:"internal_error,omitempty"`

	// StatusCode is the status code associated with the error. Usually, this is a HTTP status code.
	StatusCode int `json:"status_code"`

	// UserMessage represents a message that can be displayed to the user as the result of an action.
	UserMessage *UserMessage `json:"user_message,omitempty"`
}

APIError represents an error returned from any API within the service/application.

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) GetUserMessage

func (e *APIError) GetUserMessage() *UserMessage

GetUserMessage returns a UserMessage associated with the error. It will return an appropriate generic error message or warning where no message is already defined.

func (*APIError) HTTPStatus

func (e *APIError) HTTPStatus() int

HTTPStatus returns the status code of the API error.

func (*APIError) Unwrap

func (e *APIError) Unwrap() error

func (*APIError) WriteLog

func (e *APIError) WriteLog(ctx context.Context)

WriteLog writes the APIError to the log at the appropriate level.

type AddFeedSubscriptionRequest

type AddFeedSubscriptionRequest struct {
	// URL is the URL of the feed data.
	URL string `form:"url" json:"URL" validate:"required,url"`

	// Categories a list custom categories for the subscription. Combined with the feed's own categories.
	Categories []Category `form:"user_categories" json:"categories,omitempty"`

	// Nickname a custom name for the subscription. Overrides the feed name.
	Nickname *string `form:"user_nickname" json:"nickname,omitempty"`

	// SuggestedCategories is a list of suggested categories for the subscription.
	SuggestedCategories []Category `form:"-" json:"-"`
}

AddFeedSubscriptionRequest represents a request to create a subscription to a feed.

func GenerateRequestsFromOutlines

func GenerateRequestsFromOutlines(outlines ...opml.Outline) []*AddFeedSubscriptionRequest

func (*AddFeedSubscriptionRequest) GetNickname

func (r *AddFeedSubscriptionRequest) GetNickname() string

GetNickname returns the nickname chosen for the subscription.

func (*AddFeedSubscriptionRequest) GetURL

func (r *AddFeedSubscriptionRequest) GetURL() string

GetURL returns the (feed) URL for the request.

func (*AddFeedSubscriptionRequest) Sanitise

func (r *AddFeedSubscriptionRequest) Sanitise() error

Sanitise will sanitise the input values of the SubscriptionRequest.

func (*AddFeedSubscriptionRequest) Valid

func (r *AddFeedSubscriptionRequest) Valid() error

Valid returns a boolean indicating whether the SubscriptionRequest is valid, and any validation errors if applicable.

type AddFeedSubscriptionResult

type AddFeedSubscriptionResult struct {
	Error error `json:"error,omitempty"`

	// Feed represents a feed object.
	Feed *Feed `json:"feed,omitempty"`

	// Message represents a message that can be displayed to the user as the result of an action.
	Message *UserMessage `json:"message,omitempty"`

	// Request represents a request to create a subscription to a feed.
	Request AddFeedSubscriptionRequest `json:"request"`

	// Subscription represents any kind of subscription.
	Subscription *Subscription `json:"subscription,omitempty"`
}

AddFeedSubscriptionResult contains the result of adding/importing a subscription from a request.

type AddFeedsetRequest

type AddFeedsetRequest struct {
	Feedset []string `form:"feedset,unique" json:"feedset,omitempty"`
}

AddFeedsetRequest is a request from a user to add one or more feed sets as subscriptions.

func (*AddFeedsetRequest) Sanitise

func (r *AddFeedsetRequest) Sanitise() error

Sanitise will sanitise the input values of the SubscriptionRequest.

func (*AddFeedsetRequest) Valid

func (r *AddFeedsetRequest) Valid() error

Valid returns a boolean indicating whether the SubscriptionRequest is valid, and any validation errors if applicable.

type AddSubscriptionResult

type AddSubscriptionResult struct {
	Subscription *FeedSubscription
	Message      *UserMessage
}

AddSubscriptionResult represents the result of creating a new subscription.

type AddSubscriptionSearchFilterRequest

type AddSubscriptionSearchFilterRequest struct {
	// InputName is the name of the input in the form into which this filter should be added.
	InputName string `form:"subscriptions-input-name" json:"input_name"`

	// SubscriptionID is the unique ID of a subscription.
	SubscriptionID SubscriptionID `form:"subscription_id" json:"subscription_id" validate:"required,startswith=sub_"`

	// SubscriptionName is the nickname of the subscription.
	SubscriptionName string `form:"subscription_name" json:"subscription_name"`
}

AddSubscriptionSearchFilterRequest contains the data for adding a new subscription filter to a search request.

func (*AddSubscriptionSearchFilterRequest) Sanitise

Sanitise will sanitise the add subscription search filter request.

func (*AddSubscriptionSearchFilterRequest) Valid

Valid returns a boolean indicating whether the add subscription search filter data is valid.

type Article

type Article struct {
	// Content contains the full article content, when it has been fetched from the origin link.
	Content *string `json:"content,omitempty"`

	// Favorite indicates whether this subscription has been marked as a Favorite by the user.
	Favorite bool `json:"-"`

	// Item represents an individual item (e.g., an individual feed item).
	Item Item `json:"item"`

	// MarkArticleReadOnView indicates whether to automatically mark an article as read when viewed.
	MarkArticleReadOnView bool `json:"mark_article_read_on_view"`

	// ShowFullContent indicates whether the full article content should be fetched and displayed instead of any content from the feed item itself.
	ShowFullContent bool `json:"show_full_content"`

	// SourceType indicates what type of source the object came from.
	SourceType SourceType `json:"source_type"`

	// State tracks the state of an article.
	State ArticleState `json:"state"`

	// SubscriptionID is the unique ID of a subscription.
	SubscriptionID SubscriptionID `form:"subscription_id" json:"subscription_id" validate:"required,startswith=sub_"`
}

Article defines model for Article.

func (*Article) GetAuthors

func (a *Article) GetAuthors() []string

GetAuthors returns a slice of authors (if any) of the article.

func (*Article) GetCategories

func (a *Article) GetCategories(num int) Categories

GetCategories returns the categories of the article (if any).

func (*Article) GetContent

func (a *Article) GetContent() string

GetContent returns the main content of the article. This will be either the full content fetched remotely (if requested), the "content" field of the item (if not empty), or the description (if any).

func (*Article) GetDescription

func (a *Article) GetDescription() string

GetDescription returns the description of the article.

func (*Article) GetFeedID

func (a *Article) GetFeedID() FeedID

GetFeedID returns the ID of the feed the article belongs to.

func (*Article) GetFeedTitle

func (a *Article) GetFeedTitle() string

GetFeedTitle returns the title of the feed the article belongs to.

func (*Article) GetID

func (a *Article) GetID() string

GetID returns the article ID.

func (*Article) GetImage

func (a *Article) GetImage() *RemoteImage

GetImage returns the image associated with the article.

func (a *Article) GetLink() string

GetLink returns the URL pointing to the original article content.

func (*Article) GetObjectType

func (a *Article) GetObjectType() ObjectType

GetObjectType returns the type of the object, in this case, "article".

func (*Article) GetSubscriptionID

func (a *Article) GetSubscriptionID() SubscriptionID

GetSubscriptionID returns the ID of the user subscription the article belongs to.

func (*Article) GetTitle

func (a *Article) GetTitle() string

GetTitle returns the title of the article.

func (*Article) GetUpdatedDate

func (a *Article) GetUpdatedDate() time.Time

GetUpdatedDate returns the timestamp when the article was last updated (or created if no updates).

func (*Article) IsFavorite

func (a *Article) IsFavorite() bool

IsFavorite returns a boolean indicating whether the article has been favorited.

func (*Article) IsRemoteContent

func (a *Article) IsRemoteContent() bool

IsRemoteContent returns a boolean indicating whether the full content of the article should be shown.

func (*Article) IsUnread

func (a *Article) IsUnread() bool

IsUnread returns a boolean indicating whether the user has not read this article.

func (*Article) Valid

func (a *Article) Valid() error

Valid returns a boolean indicating if the article contains valid data (true). If it contains invalid data (false) a non-nil error is also returned which contains validation issues.

type ArticleArchive

type ArticleArchive struct {
	// Timestamp is when the document was created.
	Timestamp Timestamp `json:"@timestamp" validate:"required"`

	// Authors is a list of people (names, nicknames and/or emails) who "authored" the object content.
	Authors []string `json:"authors,omitempty"`

	// Categories is a list of categories that define a taxonomy for the feed or item.
	Categories []Category `json:"categories,omitempty" validate:"omitempty,unique"`

	// Content contains the item content.
	Content string `json:"content,omitempty"`

	// Contributors is a list of people (names, nicknames and/or emails) who "contributed" the object content.
	Contributors []string `json:"contributors,omitempty"`
	Copyright    string   `json:"copyright,omitempty"`

	// Description is a short summary or description of the feed or item.
	Description *string `json:"description,omitempty"`

	// ExtensionData contains the embedded extension data.
	ExtensionData *ArticleArchive_ExtensionData `json:"extension_data,omitempty"`

	// ExtensionType is the type of extension for this item.
	ExtensionType *ArticleArchiveExtensionType `json:"extension_type,omitempty"`

	// FeedID is the unique ID of a feed.
	FeedID FeedID `form:"feed_id" json:"feed_id" validate:"required,startswith=feed_"`

	// FeedTitle is the title of the feed to which this item belongs.
	FeedTitle string `json:"feed_title" validate:"required"`

	// Image contains details about a remote image.
	Image *RemoteImage `json:"image,omitempty"`

	// ItemID is the unique ID of an item.
	ItemID   ItemID `form:"item_id" json:"item_id" validate:"required,startswith=item_"`
	Language string `json:"language,omitempty"`

	// Published is the datetime at which the feed or item was published.
	Published time.Time `json:"published"`

	// SourceType indicates what type of source the object came from.
	SourceType SourceType `json:"source_type"`

	// SubscriptionID is the unique ID of a subscription.
	SubscriptionID SubscriptionID `form:"subscription_id" json:"subscription_id" validate:"required,startswith=sub_"`

	// Title is the title of the feed or item.
	Title string `json:"title"`

	// Updated is the datetime at which the feed or item was updated.
	Updated time.Time `json:"updated,omitempty"`

	// URL is the URL to the webpage for the feed or item. For a feed, this is most likely the webpage the feed is sourced from. For an item, this is most likely the webpage containing the full item contents.
	URL string `json:"url,omitempty" validate:"omitempty,url"`

	// UserID is the unique ID of a user.
	UserID UserID `form:"user_id" json:"user_id" validate:"required,startswith=user_"`
}

ArticleArchive defines model for ArticleArchive.

func NewArchivedArticle

func NewArchivedArticle(userID UserID, subscriptionID SubscriptionID, item *Item) (*ArticleArchive, error)

NewArchivedArticle creates a new archived article for long-term storage.

type ArticleArchiveExtensionType added in v0.61.0

type ArticleArchiveExtensionType string

ArticleArchiveExtensionType is the type of extension for this item.

const (
	ArticleArchiveExtensionTypeYoutube ArticleArchiveExtensionType = "youtube"
)

Defines values for ArticleArchiveExtensionType.

func (ArticleArchiveExtensionType) Valid added in v0.79.0

Valid indicates whether the value is a known member of the ArticleArchiveExtensionType enum.

type ArticleArchive_ExtensionData added in v0.61.0

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

ArticleArchive_ExtensionData contains the embedded extension data.

func (ArticleArchive_ExtensionData) AsItemExtensionYoutube added in v0.61.0

func (t ArticleArchive_ExtensionData) AsItemExtensionYoutube() (ItemExtensionYoutube, error)

AsItemExtensionYoutube returns the union data inside the ArticleArchive_ExtensionData as a ItemExtensionYoutube

func (*ArticleArchive_ExtensionData) FromItemExtensionYoutube added in v0.61.0

func (t *ArticleArchive_ExtensionData) FromItemExtensionYoutube(v ItemExtensionYoutube) error

FromItemExtensionYoutube overwrites any union data inside the ArticleArchive_ExtensionData as the provided ItemExtensionYoutube

func (ArticleArchive_ExtensionData) MarshalJSON added in v0.61.0

func (t ArticleArchive_ExtensionData) MarshalJSON() ([]byte, error)

func (*ArticleArchive_ExtensionData) MergeItemExtensionYoutube added in v0.61.0

func (t *ArticleArchive_ExtensionData) MergeItemExtensionYoutube(v ItemExtensionYoutube) error

MergeItemExtensionYoutube performs a merge with any union data inside the ArticleArchive_ExtensionData, using the provided ItemExtensionYoutube

func (*ArticleArchive_ExtensionData) UnmarshalJSON added in v0.61.0

func (t *ArticleArchive_ExtensionData) UnmarshalJSON(b []byte) error

type ArticleMetadata

type ArticleMetadata struct {
	// SourceType indicates what type of source the object came from.
	SourceType SourceType `json:"source_type"`

	// State tracks the state of an article.
	State ArticleState `json:"state"`

	// SubscriptionID is the unique ID of a subscription.
	SubscriptionID SubscriptionID `form:"subscription_id" json:"subscription_id" validate:"required,startswith=sub_"`
}

ArticleMetadata contains the stored data that represents an article.

type ArticleSettings

type ArticleSettings struct {
	// MarkArticleReadOnView indicates whether to automatically mark an article as read when viewed.
	MarkArticleReadOnView bool `json:"mark_article_read_on_view"`

	// ShowFullContent indicates whether the full article content should be fetched and displayed instead of any content from the feed item itself.
	ShowFullContent bool `json:"show_full_content"`
}

ArticleSettings contains settings related to the display of the article.

type ArticleState

type ArticleState struct {
	// Read indicates whether the object has been read (true) or is unread (false).
	Read bool `json:"read"`

	// UpdatedAt records when the object was last updated in the database.
	UpdatedAt UpdatedAt `json:"updated_at,omitempty" validate:"omitnil"`
}

ArticleState tracks the state of an article.

func (*ArticleState) MarkRead

func (s *ArticleState) MarkRead(markedAt time.Time)

MarkRead will set the article state to read.

func (*ArticleState) MarkUnread

func (s *ArticleState) MarkUnread(markedAt time.Time)

MarkUnread will set the article state to unread.

type Articles

type Articles []*Article

Articles is a slices of Article objects.

func FindSimilarArticles

func FindSimilarArticles(ctx context.Context, count int, itemIDs ...ItemID) (Articles, error)

FindSimilarArticles performs a "more like this" search to find other Articles that are similar to the Items with the given IDs.

func GenerateArticles

func GenerateArticles(ctx context.Context, items Items) (Articles, error)

GenerateArticles takes a slice of items and creates articles from them, grabbing the necessary data from the user object.

func GetArticles

func GetArticles(ctx context.Context, itemIDs ...ItemID) (Articles, error)

GetArticles generates Article objects from the Items with the given IDs.

func (Articles) FilterByView added in v0.26.0

func (a Articles) FilterByView(view View) Articles

FilterByView returns a slice containing the subscription which match the given view state.

func (Articles) GetCategoryCounts

func (a Articles) GetCategoryCounts() CategoryCounts

GetCategoryCounts returns a count of the occurrence of a Category across all the Articles in the slice.

func (Articles) GetFeedIDs

func (a Articles) GetFeedIDs() []FeedID

GetFeedIDs retrieves the feed ids for all articles in the slice.

func (Articles) GetIDs

func (a Articles) GetIDs() []ItemID

GetIDs retrieves the item ids for all articles in the slice.

func (Articles) GetSubscriptionIDs

func (a Articles) GetSubscriptionIDs() []SubscriptionID

GetSubscriptionIDs retrieves the subscription ids for all articles in the slice.

type Categories

type Categories []Category

Categories is a slice of categories.

func (Categories) HasCategory

func (c Categories) HasCategory(category Category) bool

HasCategory is a convienience function to check if the given category is in the slice of categories.

type Category

type Category = string

Category represents a taxonomy applied to an object.

func GetArticleTopCategories

func GetArticleTopCategories(ctx context.Context, searchQuery query.Option) ([]Category, error)

GetArticleTopCategories performs an aggregation to return the top Item categories across the given Feeds.

type CategoryCount

type CategoryCount struct {
	// Category represents a taxonomy applied to an object.
	Category Category `json:"category"`
	Count    int      `json:"count"`
}

CategoryCount holds a category and the count of its occurence. The count will be contextual. i.e., across subscriptions, items, etc.

type CategoryCounts

type CategoryCounts []CategoryCount

CategoryCounts is a slice of Categories and their counts.

func GetCategoriesForSubscriptions added in v0.27.0

func GetCategoriesForSubscriptions(ctx context.Context, subscriptionIDs ...SubscriptionID) (CategoryCounts, error)

func GetCategoryCounts

func GetCategoryCounts(subscriptions ...*Subscription) CategoryCounts

GetCategoryCounts returns a count of the occurrence of a Category across all the Subscriptions.

func GetSubscriptionCategories added in v0.27.0

func GetSubscriptionCategories(ctx context.Context, subscriptions Subscriptions) (CategoryCounts, error)

GetSubscriptionCategories retrieves a map of categories from user subscriptions by count.

func GetTopCategoriesForItems added in v0.27.0

func GetTopCategoriesForItems(ctx context.Context, itemsQueries ...query.Option) (CategoryCounts, error)

func (CategoryCounts) GetCategories added in v0.55.0

func (c CategoryCounts) GetCategories() []Category

func (CategoryCounts) Limit added in v0.55.0

func (c CategoryCounts) Limit(count int) CategoryCounts

Limit returns the n top Categories from the list of CategoryCounts.

func (CategoryCounts) Sort

func (c CategoryCounts) Sort()

Sort will sort the list of CategoryCounts by the count values.

type CategoryFilters added in v0.27.0

type CategoryFilters struct {
	Categories CategoryCounts `json:"categories"`

	// Filters contains filters for altering the display of objects.
	Filters ListFilters `json:"filters" validate:"required"`
	Path    string      `json:"path"`
}

CategoryFilters contains categories that can be used for filtering.

type ChangePasswordRequest

type ChangePasswordRequest struct {
	// ConfirmNewPassword is the new password (again), used for confirmation.
	ConfirmNewPassword *string `form:"confirm_new_password" json:"confirm_new_password,omitempty" validate:"required"`

	// NewPassword is the new password.
	NewPassword string `form:"new_password" json:"new_password" validate:"required,eqfield=ConfirmNewPassword"`
}

ChangePasswordRequest contains details for changing a user password.

func (*ChangePasswordRequest) Sanitise

func (r *ChangePasswordRequest) Sanitise() error

Sanitise will sanitise the user input for a ChangePasswordRequest.

func (*ChangePasswordRequest) Valid

func (r *ChangePasswordRequest) Valid() error

Valid returns a boolean indicating whether the ChangePasswordRequest contains valid data.

type Count

type Count = int

Count is the count of items to retrieve with a request.

type CreatedAt

type CreatedAt = time.Time

CreatedAt records when the object was created in the database.

type DeletedAt

type DeletedAt = time.Time

DeletedAt records when the object was deleted.

type EditEmailSubscriptionRequest added in v0.26.0

type EditEmailSubscriptionRequest struct {
	Customisation *SubscriptionCustomisation `form:"customisation" json:"customisation,omitempty"`
	Settings      *SubscriptionSettings      `form:"settings" json:"settings,omitempty"`

	// SubscriptionID is the unique ID of a subscription.
	SubscriptionID SubscriptionID `form:"subscription_id" json:"subscription_id" validate:"required,startswith=sub_"`

	// SuggestedCategories is a list of suggested categories for the subscription.
	SuggestedCategories []Category `form:"-" json:"-"`
}

EditEmailSubscriptionRequest represents a request to create an email subscription.

func (*EditEmailSubscriptionRequest) Sanitise added in v0.26.0

func (r *EditEmailSubscriptionRequest) Sanitise() error

Sanitise will sanitise the input values of the SubscriptionRequest.

func (*EditEmailSubscriptionRequest) Valid added in v0.26.0

Valid returns a boolean indicating whether the SubscriptionRequest is valid, and any validation errors if applicable.

type EditFeedSubscriptionRequest added in v0.54.0

type EditFeedSubscriptionRequest struct {
	// ArticleFilters holds filters to apply to the articles within a subscription.
	ArticleFilters *SubscriptionArticleFilters `form:"article_filters" json:"article_filters"`
	Customisation  *SubscriptionCustomisation  `form:"customisation" json:"customisation,omitempty"`
	Settings       *SubscriptionSettings       `form:"settings" json:"settings,omitempty"`

	// SubscriptionID is the unique ID of a subscription.
	SubscriptionID SubscriptionID `form:"subscription_id" json:"subscription_id" validate:"required,startswith=sub_"`

	// SuggestedCategories is a list of suggested categories for the subscription.
	SuggestedCategories []Category `form:"-" json:"-"`
}

EditFeedSubscriptionRequest is the request details for editing a feed subscription.

func (*EditFeedSubscriptionRequest) Sanitise added in v0.54.0

func (s *EditFeedSubscriptionRequest) Sanitise() error

func (*EditFeedSubscriptionRequest) Valid added in v0.54.0

type EditUserRequest

type EditUserRequest = UserCustomisation

EditUserRequest contains account fields that a user can customize.

func (*EditUserRequest) Sanitise

func (s *EditUserRequest) Sanitise() error

Sanitise will sanitise the user input for a SubscriptionCustomisation.

func (*EditUserRequest) Valid

func (s *EditUserRequest) Valid() error

Valid returns a boolean indicating if the Subscription contains valid data (true). If it contains invalid data (false) a non-nil error is also returned which contains validation issues.

type ElementID added in v0.35.0

type ElementID string

ID represents an id attribute in a HTML element.

func (ElementID) String added in v0.35.0

func (a ElementID) String() string

String returns the id attribute as a string.

func (ElementID) Target added in v0.35.0

func (a ElementID) Target() string

Target returns the id attribute as a target (i.e., for htmx requests). This is the base id string with a "#" prefix.

type Email added in v0.25.0

type Email interface {
	GetID() string
	Timestamp() time.Time
	GetSubject() string
	GetBody() string
	GetFrom() *mail.Address
}

type EmailSenderID added in v0.25.0

type EmailSenderID = string

EmailSenderID is an email address that sends emails.

type EmailSubscription added in v0.25.0

type EmailSubscription struct {
	// ArticleFilters holds filters to apply to the articles within a subscription.
	ArticleFilters *SubscriptionArticleFilters `form:"article_filters" json:"article_filters"`

	// ArticleStates contains the states of items marked explicitly as read/unread/saved by the user.
	ArticleStates map[ItemID]ArticleState `json:"article_states" validate:"required"`

	// EmailSenderID is an email address that sends emails.
	EmailSenderID EmailSenderID `form:"email_sender_id" json:"email_sender_id" validate:"required,email"`

	// FeedID is the unique ID of a feed.
	FeedID FeedID `form:"feed_id" json:"feed_id" validate:"required,startswith=feed_"`
}

EmailSubscription is a subscription to an email newsletter source.

func (*EmailSubscription) Valid added in v0.25.0

func (s *EmailSubscription) Valid() error

Valid returns a non-nil error if the EmailSubscription contains invalid data.

type FavoriteArticleRequest added in v0.31.0

type FavoriteArticleRequest struct {
	// ItemID is the unique ID of an item.
	ItemID ItemID `form:"item_id" json:"item_id" validate:"required,startswith=item_"`

	// SubscriptionID is the unique ID of a subscription.
	SubscriptionID SubscriptionID `form:"subscription_id" json:"subscription_id" validate:"required,startswith=sub_"`
}

FavoriteArticleRequest contains parameters for favoriting an article.

func (*FavoriteArticleRequest) Sanitise added in v0.31.0

func (r *FavoriteArticleRequest) Sanitise() error

func (*FavoriteArticleRequest) Valid added in v0.31.0

func (r *FavoriteArticleRequest) Valid() error

type FavoriteSubscriptionRequest added in v0.31.0

type FavoriteSubscriptionRequest struct {
	// SubscriptionID is the unique ID of a subscription.
	SubscriptionID SubscriptionID `form:"subscription_id" json:"subscription_id" validate:"required,startswith=sub_"`
}

FavoriteSubscriptionRequest contains parameters for favoriting a subscription.

func (*FavoriteSubscriptionRequest) Sanitise added in v0.31.0

func (s *FavoriteSubscriptionRequest) Sanitise() error

Sanitise will sanitise the FavoriteSubscriptionsRequest, ensuring it contains valid field values.

func (*FavoriteSubscriptionRequest) Valid added in v0.31.0

Valid checks that the FavoriteSubscriptionsRequest contains valid data.

type Feed

type Feed struct {
	// Authors is a list of people (names, nicknames and/or emails) who "authored" the object content.
	Authors []string `json:"authors,omitempty"`

	// Categories is a list of categories that define a taxonomy for the feed or item.
	Categories []Category `json:"categories,omitempty" validate:"omitempty,unique"`

	// Contributors is a list of people (names, nicknames and/or emails) who "contributed" the object content.
	Contributors []string `json:"contributors,omitempty"`
	Copyright    string   `json:"copyright,omitempty"`

	// CreatedAt records when the object was created in the database.
	CreatedAt CreatedAt `json:"created_at" validate:"required"`

	// Description is a short summary or description of the feed or item.
	Description *string `json:"description,omitempty"`

	// FeedID is the unique ID of a feed.
	FeedID FeedID `form:"feed_id" json:"feed_id" validate:"required,startswith=feed_"`

	// Image contains details about a remote image.
	Image *RemoteImage `json:"image,omitempty"`

	// Items contains the list of items in the feed.
	Items    []Item `json:"-"`
	Language string `json:"language,omitempty"`

	// LastFetched indicates when an object was last fetched.
	LastFetched LastFetched `json:"last_fetched,omitempty"`

	// Published is the datetime at which the feed or item was published.
	Published time.Time `json:"published"`

	// SourceType indicates what type of source the object came from.
	SourceType SourceType `json:"source_type"`

	// SourceURLs is a list of URLs that point to the feed source. These might be either the website corresponding to the feed or the
	SourceURLs []URL `json:"source_urls" validate:"required,dive,url"`

	// Title is the title of the feed or item.
	Title string `json:"title"`

	// UpdateInterval indicates how often the feed is updated. Where a feed does not supply an actual update interval, this value will be derived from the median update interval between published items.
	UpdateInterval int64 `json:"update_interval"`

	// Updated is the datetime at which the feed or item was updated.
	Updated time.Time `json:"updated,omitempty"`

	// URL is the URL to the webpage for the feed or item. For a feed, this is most likely the webpage the feed is sourced from. For an item, this is most likely the webpage containing the full item contents.
	URL string `json:"url,omitempty" validate:"omitempty,url"`
}

Feed defines model for Feed.

func GetFeedByID added in v0.25.0

func GetFeedByID(ctx context.Context, id FeedID) (*Feed, error)

GetFeedByID fetches the given Feed by its id.

func NewFeedFromURL

func NewFeedFromURL(ctx context.Context, url string, id FeedID, validate bool) (*Feed, error)

NewFeedFromURL generates a new Feed object from the given URL. If there is a problem generating the object, a non-nil error is returned.

func NewSyndicationFeed added in v0.25.0

func NewSyndicationFeed(ctx context.Context, url string, id FeedID, source *feeds.Feed) *Feed

NewSyndicationFeed converts the raw types.FeedSource into a Feed object.

func (*Feed) GetAuthors

func (f *Feed) GetAuthors() []string

GetAuthors returns the feed authors, if any.

func (*Feed) GetCategories

func (f *Feed) GetCategories() []string

GetCategories returns the slice of categories assigned to the feed, if any.

func (*Feed) GetContributors

func (f *Feed) GetContributors() []string

GetContributors returns the feed contributors, if any.

func (*Feed) GetDescription

func (f *Feed) GetDescription() string

GetDescription returns the feed description, if any.

func (*Feed) GetID

func (f *Feed) GetID() FeedID

GetID returns the ID of the Feed.

func (*Feed) GetImage

func (f *Feed) GetImage() *RemoteImage

GetImage returns an image object that can visually represent the feed.

func (*Feed) GetItems

func (f *Feed) GetItems() Items

GetItems returns a slice of the currently published items in the feed.

func (*Feed) GetLanguage

func (f *Feed) GetLanguage() string

GetLanguage returns the language tag of the feed, if any.

func (f *Feed) GetLink() URL

GetLink returns the URL of the website that publishes and/or is the owner the feed.

func (*Feed) GetRights

func (f *Feed) GetRights() string

GetRights returns the rights or copyright of the feed content, if any.

func (*Feed) GetSourceURLs

func (f *Feed) GetSourceURLs() []URL

GetSourceURLs returns all discovered source URLs of the feed (i.e., URLs that point to the feed itself).

func (*Feed) GetTimestamp

func (f *Feed) GetTimestamp() time.Time

GetTimestamp returns a timestamp indicating when the feed was last updated. This will be either, the updated timestamp in the feed, or, the published timestamp in the feed, or the last fetched timestamp, whichever is found and is a valid value, in that order.

func (*Feed) GetTitle

func (f *Feed) GetTitle() string

GetTitle returns the feed title.

func (*Feed) SetUpdateInterval added in v0.24.0

func (f *Feed) SetUpdateInterval(ctx context.Context) error

SetUpdateInterval will set the update interval of the feed. It fetches the feed details from the source and determines a reasonable update interval. In the case of errors, a default interval will be set.

type FeedID

type FeedID = string

FeedID is the unique ID of a feed.

type FeedSorting

type FeedSorting struct {
	Updated   string `json:"updated"`
	Published string `json:"published"`
	FeedID    string `json:"feed_id"`
}

FeedSorting contains the sort options for sorting item search results.

func (*FeedSorting) SortCombinationsCaster

func (s *FeedSorting) SortCombinationsCaster() *estypes.SortCombinations

SortCombinationsCaster is required to allow FeedSorting to be used as Elasticsearch sort values.

type FeedStatus added in v0.46.0

type FeedStatus struct {
	// FeedID is the unique ID of a feed.
	FeedID FeedID `form:"feed_id" json:"feed_id" validate:"required,startswith=feed_"`

	// StatusCode is the HTTP status code returned when fetching.
	StatusCode int `json:"status_code"`

	// StatusMessage is a message associated with the status code.
	StatusMessage *string `json:"status_message,omitempty"`

	// Timestamp is when the document was created.
	Timestamp Timestamp `json:"@timestamp" validate:"required"`

	// URL is a URL.
	URL URL `json:"url" validate:"omitempty,url"`
}

FeedStatus represents the status of fetching the feed.

func (*FeedStatus) GetID added in v0.46.0

func (s *FeedStatus) GetID() string

GetID retrieves (generates) a unique ID for a FeedStatus object.

type FeedSubscription

type FeedSubscription struct {
	// ArticleFilters holds filters to apply to the articles within a subscription.
	ArticleFilters *SubscriptionArticleFilters `form:"article_filters" json:"article_filters"`

	// ArticleStates contains the states of items marked explicitly as read/unread/saved by the user.
	ArticleStates map[ItemID]ArticleState `json:"article_states" validate:"required"`

	// FeedID is the unique ID of a feed.
	FeedID FeedID `form:"feed_id" json:"feed_id" validate:"required,startswith=feed_"`

	// URL is a URL pointing to the original website that publishes the feed.
	URL string `json:"url" validate:"required,url"`
}

FeedSubscription represents a feed a user has subscribed to.

func (*FeedSubscription) GetFeedID

func (s *FeedSubscription) GetFeedID() FeedID

GetFeedID returns the feed ID.

func (*FeedSubscription) Valid

func (s *FeedSubscription) Valid() error

Valid returns a boolean indicating if the Subscription contains valid data (true). If it contains invalid data (false) a non-nil error is also returned which contains validation issues.

type Feeds

type Feeds []*Feed

Feeds is a slice of Feed objects.

func (Feeds) FindByID

func (f Feeds) FindByID(id FeedID) *Feed

FindByID will return the feed with the given ID.

func (Feeds) GetIDs

func (f Feeds) GetIDs() []FeedID

GetIDs returns the Feed IDs for the Feeds.

type FileDetails added in v0.49.0

type FileDetails struct {
	// File is the path in an embedded FS to the file.
	File string `json:"file" toml:"file" validate:"required,filepath"`

	// Path is the relative URL path from where this document should be served.
	Path string `json:"path" toml:"path" validate:"required,filepath"`
}

FileDetails contains a mapping of a file in an embedded FS to the URL path it is served from.

type FileIndex added in v0.49.0

type FileIndex struct {
	// Files is a list of details for files.
	Files []FileDetails `json:"files,omitempty" toml:"file"`

	// UpdatedAt indicates when the index was last updated.
	UpdatedAt *time.Time `json:"updated_at,omitempty" toml:"updated_at"`
}

FileIndex contains a listing of files in a directory of an embedded FS.

type FileUpload

type FileUpload struct {
	// Data is the file data/content.
	Data multipart.File `json:"data" validate:"required"`

	// Header is the mime header information of the file.
	Header *multipart.FileHeader `json:"header" validate:"required"`
}

FileUpload represents a file upload by a user.

func (*FileUpload) GetSize

func (f *FileUpload) GetSize() int64

GetSize returns the file size.

func (*FileUpload) ParseMimetype

func (f *FileUpload) ParseMimetype() (string, error)

ParseMimetype attempts to parse and return the mimetype of the file from its mime header.

func (*FileUpload) Valid

func (f *FileUpload) Valid() error

Valid will return a non-nill error containing details of any validation issues with the file upload data. Otherwise, a nil error is returned if the data is valid.

type Filters

type Filters interface {
	Valid() error
	GetSort() Sort
	GetCount() int
	GetView() View
	GetCategories() Categories
	Values() map[string]any
	QueryString() string
}

Filters represents either Subscription or Article filters.

type GetSubscriptionsSuggestionRequest

type GetSubscriptionsSuggestionRequest struct {
	// Text is a string that should match a subscription.
	Text string `form:"subscription-text" json:"text"`
}

GetSubscriptionsSuggestionRequest contains the data for finding matching subscriptions as suggestion results.

func (*GetSubscriptionsSuggestionRequest) Sanitise

Sanitise will sanitise the add subscription search filter request.

func (*GetSubscriptionsSuggestionRequest) Valid

Valid returns a boolean indicating whether the add subscription search filter data is valid.

type GroupSubscription

type GroupSubscription struct {
	// ArticleFilters holds filters to apply to the articles within a subscription.
	ArticleFilters *SubscriptionArticleFilters `form:"article_filters" json:"article_filters"`

	// Subscriptions is the list of subscription IDs belonging to the group.
	Subscriptions []SubscriptionID `form:"subscriptions" json:"subscriptions" validate:"required,dive,startswith=sub_"`
}

GroupSubscription represents a subscription that combines other subscriptions.

func (*GroupSubscription) Valid

func (s *GroupSubscription) Valid() error

Valid returns a boolean indicating if the Subscription contains valid data (true). If it contains invalid data (false) a non-nil error is also returned which contains validation issues.

type GroupSubscriptionRequest

type GroupSubscriptionRequest struct {
	// ArticleFilters holds filters to apply to the articles within a subscription.
	ArticleFilters *SubscriptionArticleFilters `form:"article_filters" json:"article_filters"`
	Customisation  *SubscriptionCustomisation  `form:"customisation" json:"customisation,omitempty"`
	Settings       *SubscriptionSettings       `form:"settings" json:"settings,omitempty"`

	// SubscriptionID will be a subscription ID if the user is editing an existing group subscription.
	SubscriptionID *SubscriptionID `form:"subscription_id" json:"-" validate:"omitempty,startswith=sub_"`

	// Subscriptions contains details of the subscriptions in the group.
	Subscriptions map[SubscriptionID]string `form:"subscriptions" json:"subscriptions" validate:"required"`

	// SuggestedCategories is a list of suggested categories for the subscription.
	SuggestedCategories []Category `form:"-" json:"-"`
}

GroupSubscriptionRequest represents a request to create a group subscription.

func NewGroupSubscriptionRequest added in v0.54.0

func NewGroupSubscriptionRequest(suggestedCategories []Category) *GroupSubscriptionRequest

func (*GroupSubscriptionRequest) Sanitise

func (r *GroupSubscriptionRequest) Sanitise() error

func (*GroupSubscriptionRequest) Valid

func (r *GroupSubscriptionRequest) Valid() error

type GroupSubscriptionSuggestionRequest added in v0.54.0

type GroupSubscriptionSuggestionRequest struct {
	// IgnoredSubscriptions contains subscriptions that can be ignored and not suggested.
	IgnoredSubscriptions map[SubscriptionID]string `form:"subscriptions" json:"ignored_subscriptions,omitempty"`

	// Text is the text of a subscription to match for a suggestion.
	Text string `form:"text" json:"text"`
}

GroupSubscriptionSuggestionRequest contains details for suggesting a subscription to add to a group.

func (*GroupSubscriptionSuggestionRequest) Sanitise added in v0.54.0

func (*GroupSubscriptionSuggestionRequest) Valid added in v0.54.0

type HomeResponse added in v0.37.0

type HomeResponse struct {
	LatestArticles Articles                   `json:"latest_articles,omitempty"`
	RareCategories CategoryCounts             `json:"rare_categories,omitempty"`
	Subscriptions  Subscriptions              `json:"subscriptions,omitempty"`
	TopCategories  map[CategoryCount]Articles `json:"top_categories,omitempty"`
}

HomeResponse contains the data for displaying the home page.

type Item

type Item struct {
	// Timestamp is when the document was created.
	Timestamp Timestamp `json:"@timestamp" validate:"required"`

	// Authors is a list of people (names, nicknames and/or emails) who "authored" the object content.
	Authors []string `json:"authors,omitempty"`

	// Categories is a list of categories that define a taxonomy for the feed or item.
	Categories []Category `json:"categories,omitempty" validate:"omitempty,unique"`

	// Content contains the item content.
	Content string `json:"content,omitempty"`

	// Contributors is a list of people (names, nicknames and/or emails) who "contributed" the object content.
	Contributors []string `json:"contributors,omitempty"`
	Copyright    string   `json:"copyright,omitempty"`

	// Description is a short summary or description of the feed or item.
	Description *string `json:"description,omitempty"`

	// ExtensionData contains the embedded extension data.
	ExtensionData *Item_ExtensionData `json:"extension_data,omitempty"`

	// ExtensionType is the type of extension for this item.
	ExtensionType *ItemExtensionType `json:"extension_type,omitempty"`

	// FeedID is the unique ID of a feed.
	FeedID FeedID `form:"feed_id" json:"feed_id" validate:"required,startswith=feed_"`

	// FeedTitle is the title of the feed to which this item belongs.
	FeedTitle string `json:"feed_title" validate:"required"`

	// Image contains details about a remote image.
	Image *RemoteImage `json:"image,omitempty"`

	// ItemID is the unique ID of an item.
	ItemID   ItemID `form:"item_id" json:"item_id" validate:"required,startswith=item_"`
	Language string `json:"language,omitempty"`

	// Published is the datetime at which the feed or item was published.
	Published time.Time `json:"published"`

	// SourceType indicates what type of source the object came from.
	SourceType SourceType `json:"source_type"`

	// Title is the title of the feed or item.
	Title string `json:"title"`

	// Updated is the datetime at which the feed or item was updated.
	Updated time.Time `json:"updated,omitempty"`

	// URL is the URL to the webpage for the feed or item. For a feed, this is most likely the webpage the feed is sourced from. For an item, this is most likely the webpage containing the full item contents.
	URL string `json:"url,omitempty" validate:"omitempty,url"`
}

Item defines model for Item.

func NewEmailItem added in v0.25.0

func NewEmailItem(email Email, subscription *Subscription) *Item

NewEmailItem generates a new Item from an email.

func NewFeedItem added in v0.25.0

func NewFeedItem(ctx context.Context, source *feeds.Item, feed *Feed) *Item

NewFeedItem generates an Item from the underlying feed data.

func (*Item) GetAuthors

func (i *Item) GetAuthors() []string

GetAuthors returns a slice of the item's authors, if any.

func (*Item) GetCategories

func (i *Item) GetCategories() []string

GetCategories returns a slice of the item's categories, if any.

func (*Item) GetContent

func (i *Item) GetContent() string

GetContent returns the full item content, if set.

func (*Item) GetContributors

func (i *Item) GetContributors() []string

GetContributors returns a slice of the item's contributors, if any.

func (*Item) GetDescription

func (i *Item) GetDescription() string

GetDescription returns the summary of the item content, if any.

func (*Item) GetFeedID

func (i *Item) GetFeedID() FeedID

GetFeedID returns the ID of the feed the item belongs to.

func (*Item) GetID

func (i *Item) GetID() ItemID

GetID returns the item ID.

func (*Item) GetImage

func (i *Item) GetImage() *RemoteImage

GetImage returns an image that can represent the item, if any.

func (*Item) GetLanguage

func (i *Item) GetLanguage() string

GetLanguage returns the language of the item, if set.

func (i *Item) GetLink() URL

GetLink returns the URL that should point to a page containing the full item content.

func (*Item) GetRights

func (i *Item) GetRights() string

GetRights returns the copyright associated with the item, if any.

func (*Item) GetTimestamp

func (i *Item) GetTimestamp() time.Time

GetTimestamp returns a timestamp indicating when the item was last updated. This will be either, the updated timestamp, or, the published timestamp, or the indexing timestamp, whichever is found and is a valid value, in that order.

func (*Item) GetTitle

func (i *Item) GetTitle() string

GetTitle returns the item's title.

func (*Item) IsNewer

func (i *Item) IsNewer(since time.Time) bool

IsNewer returns a boolean indicating whether this item has been updated or published after the given time and before now (to ignore potentially incorrect dates in the future).

type ItemExtensionType added in v0.61.0

type ItemExtensionType string

ItemExtensionType is the type of extension for this item.

const (
	ItemExtensionTypeYoutube ItemExtensionType = "youtube"
)

Defines values for ItemExtensionType.

func (ItemExtensionType) Valid added in v0.79.0

func (e ItemExtensionType) Valid() bool

Valid indicates whether the value is a known member of the ItemExtensionType enum.

type ItemExtensionYoutube added in v0.61.0

type ItemExtensionYoutube struct {
	// Height is the video height.
	Height *int `json:"height,omitempty"`

	// VideoId is the Youtube video ID for the video.
	VideoId string `json:"video_id"`

	// Width is the video width.
	Width *int `json:"width,omitempty"`
}

ItemExtensionYoutube is an item extension for Youtube videos.

type ItemID

type ItemID = string

ItemID is the unique ID of an item.

type ItemSorting

type ItemSorting struct {
	Updated   string `json:"updated"`
	Published string `json:"published"`
	ItemID    string `json:"item_id"`
}

ItemSorting contains the sort options for sorting item search results.

func (*ItemSorting) SortCombinationsCaster

func (s *ItemSorting) SortCombinationsCaster() *estypes.SortCombinations

SortCombinationsCaster is required to allow ItemSorting to be used as Elasticsearch sort values.

type ItemSource added in v0.27.0

type ItemSource interface {
	GetFeedID() FeedID
	GetMarkedReadAt() time.Time
	GetReadItems() []ItemID
	GetUnreadItems() []ItemID
	GetArticleFilters() SubscriptionArticleFilters
}

type Item_ExtensionData added in v0.61.0

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

Item_ExtensionData contains the embedded extension data.

func (Item_ExtensionData) AsItemExtensionYoutube added in v0.61.0

func (t Item_ExtensionData) AsItemExtensionYoutube() (ItemExtensionYoutube, error)

AsItemExtensionYoutube returns the union data inside the Item_ExtensionData as a ItemExtensionYoutube

func (*Item_ExtensionData) FromItemExtensionYoutube added in v0.61.0

func (t *Item_ExtensionData) FromItemExtensionYoutube(v ItemExtensionYoutube) error

FromItemExtensionYoutube overwrites any union data inside the Item_ExtensionData as the provided ItemExtensionYoutube

func (Item_ExtensionData) MarshalJSON added in v0.61.0

func (t Item_ExtensionData) MarshalJSON() ([]byte, error)

func (*Item_ExtensionData) MergeItemExtensionYoutube added in v0.61.0

func (t *Item_ExtensionData) MergeItemExtensionYoutube(v ItemExtensionYoutube) error

MergeItemExtensionYoutube performs a merge with any union data inside the Item_ExtensionData, using the provided ItemExtensionYoutube

func (*Item_ExtensionData) UnmarshalJSON added in v0.61.0

func (t *Item_ExtensionData) UnmarshalJSON(b []byte) error

type Items

type Items []Item

Items is a slice of items.

func (Items) FilterByFeed

func (i Items) FilterByFeed(feedID FeedID) Items

FilterByFeed filters items to ones which match the given feed ID.

func (Items) FilterSince

func (i Items) FilterSince(since time.Time) Items

FilterSince filters items to ones which are newer than the given timestamp.

func (Items) GetCategoryCounts

func (i Items) GetCategoryCounts() CategoryCounts

GetCategoryCounts returns a count of the occurrence of a Category across all the Items.

func (Items) GetFeedIDs

func (i Items) GetFeedIDs() []FeedID

GetFeedIDs retrieves a list of all FeedIDs from all items.

func (Items) GetIDs

func (i Items) GetIDs() []ItemID

GetIDs retrieves a list of all ItemIDs from all items.

func (Items) SortByTimestamp

func (i Items) SortByTimestamp() Items

SortByTimestamp sorts the items by their timestamps, in descending order.

type JobState

type JobState struct {
	JobData json.RawMessage `json:"job_data,omitempty"`

	// UpdatedAt records when the object was last updated in the database.
	UpdatedAt UpdatedAt `json:"updated_at,omitempty" validate:"omitnil"`
}

JobState represents the stored state of a scheduled job.

type LastFetched added in v0.46.0

type LastFetched = time.Time

LastFetched indicates when an object was last fetched.

type ListArticlesResponse

type ListArticlesResponse struct {
	Articles Articles `json:"articles"`

	// Filters contains filters for altering the display of objects.
	Filters ListFilters `json:"filters" validate:"required"`

	// Pagination contains data for paginating through results.
	Pagination   Pagination    `form:"pagination" json:"pagination" validate:"omitempty,url_encoded"`
	Subscription *Subscription `json:"subscription,omitempty"`
}

ListArticlesResponse contains the data retrieved and relevant for listing articles.

type ListFavoritesResponse added in v0.39.0

type ListFavoritesResponse struct {
	Articles      Articles      `json:"articles,omitempty"`
	Subscriptions Subscriptions `json:"subscriptions,omitempty"`
}

ListFavoritesResponse contains the data for displaying the favorites page.

type ListFilters

type ListFilters struct {
	// Categories is a list of categories.
	Categories []Category `form:"categories" json:"categories" validate:"omitnil,unique,dive,url_encoded"`

	// Count is the count of items to retrieve with a request.
	Count Count `form:"count" json:"count" validate:"gt=0,lt=20"`

	// OnlyFavorites indicates whether to filter by favorites only.
	OnlyFavorites bool `form:"only_favorites" json:"only_favorites" validate:"omitempty,boolean"`

	// Sort is how a list of objects is sorted.
	Sort Sort `form:"sort" json:"sort" validate:"required,oneof=newest_first oldest_first most_unread least_unread most_relevant"`

	// Subscriptions is a list of subscription IDs.
	Subscriptions []SubscriptionID `form:"subscriptions" json:"subscriptions" validate:"omitnil,dive,startswith=sub_"`

	// View The state of objects to view.
	View View `form:"view" json:"view" validate:"required,oneof=read unread all"`
}

ListFilters contains filters for altering the display of objects.

func NewListDisplayFilters

func NewListDisplayFilters() ListFilters

NewListDisplayFilters creates a new set of display filters with sensible defaults.

func PageFiltersFromCtx

func PageFiltersFromCtx(ctx context.Context, path string) *ListFilters

PageFiltersFromCtx retrieves the current page display filters from the context.

func (*ListFilters) GetCategories

func (f *ListFilters) GetCategories() Categories

GetCategories returns any category filters.

func (*ListFilters) GetCount

func (f *ListFilters) GetCount() int

GetCount returns the count value (encoded as a string in the filters) as an int.

func (*ListFilters) GetSort

func (f *ListFilters) GetSort() Sort

GetSort returns the Sort object for the Filters.

func (*ListFilters) GetSubscriptions

func (f *ListFilters) GetSubscriptions() []SubscriptionID

GetSubscriptions retrieves any subscription filters.

func (*ListFilters) GetView

func (f *ListFilters) GetView() View

GetView returns the view filter.

func (*ListFilters) QueryParams

func (f *ListFilters) QueryParams() url.Values

QueryParams converts the filters into query parameters.

func (*ListFilters) QueryString

func (f *ListFilters) QueryString() string

QueryString converts the filters into a string that can be appended to a URL to represent the filters.

func (*ListFilters) Sanitise

func (f *ListFilters) Sanitise() error

Sanitise performs sanitisation of the filter values to ensure correctness.

func (*ListFilters) Valid

func (f *ListFilters) Valid() error

Valid will return a boolean indicating whether the filters are valid and a non-nil error with details if not.

func (*ListFilters) Values

func (f *ListFilters) Values() map[string]any

Values converts the filters into a map[string]string object, that can be further manipulated before being (most likely) used as the value of hx-vals in a HTMX request.

type ListRequest

type ListRequest struct {
	// Filters contains filters for altering the display of objects.
	Filters ListFilters `json:"filters" validate:"required"`

	// Pagination contains data for paginating through results.
	Pagination *Pagination `form:"pagination" json:"pagination,omitempty" validate:"omitempty,url_encoded"`

	// Query is an additional query to apply for this request.
	Query query.Option `json:"query,omitempty"`
}

ListRequest contains the parameters needed for listing subscriptions or articles.

func (*ListRequest) Valid

func (r *ListRequest) Valid() error

Valid will return an error if the request object does not pass validation.

type ListSubscriptionCategoriesRequest added in v0.27.0

type ListSubscriptionCategoriesRequest struct {
	// Subscriptions is a list of subscription IDs.
	Subscriptions []SubscriptionID `form:"displayed_subscriptions" json:"subscriptions,omitempty" validate:"omitempty,dive,startswith=sub_"`
}

ListSubscriptionCategoriesRequest contains data for listing categories for a list of subscriptions.

func (*ListSubscriptionCategoriesRequest) Sanitise added in v0.27.0

func (*ListSubscriptionCategoriesRequest) Valid added in v0.27.0

type ListSubscriptionsResponse

type ListSubscriptionsResponse struct {
	// Filters contains filters for altering the display of objects.
	Filters ListFilters `json:"filters" validate:"required"`

	// Pagination contains data for paginating through results.
	Pagination    Pagination    `form:"pagination" json:"pagination" validate:"omitempty,url_encoded"`
	Subscriptions Subscriptions `json:"subscriptions"`
}

ListSubscriptionsResponse contains the data retrieved and relevant for listing subscriptions.

type Mark

type Mark string

Mark applies the given mark action to objects.

const (
	MarkRead   Mark = "read"
	MarkUnread Mark = "unread"
)

Defines values for Mark.

func (Mark) Valid added in v0.79.0

func (e Mark) Valid() bool

Valid indicates whether the value is a known member of the Mark enum.

type MarkArticleRequest added in v0.28.0

type MarkArticleRequest struct {
	// ItemID is the unique ID of an item.
	ItemID ItemID `form:"item_id" json:"item_id" validate:"required,startswith=item_"`

	// Mark applies the given mark action to objects.
	Mark Mark `form:"mark" json:"mark" validate:"oneof=read unread"`

	// SubscriptionID is the unique ID of a subscription.
	SubscriptionID SubscriptionID `form:"subscription_id" json:"subscription_id" validate:"required,startswith=sub_"`
}

MarkArticleRequest contains parameters for marking an article.

func (*MarkArticleRequest) Sanitise added in v0.28.0

func (r *MarkArticleRequest) Sanitise() error

func (*MarkArticleRequest) Valid added in v0.28.0

func (r *MarkArticleRequest) Valid() error

type MarkArticlesRequest

type MarkArticlesRequest struct {
	// DisplayedArticles is a map of item ids per subscription.
	DisplayedArticles map[SubscriptionID][]ItemID `form:"displayed_articles" json:"displayed_articles"`

	// Mark applies the given mark action to objects.
	Mark Mark `form:"mark" json:"mark" validate:"oneof=read unread"`
}

MarkArticlesRequest contains the parameters for marking articles.

func (*MarkArticlesRequest) Sanitise

func (r *MarkArticlesRequest) Sanitise() error

Sanitise will alter MarkArticlesRequest data to ensure safety, where needed.

func (*MarkArticlesRequest) Valid

func (r *MarkArticlesRequest) Valid() error

Valid ensures that the MarkArticlesRequest contains valid data.

type MarkObjectParams

type MarkObjectParams struct {
	// ObjectID represents an ID of any user-facing object.
	ObjectID ObjectID `form:"id" json:"id" validate:"required,startswith=sub_|startswith=item_"`

	// Mark applies the given mark action to objects.
	Mark Mark `form:"mark" json:"mark" validate:"oneof=read unread"`

	// Object represents the type of any user-facing object.
	Object ObjectType `form:"object" json:"object" validate:"required,oneof=subscription article"`
}

MarkObjectParams defines model for MarkObjectParams.

func (*MarkObjectParams) Sanitise

func (m *MarkObjectParams) Sanitise() error

func (*MarkObjectParams) Valid

func (m *MarkObjectParams) Valid() error

type MarkSubscriptionRequest added in v0.31.0

type MarkSubscriptionRequest struct {
	// Mark applies the given mark action to objects.
	Mark Mark `form:"mark" json:"mark" validate:"oneof=read unread"`

	// SubscriptionID is the unique ID of a subscription.
	SubscriptionID SubscriptionID `form:"subscription_id" json:"subscription_id" validate:"required,startswith=sub_"`
}

MarkSubscriptionRequest contains the parameters for marking a subscription.

func (*MarkSubscriptionRequest) Sanitise added in v0.31.0

func (s *MarkSubscriptionRequest) Sanitise() error

Sanitise will sanitise the MarkSubscriptionRequest, ensuring it contains valid field values.

func (*MarkSubscriptionRequest) Valid added in v0.31.0

func (s *MarkSubscriptionRequest) Valid() error

Valid checks that the MarkSubscriptionRequest contains valid data.

type MarkSubscriptionsRequest

type MarkSubscriptionsRequest struct {
	// Mark applies the given mark action to objects.
	Mark Mark `form:"mark" json:"mark" validate:"oneof=read unread"`

	// Subscriptions is a list of subscription IDs.
	Subscriptions []SubscriptionID `form:"displayed_subscriptions" json:"subscriptions" validate:"omitempty,dive,startswith=sub_"`

	// View The state of objects to view.
	View View `form:"view" json:"view" validate:"required,oneof=read unread all"`
}

MarkSubscriptionsRequest contains the parameters for marking a list of subscriptions.

func (*MarkSubscriptionsRequest) Sanitise

func (s *MarkSubscriptionsRequest) Sanitise() error

Sanitise will sanitise the MarkSubscriptionsRequest, ensuring it contains valid field values.

func (*MarkSubscriptionsRequest) Valid

func (s *MarkSubscriptionsRequest) Valid() error

Valid checks that the MarkSubscriptionsRequest contains valid data.

type MarkdownFile added in v0.49.0

type MarkdownFile struct {
	Content []byte `json:"content"`

	// Details contains a mapping of a file in an embedded FS to the URL path it is served from.
	Details FileDetails `json:"details"`

	// Frontmatter contains metadata about a markdown file that allows mapping it to a path under a documentation directory.
	Frontmatter MarkdownFrontMatter `json:"frontmatter" toml:"doc_metadata"`
}

MarkdownFile contains the raw markdown file data and its frontmatter.

type MarkdownFrontMatter added in v0.49.0

type MarkdownFrontMatter struct {
	// Author the person who wrote or is responsible for the document.
	Author *string `json:"author,omitempty" toml:"author"`

	// CreatedAt is when the post was created.
	CreatedAt string `json:"created_at" toml:"created_at" validate:"required,datetime=2006-01-02"`

	// Description is a description of the document, used in metadata headers of the page.
	Description string `json:"description" toml:"description" validate:"required"`

	// Image is a URL to an image to represent the file.
	Image *string `json:"image,omitempty" toml:"image" validate:"omitempty,url"`

	// Title is the title to display for the document.
	Title string `json:"title" toml:"title" validate:"required"`

	// UpdatedAt is when the post was updated.
	UpdatedAt *string `json:"updated_at,omitempty" toml:"updated_at" validate:"omitempty,datetime=2006-01-02"`
}

MarkdownFrontMatter contains metadata about a markdown file that allows mapping it to a path under a documentation directory.

type Nickname

type Nickname = string

Nickname is an optional friendly name.

type OPMLFile

type OPMLFile struct {
	*FileUpload
}

OPMLFile is an opml file used for importing/exporting subscriptions.

func (*OPMLFile) GenerateRequests

func (f *OPMLFile) GenerateRequests() ([]*AddFeedSubscriptionRequest, error)

GenerateRequests extracts the feed outlines from the OPML file and returns a slice of subscription requests.

func (*OPMLFile) Valid

func (f *OPMLFile) Valid() (bool, error)

Valid returns a boolean indicating if the OPML file is valid. If not valid, a non-nil error is also returned which will contain details about validation failures.

type ObjectCommon

type ObjectCommon struct {
	// Authors is a list of people (names, nicknames and/or emails) who "authored" the object content.
	Authors []string `json:"authors,omitempty"`

	// Categories is a list of categories that define a taxonomy for the feed or item.
	Categories []Category `json:"categories,omitempty" validate:"omitempty,unique"`

	// Contributors is a list of people (names, nicknames and/or emails) who "contributed" the object content.
	Contributors []string `json:"contributors,omitempty"`
	Copyright    string   `json:"copyright,omitempty"`

	// Description is a short summary or description of the feed or item.
	Description *string `json:"description,omitempty"`

	// Image contains details about a remote image.
	Image    *RemoteImage `json:"image,omitempty"`
	Language string       `json:"language,omitempty"`

	// Published is the datetime at which the feed or item was published.
	Published time.Time `json:"published"`

	// SourceType indicates what type of source the object came from.
	SourceType SourceType `json:"source_type"`

	// Title is the title of the feed or item.
	Title string `json:"title"`

	// Updated is the datetime at which the feed or item was updated.
	Updated time.Time `json:"updated,omitempty"`

	// URL is the URL to the webpage for the feed or item. For a feed, this is most likely the webpage the feed is sourced from. For an item, this is most likely the webpage containing the full item contents.
	URL string `json:"url,omitempty" validate:"omitempty,url"`
}

ObjectCommon contains common fields across objects.

type ObjectID

type ObjectID = string

ObjectID represents an ID of any user-facing object.

type ObjectParams

type ObjectParams struct {
	// ObjectID represents an ID of any user-facing object.
	ObjectID ObjectID `form:"id" json:"id" validate:"required,startswith=sub_|startswith=item_"`

	// Object represents the type of any user-facing object.
	Object ObjectType `form:"object" json:"object" validate:"required,oneof=subscription article"`
}

ObjectParams contains the parameters for viewing an object.

func (*ObjectParams) Sanitise

func (p *ObjectParams) Sanitise() error

func (*ObjectParams) Valid

func (p *ObjectParams) Valid() error

type ObjectType

type ObjectType string

ObjectType represents the type of any user-facing object.

const (
	ObjectTypeArticle      ObjectType = "article"
	ObjectTypeSubscription ObjectType = "subscription"
)

Defines values for ObjectType.

func (ObjectType) Valid added in v0.79.0

func (e ObjectType) Valid() bool

Valid indicates whether the value is a known member of the ObjectType enum.

type Pagination

type Pagination = string

Pagination contains data for paginating through results.

type RemoteImage added in v0.79.0

type RemoteImage struct {
	// Title the description of the image
	Title *string `json:"title,omitempty"`

	// URL is a URL.
	URL *URL `json:"url" validate:"omitempty,url"`
}

RemoteImage contains details about a remote image.

func ExtractImageFromContent added in v0.28.0

func ExtractImageFromContent(content string) (*RemoteImage, error)

func NewRemoteImage added in v0.79.0

func NewRemoteImage(url, title string) *RemoteImage

func (*RemoteImage) GetTitle added in v0.79.0

func (i *RemoteImage) GetTitle() string

func (*RemoteImage) GetURL added in v0.79.0

func (i *RemoteImage) GetURL() string

type RemoveSubscriptionRequest

type RemoveSubscriptionRequest struct {
	Nickname string `form:"nickname" json:"nickname" validate:"required"`

	// SubscriptionID is the unique ID of a subscription.
	SubscriptionID SubscriptionID `form:"subscription_id" json:"subscription_id" validate:"required,startswith=sub_"`
}

RemoveSubscriptionRequest contains the parameters for removing a subscription.

func (*RemoveSubscriptionRequest) Valid

func (r *RemoveSubscriptionRequest) Valid() error

Valid checks that the RemoveSubscriptionRequest contains valid data.

type ReportIssueRequest

type ReportIssueRequest struct {
	// Details is the user-submitted text about the issue.
	Details *string `form:"details" json:"details,omitempty"`

	// PageUrl is the URL of the page on which the user selected the report issue action.
	PageUrl string `form:"page_url" json:"page_url" validate:"required,url"`

	// ScreenshotURL is a URL to a screenshot the user has uploaded that is related to or showing the problem.
	ScreenshotURL *string `form:"-" json:"screenshot_url,omitempty" validate:"omitempty,url"`

	// UserEmail is the email address the user has entered for getting in touch about the issue.
	UserEmail string `form:"user_email" json:"user_email" validate:"required,email"`
}

ReportIssueRequest contains details about an issue with the service.

func (*ReportIssueRequest) Sanitise

func (i *ReportIssueRequest) Sanitise() error

func (*ReportIssueRequest) Valid

func (i *ReportIssueRequest) Valid() error

type ReportObjectIssueRequest

type ReportObjectIssueRequest struct {
	// Details is the user-submitted text about the issue.
	Details *string `form:"details" json:"details,omitempty"`

	// Duplicate indicates that the object has a duplicate.
	Duplicate bool `form:"duplicate" json:"duplicate"`

	// ObjectID represents an ID of any user-facing object.
	ObjectID ObjectID `form:"id" json:"id" validate:"required,startswith=sub_|startswith=item_"`

	// MangledContent indicates that the text content of the object is mangled/malformed or otherwise incorrect in some way.
	MangledContent bool `form:"mangled_content" json:"mangled_content"`

	// MissingImage indicates the object is expected to have an image, but it is missing.
	MissingImage bool `form:"missing_image" json:"missing_image"`

	// Object represents the type of any user-facing object.
	Object ObjectType `form:"object" json:"object" validate:"required,oneof=subscription article"`

	// PageUrl is the URL of the page on which the user selected the report issue action.
	PageUrl string `form:"page_url" json:"page_url" validate:"required,url"`

	// ScreenshotURL is a URL to a screenshot the user has uploaded that is related to or showing the problem.
	ScreenshotURL *string `form:"-" json:"screenshot_url,omitempty" validate:"omitempty,url"`

	// UserEmail is the email address the user has entered for getting in touch about the issue.
	UserEmail string `form:"user_email" json:"user_email" validate:"required,email"`
}

ReportObjectIssueRequest defines model for ReportObjectIssueRequest.

func NewObjectIssue

func NewObjectIssue(obj *ObjectParams, email, url string) *ReportObjectIssueRequest

func (*ReportObjectIssueRequest) Sanitise

func (i *ReportObjectIssueRequest) Sanitise() error

func (*ReportObjectIssueRequest) Valid

func (i *ReportObjectIssueRequest) Valid() error

type SearchRequest

type SearchRequest struct {
	// Authors a list of search terms for authors.
	Authors *string `form:"authors" json:"authors,omitempty"`

	// Categories a list of search terms for categories.
	Categories *string `form:"categories" json:"categories,omitempty"`

	// PublishedWithin represents a time range within which the objects should be published
	PublishedWithin SearchRequestPublishedWithin `` /* 135-byte string literal not displayed */

	// Sort is how a list of objects is sorted.
	Sort Sort `form:"sort" json:"sort" validate:"required,oneof=newest_first oldest_first most_unread least_unread most_relevant"`

	// SubscriptionID will be a subscription ID if the user has created a SearchSubscription for this request.
	SubscriptionID *SubscriptionID `form:"subscription_id" json:"subscription_id,omitempty" validate:"omitzero,startswith=sub_"`

	// Subscriptions is a list of subscription IDs.
	Subscriptions []SubscriptionID `form:"subscriptions" json:"subscriptions,omitempty" validate:"omitempty,unique,dive,startswith=sub_"`

	// Text is the text to search.
	Text string `form:"text" json:"text" validate:"omitempty,required"`

	// Timezone represents the timezone of the browser (i.e., user), used for calculating published_within offset.
	Timezone string `form:"timezone" json:"timezone" validate:"required,timezone"`

	// View The state of objects to view.
	View View `form:"view" json:"view" validate:"required,oneof=read unread all"`
}

SearchRequest represents a search request by the user.

func NewSearchRequest

func NewSearchRequest() *SearchRequest

NewSearchRequest creates a new SearchRequest object with default values. Defaults are search all objects within last week, sorted by most relevant.

func (*SearchRequest) HXVals

func (r *SearchRequest) HXVals() string

HXVals returns a string that represents the search as hx-vals.

func (*SearchRequest) Query

func (r *SearchRequest) Query() string

Query returns a string that represents the search as query parameters.

func (*SearchRequest) Sanitise

func (r *SearchRequest) Sanitise() error

Sanitise will sanitise the search request data.

func (*SearchRequest) Valid

func (r *SearchRequest) Valid() error

Valid returns a boolean indicating whether the search request data is valid.

type SearchRequestPublishedWithin

type SearchRequestPublishedWithin string

SearchRequestPublishedWithin represents a time range within which the objects should be published

const (
	SearchRequestPublishedWithinAllTime     SearchRequestPublishedWithin = "all_time"
	SearchRequestPublishedWithinLast12hours SearchRequestPublishedWithin = "last_12hours"
	SearchRequestPublishedWithinLastDay     SearchRequestPublishedWithin = "last_day"
	SearchRequestPublishedWithinLastHour    SearchRequestPublishedWithin = "last_hour"
	SearchRequestPublishedWithinLastMonth   SearchRequestPublishedWithin = "last_month"
	SearchRequestPublishedWithinLastWeek    SearchRequestPublishedWithin = "last_week"
)

Defines values for SearchRequestPublishedWithin.

func (SearchRequestPublishedWithin) Valid added in v0.79.0

Valid indicates whether the value is a known member of the SearchRequestPublishedWithin enum.

type SearchResults added in v0.28.1

type SearchResults struct {
	Articles Articles `json:"articles,omitempty"`

	// Categories is a list of categories.
	Categories []Category `form:"categories" json:"categories" validate:"omitnil,unique,dive,url_encoded"`

	// Pagination contains data for paginating through results.
	Pagination *Pagination `form:"pagination" json:"pagination,omitempty" validate:"omitempty,url_encoded"`

	// Search represents a search request by the user.
	Search        SearchRequest `form:"search" json:"search" validate:"required"`
	Subscriptions Subscriptions `json:"subscriptions,omitempty"`
}

SearchResults contains the results of a search.

type SearchSubscription

type SearchSubscription struct {
	// Search represents a search request by the user.
	Search SearchRequest `form:"search" json:"search" validate:"required"`
}

SearchSubscription is a custom subscription created from a search request.

func (*SearchSubscription) Valid

func (s *SearchSubscription) Valid() error

Valid returns a boolean indicating if the Subscription contains valid data (true). If it contains invalid data (false) a non-nil error is also returned which contains validation issues.

type SearchSubscriptionRequest

type SearchSubscriptionRequest struct {
	// Customisation contains object fields that can be customised (overridden) by a user
	Customisation *SubscriptionCustomisation `form:"customisation" json:"customisation,omitempty"`

	// Search represents a search request by the user.
	Search SearchRequest `form:"search" json:"search" validate:"required"`

	// Settings contains options that control how the subscription is stored/displayed.
	Settings *SubscriptionSettings `form:"settings" json:"settings,omitempty"`

	// SuggestedCategories is a list of suggested categories for the subscription.
	SuggestedCategories []Category `form:"-" json:"-"`
}

SearchSubscriptionRequest represents a request to create a search subscription.

func NewSearchSubscriptionRequest added in v0.54.0

func NewSearchSubscriptionRequest(
	search SearchRequest,
	suggestedCategories []Category,
) *SearchSubscriptionRequest

func (*SearchSubscriptionRequest) Sanitise

func (r *SearchSubscriptionRequest) Sanitise() error

func (*SearchSubscriptionRequest) Valid

func (r *SearchSubscriptionRequest) Valid() error

type ShareArticleRequest added in v0.34.1

type ShareArticleRequest struct {
	// ItemID is the unique ID of an item.
	ItemID ItemID `form:"item_id" json:"item_id" validate:"required,startswith=item_"`

	// Link is the link to the article.
	Link string `form:"link" json:"link" validate:"required,url"`

	// Title is the article title.
	Title string `form:"title" json:"title" validate:"required"`
}

ShareArticleRequest contains parameters for sharing an article.

func (*ShareArticleRequest) Sanitise added in v0.34.1

func (r *ShareArticleRequest) Sanitise() error

func (*ShareArticleRequest) Valid added in v0.34.1

func (r *ShareArticleRequest) Valid() error

type Sort

type Sort string

Sort is how a list of objects is sorted.

const (
	SortLeastUnread  Sort = "least_unread"
	SortMostRelevant Sort = "most_relevant"
	SortMostUnread   Sort = "most_unread"
	SortNewestFirst  Sort = "newest_first"
	SortOldestFirst  Sort = "oldest_first"
)

Defines values for Sort.

func (Sort) String

func (s Sort) String() string

func (Sort) Valid added in v0.79.0

func (e Sort) Valid() bool

Valid indicates whether the value is a known member of the Sort enum.

type SourceType added in v0.26.0

type SourceType string

SourceType indicates what type of source the object came from.

const (
	SourceTypeAtom     SourceType = "Atom"
	SourceTypeEmail    SourceType = "Email"
	SourceTypeJSONFeed SourceType = "JSONFeed"
	SourceTypeRSS      SourceType = "RSS"
)

Defines values for SourceType.

func (SourceType) Valid added in v0.79.0

func (e SourceType) Valid() bool

Valid indicates whether the value is a known member of the SourceType enum.

type State

type State string

State Tracks the state of an object.

const (
	StateRead   State = "read"
	StateSaved  State = "saved"
	StateUnread State = "unread"
)

Defines values for State.

func (State) Valid added in v0.79.0

func (e State) Valid() bool

Valid indicates whether the value is a known member of the State enum.

type StoredImage

type StoredImage struct {
	Data image.Image `json:"data"`
}

StoredImage is an image stored locally (i.e., the binary data to represent the image).

type Subscription

type Subscription struct {
	// CreatedAt records when the object was created in the database.
	CreatedAt CreatedAt `json:"created_at" validate:"required"`

	// Customisation contains object fields that can be customised (overridden) by a user
	Customisation *SubscriptionCustomisation `form:"customisation" json:"customisation,omitempty"`

	// EmailData is a subscription to an email newsletter source.
	EmailData *EmailSubscription `json:"email_data,omitempty" validate:"omitempty"`

	// Favorite indicates whether this subscription has been marked as a favorite by the user.
	Favorite bool `json:"favorite"`

	// FeedData represents a feed a user has subscribed to.
	FeedData *FeedSubscription `json:"feed_data,omitempty" validate:"omitempty"`

	// GroupData represents a subscription that combines other subscriptions.
	GroupData *GroupSubscription `json:"group_data,omitempty" validate:"omitempty"`

	// MarkedReadAt indicates when the subscription was last marked read. Any articles older than this timestamp are considered read, any newer unread.
	MarkedReadAt *time.Time `json:"marked_read_at,omitempty"`

	// SearchData is a custom subscription created from a search request.
	SearchData *SearchSubscription `json:"search_data,omitempty" validate:"omitempty"`

	// Settings contains options that control how the subscription is stored/displayed.
	Settings SubscriptionSettings `form:"settings" json:"settings"`

	// Stats contains stats about a subscription.
	Stats *SubscriptionStats `json:"-" validate:"-"`

	// SubscriptionID is the unique ID of a subscription.
	SubscriptionID SubscriptionID `form:"subscription_id" json:"subscription_id" validate:"required,startswith=sub_"`

	// Type is the type of subscription.
	Type SubscriptionType `json:"type" validate:"required,oneof=feed search group email"`

	// UpdatedAt records when the object was last updated in the database.
	UpdatedAt *UpdatedAt `json:"updated_at,omitempty" validate:"omitnil"`

	// UserID is the unique ID of a user.
	UserID UserID `form:"user_id" json:"user_id" validate:"required,startswith=user_"`
}

Subscription defines model for Subscription.

func GetEmailSubscription added in v0.25.0

func GetEmailSubscription(ctx context.Context, userID UserID, from *mail.Address) (*Subscription, error)

GetEmailSubscription retrieves an EmailSubscription for the given user ID and email sender.

func GetSubscription

func GetSubscription(
	ctx context.Context,
	id SubscriptionID,
	options ...subscriptionsRequestOption,
) (*Subscription, error)

GetSubscription returns the subscription that matches the given ID.

Accepts the GetSubscriptionsDynamicInfo request option to generate dynamic info (i.e. stats) for the subscription.

func GetSubscriptionByFeedID

func GetSubscriptionByFeedID(
	ctx context.Context,
	id FeedID,
	options ...subscriptionsRequestOption,
) (*Subscription, error)

GetSubscriptionByFeedID returns the subscription that matches the given feed ID.

Accepts the GetSubscriptionsDynamicInfo request option to generate dynamic info (i.e. stats) for the subscription.

func NewEmailSubscription added in v0.25.0

func NewEmailSubscription(
	ctx context.Context,
	userID UserID,
	from *mail.Address,
) (*Subscription, error)

func NewFeedSubscription

func NewFeedSubscription(ctx context.Context, feed *Feed, request *AddFeedSubscriptionRequest) (*Subscription, error)

NewFeedSubscription creates a new subscription for a feed from the request and feed details.

func NewGroupSubscription

func NewGroupSubscription(ctx context.Context, request *GroupSubscriptionRequest) (*Subscription, error)

NewGroupSubscription creates a GroupSubscription. A GroupSubscription is a kind of meta-subscription that aggregates all articles from multiple individual subscriptions into a single custom subscription.

func NewSearchSubscription

func NewSearchSubscription(ctx context.Context, request *SearchSubscriptionRequest) (*Subscription, error)

NewSearchSubscription creates a new SearchSubscription. A SearchSubscription collates articles that match a search into a single custom subscription.

func (*Subscription) GetArticleFilters added in v0.26.0

func (s *Subscription) GetArticleFilters() SubscriptionArticleFilters

func (*Subscription) GetCategories

func (s *Subscription) GetCategories(maxCount int) Categories

GetCategories returns the categories of the subscription. It is the combined list of any user-assigned categories and the categories in the feed content.

func (*Subscription) GetFeedID added in v0.26.0

func (s *Subscription) GetFeedID() FeedID

GetFeedID returns the unqiue FeedID of the subscription. Not all subscription types will have a FeedID.

func (*Subscription) GetID

func (s *Subscription) GetID() SubscriptionID

GetID returns the unqiue ID of the subscription.

func (*Subscription) GetImage

func (s *Subscription) GetImage() URL

GetImage retrieves the image that represents the subscription, or nil if no image is available.

func (*Subscription) GetItemState added in v0.26.0

func (s *Subscription) GetItemState(itemID ItemID) *ArticleState

GetItemState retrieves the item state (read/unread/saved) from the subscription. By default it will return unread unless the user has explicitly marked or saved the item.

func (s *Subscription) GetLink() string

GetLink returns the source feed link. For a search subscription, there is no source so this returns an empty string.

func (*Subscription) GetMarkedReadAt added in v0.26.0

func (s *Subscription) GetMarkedReadAt() time.Time

func (*Subscription) GetReadItems added in v0.26.0

func (s *Subscription) GetReadItems() []ItemID

GetReadItems retrieves a list of ItemIDs for the feed subscription that user has explicitly marked as read.

func (*Subscription) GetStats

func (s *Subscription) GetStats() *SubscriptionStats

GetStats returns the stats object containing the dynamically generated stats (i.e., unread count, article rate) of the subscription.

func (*Subscription) GetSubscriptionType

func (s *Subscription) GetSubscriptionType() SubscriptionType

GetSubscriptionType returns the type of subscription (i.e., feed, search, group, etc.).

func (*Subscription) GetTitle

func (s *Subscription) GetTitle() string

GetTitle returns the title (or user nickname if assigned) of the subscription.

func (*Subscription) GetUnreadItems added in v0.26.0

func (s *Subscription) GetUnreadItems() []ItemID

GetUnreadItems retrieves a list of ItemIDs for the feed subscription that user has explicitly marked as unread.

func (*Subscription) GetUpdatedDate

func (s *Subscription) GetUpdatedDate() time.Time

GetUpdatedDate returns the timestamp that represents when the subscription was last updated. Usually, this means the timestamp of the newest article in the subscription.

func (*Subscription) IsFavorite

func (s *Subscription) IsFavorite() bool

IsFavorite returns a boolean indicating whether the user has marked this subscription as a favorite. Note for some subscription types, this will always return true.

func (*Subscription) Mark

func (s *Subscription) Mark(user *User, mark Mark)

Mark applies the given mark (read/unread) to a subscription.

func (*Subscription) MarkItems

func (s *Subscription) MarkItems(mark Mark, itemIDs ...ItemID)

MarkItems marks the given items in a user subscription the given mark.

func (*Subscription) MarkItemsRead

func (s *Subscription) MarkItemsRead(itemIDs ...ItemID)

MarkItemsRead will mark the given items as read for the subscription.

func (*Subscription) MarkItemsUnread

func (s *Subscription) MarkItemsUnread(itemIDs ...ItemID)

MarkItemsUnread will mark the given items as unread for the subscription.

func (*Subscription) SetItemState added in v0.26.0

func (s *Subscription) SetItemState(itemID ItemID, state *ArticleState)

SetItemState will set the state of the item to the given state.

func (*Subscription) Valid

func (s *Subscription) Valid() error

Valid returns a boolean indicating if the Subscription contains valid data (true). If it contains invalid data (false) a non-nil error is also returned which contains validation issues.

type SubscriptionArticleFilters

type SubscriptionArticleFilters struct {
	// Authors is the author filters to apply.
	Authors *string `form:"authors" json:"authors,omitempty"`

	// Categories is the category filters to apply.
	Categories *string `form:"categories" json:"categories,omitempty"`

	// Text is the filters on the title/content to apply.
	Text *string `form:"text" json:"text,omitempty"`
}

SubscriptionArticleFilters holds filters to apply to the articles within a subscription.

type SubscriptionCustomisation

type SubscriptionCustomisation struct {
	// Categories is a custom list of categories for an object.
	Categories []Category `form:"categories" json:"categories,omitempty" validate:"omitempty,unique"`

	// ImageURL is a custom image to represent the object.
	ImageURL *string `json:"image_url,omitempty" validate:"omitempty,url"`

	// Nickname is an optional alias or label for an object.
	Nickname string `form:"nickname" json:"nickname,omitempty" validate:"required"`
}

SubscriptionCustomisation contains object fields that can be customised (overridden) by a user

type SubscriptionID

type SubscriptionID = string

SubscriptionID is the unique ID of a subscription.

type SubscriptionMetadata

type SubscriptionMetadata struct {
	// CreatedAt records when the object was created in the database.
	CreatedAt CreatedAt `json:"created_at" validate:"required"`

	// Customisation contains object fields that can be customised (overridden) by a user
	Customisation *SubscriptionCustomisation `form:"customisation" json:"customisation,omitempty"`

	// Favorite indicates whether this subscription has been marked as a favorite by the user.
	Favorite bool `json:"favorite"`

	// MarkedReadAt indicates when the subscription was last marked read. Any articles older than this timestamp are considered read, any newer unread.
	MarkedReadAt *time.Time `json:"marked_read_at,omitempty"`

	// Settings contains options that control how the subscription is stored/displayed.
	Settings SubscriptionSettings `form:"settings" json:"settings"`

	// SubscriptionID is the unique ID of a subscription.
	SubscriptionID SubscriptionID `form:"subscription_id" json:"subscription_id" validate:"required,startswith=sub_"`

	// Type is the type of subscription.
	Type SubscriptionMetadataType `json:"type" validate:"required,oneof=feed search group email"`

	// UpdatedAt records when the object was last updated in the database.
	UpdatedAt *UpdatedAt `json:"updated_at,omitempty" validate:"omitnil"`

	// UserID is the unique ID of a user.
	UserID UserID `form:"user_id" json:"user_id" validate:"required,startswith=user_"`
}

SubscriptionMetadata contains common fields across all subscription types.

type SubscriptionMetadataType

type SubscriptionMetadataType string

SubscriptionMetadataType is the type of subscription.

const (
	SubscriptionMetadataTypeEmail  SubscriptionMetadataType = "email"
	SubscriptionMetadataTypeFeed   SubscriptionMetadataType = "feed"
	SubscriptionMetadataTypeGroup  SubscriptionMetadataType = "group"
	SubscriptionMetadataTypeSearch SubscriptionMetadataType = "search"
)

Defines values for SubscriptionMetadataType.

func (SubscriptionMetadataType) Valid added in v0.79.0

func (e SubscriptionMetadataType) Valid() bool

Valid indicates whether the value is a known member of the SubscriptionMetadataType enum.

type SubscriptionSettings

type SubscriptionSettings struct {
	// ShowFullArticleContent toggles whether articles in the subscription should be always displayed with remote content.
	ShowFullArticleContent bool `form:"show_full_article_content" json:"show_full_article_content"`
}

SubscriptionSettings contains options that control how the subscription is stored/displayed.

type SubscriptionSorting

type SubscriptionSorting struct {
	MarkedReadAt   string `json:"marked_read_at"`
	SubscriptionID string `json:"subscription_id"`
}

SubscriptionSorting contains the sort options for sorting subscription results.

func (*SubscriptionSorting) SortCombinationsCaster

func (s *SubscriptionSorting) SortCombinationsCaster() *estypes.SortCombinations

SortCombinationsCaster is required to allow FeedSorting to be used as Elasticsearch sort values.

type SubscriptionStats

type SubscriptionStats struct {
	// AvgDailyUpdates is the avergage number of articles published per day.
	AvgDailyUpdates float64 `json:"-" validate:"gte=0"`

	// LastUpdate is the timestamp of the most newest item that matches the search.
	LastUpdate time.Time `json:"-" validate:"required"`

	// UnreadCount is the value of items that are not explicitly marked unread by the user for this subscription.
	UnreadCount int `json:"-" validate:"gte=0"`
}

SubscriptionStats contains stats about a subscription.

func (*SubscriptionStats) IsUnread

func (s *SubscriptionStats) IsUnread() bool

IsUnread returns a boolean indicating whether the subscription is considered unread.

func (*SubscriptionStats) UnreadTotal

func (s *SubscriptionStats) UnreadTotal() int

UnreadTotal returns the unread count of items in the subscription.

func (*SubscriptionStats) UpdateFrequency

func (s *SubscriptionStats) UpdateFrequency() string

UpdateFrequency returns a string that roughly indicates how often the subscription is updated.

type SubscriptionType

type SubscriptionType string

SubscriptionType is the type of subscription.

const (
	SubscriptionTypeEmail  SubscriptionType = "email"
	SubscriptionTypeFeed   SubscriptionType = "feed"
	SubscriptionTypeGroup  SubscriptionType = "group"
	SubscriptionTypeSearch SubscriptionType = "search"
)

Defines values for SubscriptionType.

func (SubscriptionType) Valid added in v0.79.0

func (e SubscriptionType) Valid() bool

Valid indicates whether the value is a known member of the SubscriptionType enum.

type Subscriptions

type Subscriptions []*Subscription

Subscriptions is a slice of subscriptions of any type.

func GetSubscriptionSuggestions

func GetSubscriptionSuggestions(
	ctx context.Context,
	text string,
	count int,
	options ...subscriptionsRequestOption,
) (Subscriptions, error)

GetSubscriptionSuggestions returns subscriptions that match the given text.

Accepts the GetSubscriptionsDynamicInfo request option to generate dynamic info (i.e. stats) for the subscription suggestions.

func GetSubscriptions

func GetSubscriptions(
	ctx context.Context,
	options ...subscriptionsRequestOption,
) (Subscriptions, error)

GetSubscriptions performs a search request to fetch subscriptions. Accepts all request options to filter/enrich the results.

func GetSubscriptionsForItems added in v0.26.0

func GetSubscriptionsForItems(ctx context.Context, items Items) (Subscriptions, error)

GetSubscriptionsForItems returns the subscriptions that the list of items belong to.

func SubscriptionsFromCtx

func SubscriptionsFromCtx(ctx context.Context) Subscriptions

SubscriptionsFromCtx retrieves the slice of Subscriptions from the context. If no Subscriptions slice is in the context, it returns an empty slice.

func (Subscriptions) FilterByCategories

func (s Subscriptions) FilterByCategories(categories ...Category) Subscriptions

FilterByCategories returns a new slice containing the subscriptions which have a category matching the given categories.

func (Subscriptions) FilterByFavorites

func (s Subscriptions) FilterByFavorites(value bool) Subscriptions

FilterByFavorites returns a slice containing only favorite subscriptions.

func (Subscriptions) FilterByType

func (s Subscriptions) FilterByType(t ...SubscriptionType) Subscriptions

FilterByType returns a slice containing subscriptions of the specified type.

func (Subscriptions) FilterByView

func (s Subscriptions) FilterByView(view View) Subscriptions

FilterByView returns a slice containing the subscription which match the given view state.

func (Subscriptions) GetByFeedID

func (s Subscriptions) GetByFeedID(id FeedID) *Subscription

GetByFeedID will return the subscription that matches the given feed ID, if any.

func (Subscriptions) GetCategories added in v0.54.0

func (s Subscriptions) GetCategories() Categories

GetCategories returns all categories across all the subscriptions. Duplicates are removed.

func (Subscriptions) GetFeedIDs

func (s Subscriptions) GetFeedIDs() []FeedID

GetFeedIDs returns the IDs of feeds the subscriptions are for. This may return an empty slice if the subscriptions are only of type search, for example as those subscriptions do not represent any particular feed.

func (Subscriptions) GetIDs

func (s Subscriptions) GetIDs() []SubscriptionID

GetIDs returns the subscription ids for all subscription states in the slice.

func (Subscriptions) Paginate

func (s Subscriptions) Paginate(pagination Pagination, count int) (Subscriptions, Pagination)

Paginate will paginate through a slice of subscriptions, returning a new slice of subscriptions and the next pagination value (if any).

func (Subscriptions) Sort

func (s Subscriptions) Sort(sort Sort) Subscriptions

Sort will sort the slice of subscriptions by the given sort option. Favorite subscriptions are always sorted before other subscriptions, and the sort option is used as a tiebreaker.

type Timestamp

type Timestamp = time.Time

Timestamp is when the document was created.

type URL

type URL = string

URL is a URL.

type UpdatedAt

type UpdatedAt = time.Time

UpdatedAt records when the object was last updated in the database.

type User

type User struct {
	// AvatarURL is a link to an image file to user as an avatar for the user.
	AvatarURL *string `form:"avatar_url" json:"avatar_url,omitempty" validate:"omitempty,url"`

	// CreatedAt records when the object was created in the database.
	CreatedAt CreatedAt `json:"created_at" validate:"required"`

	// Email is the email address of the user.
	Email *string `form:"email" json:"email,omitempty" validate:"omitempty,email"`

	// ExternalUserID is the ID of the user on the external backend that was used to create the account.
	ExternalUserID string `json:"external_user_id" validate:"required"`

	// ItemFavorites is the IDs of items (articles) the user has favorited.
	ItemFavorites []ItemID `json:"item_favorites,omitempty" validate:"omitempty,dive,startswith=item_"`

	// LastLogin is the timestamp of when the user last logged in to the app.
	LastLogin *time.Time `json:"last_login,omitempty"`

	// LoginCount is the total number of logins of the user.
	LoginCount *int `json:"login_count,omitempty"`

	// Metadata contains metadata related to the user's account.
	Metadata UserMetadata `json:"metadata" validate:"omitempty"`

	// Nickname is a nickname for the user.
	Nickname *string `form:"nickname" json:"nickname,omitempty"`

	// Provider is the backend provider that was used to create the account.
	Provider string `json:"provider" validate:"required"`

	// Settings contains user-specific settings for the application.
	Settings UserSettings `json:"settings"`

	// UpdatedAt records when the object was last updated in the database.
	UpdatedAt *UpdatedAt `json:"updated_at,omitempty" validate:"omitnil"`

	// UserID is the unique ID of a user.
	UserID UserID `form:"user_id" json:"user_id" validate:"required,startswith=user_"`
}

User defines model for User.

func GetUser

func GetUser(ctx context.Context, id UserID) (*User, error)

GetUser retrieves the user doc with the given id.

func GetUserByExternalID

func GetUserByExternalID(ctx context.Context, externalID string) (*User, error)

GetUserByExternalID will search for and return a user that matches the given external ID, if exists.

func GetUserBySubscriptionEmail added in v0.25.0

func GetUserBySubscriptionEmail(ctx context.Context, emails ...string) (*User, error)

GetUserByExternalID will search for and return a user that matches the given external ID, if exists.

func UserFromCtx

func UserFromCtx(ctx context.Context) *User

UserFromCtx retrieves a user from the context, if any.

func (*User) Active

func (u *User) Active() bool

Active returns a boolean indicating whether the user is "active", which means a paying customer with no payment issues or customer currently on a trial.

func (*User) Cancelled

func (u *User) Cancelled() (bool, time.Time)

Cancelled returns a boolean indicating whether the user has cancelled their subscription plan and if so, a timestamp indicating when the cancellation will apply.

func (*User) GetAvatar

func (u *User) GetAvatar() string

GetAvatar retrieves the URL to the image to represent the user.

func (*User) GetEmail

func (u *User) GetEmail() string

GetEmail retrieves the email of the user.

func (*User) GetExternalID

func (u *User) GetExternalID() UserID

GetExternalID returns the backend ID for the user.

func (*User) GetID

func (u *User) GetID() UserID

GetID returns the ID for the user.

func (*User) GetMaxHistory

func (u *User) GetMaxHistory() time.Time

GetMaxHistory returns a timestamp in the past from which the user can view items. If there is an issue retrieving and parsing the value from the user's metadata, it will default to using the lowest plan max history.

func (*User) GetNickname

func (u *User) GetNickname() string

GetNickname retrieves the nickname of the user.

func (*User) GetSettings

func (u *User) GetSettings() *UserSettings

GetSettings returns the user's settings. If the user has no settings (i.e. new user), default settings will be returned.

func (*User) GetSubscriptionPlan

func (u *User) GetSubscriptionPlan() string

GetSubscriptionPlan returns the name of the subscription plan of the user.

func (*User) GetUpdatesFrequency

func (u *User) GetUpdatesFrequency() time.Duration

GetUpdatesFrequency returns a duration on which the user will see new updates. If there is an issue retrieving and parsing the value from the user's metdata, it will use the lowest plan updates frequency.

func (*User) OnTrial

func (u *User) OnTrial() (bool, time.Time)

OnTrial returns a boolean indicating whether the user is currently in a trial period and if so, a timestamp indicating when the trial will end.

func (*User) Valid

func (u *User) Valid(_ context.Context) error

Valid returns a boolean indicating whether the user data is valid. If not valid, it will also return a non-nil error that contains the validation issues.

type UserCustomisation

type UserCustomisation struct {
	// AvatarURL is a link to an image file to user as an avatar for the user.
	AvatarURL *string `form:"avatar_url" json:"avatar_url,omitempty" validate:"omitempty,url"`

	// Email is the email address of the user.
	Email *string `form:"email" json:"email,omitempty" validate:"omitempty,email"`

	// Nickname is a nickname for the user.
	Nickname *string `form:"nickname" json:"nickname,omitempty"`
}

UserCustomisation contains account fields that a user can customize.

type UserID

type UserID = string

UserID is the unique ID of a user.

type UserMessage

type UserMessage struct {
	// Details is a longer description and/or background details about the message.
	Details *string `json:"details,omitempty"`

	// Status indicates the severity or importance of the message.
	Status UserMessageStatus `json:"status" validate:"required"`

	// Summary is a user-level brief description for the message, which can be used as a title or summary.
	Summary string `json:"summary" validate:"required"`
}

UserMessage represents a message that can be displayed to the user as the result of an action.

func NewErrorMessage

func NewErrorMessage(summary string, details string) *UserMessage

NewErrorMessage creates a new UserMessage indicating an error with the given summary and (optional) details.

func NewInfoMessage

func NewInfoMessage(summary string, details string) *UserMessage

NewInfoMessage creates a new UserMessage indicating informational details with the given summary and (optional) details.

func NewSuccessMessage

func NewSuccessMessage(summary string, details string) *UserMessage

NewSuccessMessage creates a new UserMessage indicating success with the given summary and (optional) details.

func NewWarningMessage

func NewWarningMessage(summary string, details string) *UserMessage

NewWarningMessage creates a new UserMessage indicating a warning with the given summary and (optional) details.

func (*UserMessage) HasDetails

func (msg *UserMessage) HasDetails() bool

HasDetails returns a boolean indicating whether the message has additional details.

func (*UserMessage) IsError

func (msg *UserMessage) IsError() bool

IsError returns true when the message indicates an error.

func (*UserMessage) IsInfo

func (msg *UserMessage) IsInfo() bool

IsInfo returns true when the message indicates informational status.

func (*UserMessage) IsSuccess

func (msg *UserMessage) IsSuccess() bool

IsSuccess returns true when the message indicates success.

func (*UserMessage) IsWarning

func (msg *UserMessage) IsWarning() bool

IsWarning returns true when the message indicates a warning.

func (*UserMessage) String

func (msg *UserMessage) String() string

String returns the message as a formatted string. This allows Message to satisfy the Stringer interface.

type UserMessageStatus

type UserMessageStatus string

UserMessageStatus indicates the severity or importance of the message.

const (
	UserMessageStatusError   UserMessageStatus = "error"
	UserMessageStatusInfo    UserMessageStatus = "info"
	UserMessageStatusSuccess UserMessageStatus = "success"
	UserMessageStatusWarning UserMessageStatus = "warning"
)

Defines values for UserMessageStatus.

func (UserMessageStatus) Valid added in v0.79.0

func (e UserMessageStatus) Valid() bool

Valid indicates whether the value is a known member of the UserMessageStatus enum.

type UserMetadata

type UserMetadata struct {
	// Blocked indicates whether the user is blocked from the app.
	Blocked bool `json:"blocked"`

	// CancelAt is a date in the future at which the subscription will automatically get canceled.
	CancelAt *time.Time `json:"cancel_at,omitempty"`

	// EmailVerified indicates whether the user has verfied their email address.
	EmailVerified bool `json:"email_verified" validate:"required"`

	// Plan is the name of the subscription plan that the user is paying for.
	// Possible values will come from the product defined in Stripe.
	Plan *string `json:"plan,omitempty" validate:"required"`

	// PlanID is the unique identifier for the plan.
	// Possible values will come from the product defined in Stripe.
	PlanID *string `json:"plan_id,omitempty" validate:"required"`

	// PlanStatus is the name current status of the subscription plan.
	// Possible values come directly from the Stripe API:
	// https://docs.stripe.com/api/subscriptions/object?api-version=2025-11-17.preview#subscription_object-status
	PlanStatus *stripe.SubscriptionStatus `json:"plan_status,omitempty" validate:"required"`

	// PoliciesAccepted indicates whether the user has accepted the app policies.
	PoliciesAccepted bool `json:"policies_accepted" validate:"required"`

	// StripeCustomerID is the stripe customer id of the user.
	// https://docs.stripe.com/api/customers/object?api-version=2025-11-17.preview#customer_object-id
	StripeCustomerID *string `json:"stripe_customer_id,omitempty" validate:"required"`

	// StripeSubscriptionID is the stripe subscription id of the user's plan.
	// https://docs.stripe.com/api/subscriptions/object?api-version=2025-11-17.preview#subscription_object-id
	StripeSubscriptionID *string `json:"stripe_subscription_id,omitempty" validate:"required"`

	// TrialEnd is the date when the trial for the subscription ended.
	TrialEnd *time.Time `json:"trial_end,omitempty"`
}

UserMetadata contains metadata related to the user's account.

func (*UserMetadata) Valid

func (s *UserMetadata) Valid() error

Valid returns a boolean indicating if the UserSettings contains valid data (true). If it contains invalid data (false) a non-nil error is also returned which contains validation issues.

type UserSession

type UserSession struct {
	// Data the encoded session data.
	Data []byte `json:"data"`

	// Expiry the time at which this session token expires.
	Expiry time.Time `json:"expiry"`

	// Token the session token for the user.
	Token string `json:"token"`
}

UserSession tracks a user session.

type UserSettings

type UserSettings struct {
	// MarkArticleReadOnView indicates whether to automatically mark an article as read when viewed.
	MarkArticleReadOnView bool `form:"mark_article_read_on_view" json:"mark_article_read_on_view"`

	// MaxViewHistory is a user-specified limit on how far back in time to view articles.
	MaxViewHistory time.Duration `form:"max_view_history" json:"max_view_history" validate:"gte=0"`

	// ShowOnboarding indicates whether to show onboarding information (i.e., for a new user).
	ShowOnboarding bool `form:"-" json:"show_onboarding"`

	// ShowSubscriptionStats indicates whether various subscription stats (e.g., unread counts, articles/day, etc.) should be shown.
	ShowSubscriptionStats bool `form:"show_subscription_stats" json:"show_subscription_stats"`

	// SubscriptionEmail is an email address the user can use to subscribe to email newsletters.
	SubscriptionEmail *string `form:"subscription_email" json:"subscription_email,omitempty" validate:"omitempty,email"`

	// Theme the user interface theme chosen by the user.
	Theme string `form:"-" json:"theme"`

	// UpdatesInterval is the interval on which to check for new updates.
	UpdatesInterval time.Duration `form:"update_interval" json:"updates_interval" validate:"gte=0"`
}

UserSettings contains user-specific settings for the application.

func (*UserSettings) Sanitise

func (s *UserSettings) Sanitise() error

Sanitise will sanitise UserSettings values.

func (*UserSettings) Valid

func (s *UserSettings) Valid() error

Valid returns a boolean indicating if the UserSettings contains valid data (true). If it contains invalid data (false) a non-nil error is also returned which contains validation issues.

type View

type View string

View The state of objects to view.

const (
	ViewAll    View = "all"
	ViewRead   View = "read"
	ViewUnread View = "unread"
)

Defines values for View.

func (View) Valid added in v0.79.0

func (e View) Valid() bool

Valid indicates whether the value is a known member of the View enum.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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