microsub

package
v0.0.0-...-edf5a02 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2022 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package microsub describes the protocol methods of the Microsub protocol

Index

Constants

View Source
const (
	UnreadBool  = 0
	UnreadCount = 1
)

Constants for Unread

Variables

This section is empty.

Functions

This section is empty.

Types

type Card

type Card struct {
	// Filled      bool   `json:"filled,omitempty"`
	Type        string `json:"type,omitempty"`
	Name        string `json:"name,omitempty" mf2:"name"`
	URL         string `json:"url,omitempty" mf2:"url"`
	Photo       string `json:"photo,omitempty" mf2:"photo"`
	Locality    string `json:"locality,omitempty" mf2:"locality"`
	Region      string `json:"region,omitempty" mf2:"region"`
	CountryName string `json:"country-name,omitempty" mf2:"country-name"`
	Longitude   string `json:"longitude,omitempty" mf2:"longitude"`
	Latitude    string `json:"latitude,omitempty" mf2:"latitude"`
}

Card contains the fields of an author or location.

type Channel

type Channel struct {
	// UID is a unique id for the channel
	UID    string `json:"uid"`
	Name   string `json:"name"`
	Unread Unread `json:"unread,omitempty"`
}

Channel contains information about a channel.

type Content

type Content struct {
	Text string `json:"text,omitempty" mf2:"value"`
	HTML string `json:"html,omitempty" mf2:"html"`
}

Content contains the Text or HTML content of an Item.

type Feed

type Feed struct {
	Type        string `json:"type"`
	URL         string `json:"url"`
	Name        string `json:"name,omitempty"`
	Photo       string `json:"photo,omitempty"`
	Description string `json:"description,omitempty"`
	Author      Card   `json:"author,omitempty"`
}

Feed is one microsub feed.

type Item

type Item struct {
	Type       string          `json:"type"`
	Name       string          `json:"name,omitempty" mf2:"name"`
	Published  string          `json:"published,omitempty" mf2:"published"`
	Updated    string          `json:"updated,omitempty" mf2:"updated"`
	URL        string          `json:"url,omitempty" mf2:"url"`
	UID        string          `json:"uid,omitempty" mf2:"uid"`
	Author     *Card           `json:"author,omitempty" mf2:"author"`
	Category   []string        `json:"category,omitempty" mf2:"category"`
	Photo      []string        `json:"photo,omitempty" mf2:"photo"`
	LikeOf     []string        `json:"like-of,omitempty" mf2:"like-of"`
	BookmarkOf []string        `json:"bookmark-of,omitempty" mf2:"bookmark-of"`
	RepostOf   []string        `json:"repost-of,omitempty" mf2:"repost-of"`
	InReplyTo  []string        `json:"in-reply-to,omitempty" mf2:"in-reply-to"`
	Content    *Content        `json:"content,omitempty" mf2:"content"`
	Summary    string          `json:"summary,omitempty" mf2:"summary"`
	Latitude   string          `json:"latitude,omitempty" mf2:"latitude"`
	Longitude  string          `json:"longitude,omitempty" mf2:"longitude"`
	Checkin    *Card           `json:"checkin,omitempty" mf2:"checkin"`
	Refs       map[string]Item `json:"refs,omitempty"`
	ID         string          `json:"_id,omitempty"`
	Read       bool            `json:"_is_read"`
	Source     *Source         `json:"_source,omitempty"`
}

Item is a post object

func (*Item) Scan

func (item *Item) Scan(value interface{}) error

Scan helps to scan json data from database

func (*Item) Value

func (item *Item) Value() (driver.Value, error)

Value helps to add json data to database

type Microsub

type Microsub interface {
	ChannelsGetList() ([]Channel, error)
	ChannelsCreate(name string) (Channel, error)
	ChannelsUpdate(uid, name string) (Channel, error)
	ChannelsDelete(uid string) error

	TimelineGet(before, after, channel string) (Timeline, error)

	MarkRead(channel string, entry []string) error

	FollowGetList(uid string) ([]Feed, error)
	FollowURL(uid string, url string) (Feed, error)

	UnfollowURL(uid string, url string) error

	Search(query string) ([]Feed, error)
	PreviewURL(url string) (Timeline, error)

	ItemSearch(channel, query string) ([]Item, error)

	Events() (chan sse.Message, error)
}

Microsub is the main protocol that should be implemented by a backend

type Pagination

type Pagination struct {
	After  string `json:"after,omitempty"`
	Before string `json:"before,omitempty"`
}

Pagination contains information about paging

type Source

type Source struct {
	ID    string `json:"_id"`
	URL   string `json:"url"`
	Name  string `json:"name"`
	Photo string `json:"photo"`
}

Source is an Item source

type Timeline

type Timeline struct {
	Items  []Item     `json:"items"`
	Paging Pagination `json:"paging"`
}

Timeline is a combination of items and paging information

type Unread

type Unread struct {
	Type        int
	Unread      bool
	UnreadCount int
}

Unread is a special int/bool value for the JSON response

func (*Unread) HasUnread

func (unread *Unread) HasUnread() bool

HasUnread return true of there are unread items.

func (Unread) MarshalJSON

func (unread Unread) MarshalJSON() ([]byte, error)

MarshalJSON encodes an Unread value as JSON

func (Unread) String

func (unread Unread) String() string

String returns a string of the unread value

func (*Unread) UnmarshalJSON

func (unread *Unread) UnmarshalJSON(bytes []byte) error

UnmarshalJSON decodes an Unread value from JSON

Source Files

  • database.go
  • protocol.go

Jump to

Keyboard shortcuts

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