ekster/pkg/server/null.go

115 lines
3.3 KiB
Go
Raw Permalink Normal View History

/*
* Ekster is a microsub server
* Copyright (c) 2021 The Ekster authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package server
2018-02-16 21:13:01 +00:00
import (
"p83.nl/go/ekster/pkg/microsub"
"p83.nl/go/ekster/pkg/sse"
2018-02-16 21:13:01 +00:00
)
// NullBackend is the simplest possible backend
type NullBackend struct {
}
// ChannelsGetList gets no channels
func (b *NullBackend) ChannelsGetList() ([]microsub.Channel, error) {
2018-02-16 21:13:01 +00:00
return []microsub.Channel{
2019-01-03 21:06:16 +00:00
{UID: "0001", Name: "notifications", Unread: microsub.Unread{Type: microsub.UnreadBool, Unread: false}},
{UID: "0000", Name: "default", Unread: microsub.Unread{Type: microsub.UnreadCount, UnreadCount: 0}},
}, nil
2018-02-16 21:13:01 +00:00
}
// ChannelsCreate creates no channels
func (b *NullBackend) ChannelsCreate(name string) (microsub.Channel, error) {
2018-02-16 21:13:01 +00:00
return microsub.Channel{
UID: "1234",
Name: name,
}, nil
2018-02-16 21:13:01 +00:00
}
// ChannelsUpdate updates no channels
func (b *NullBackend) ChannelsUpdate(uid, name string) (microsub.Channel, error) {
2018-02-16 21:13:01 +00:00
return microsub.Channel{
UID: uid,
Name: name,
}, nil
2018-02-16 21:13:01 +00:00
}
// ChannelsDelete delets no channels
func (b *NullBackend) ChannelsDelete(uid string) error {
return nil
2018-02-16 21:13:01 +00:00
}
// TimelineGet gets no timeline
func (b *NullBackend) TimelineGet(before, after, channel string) (microsub.Timeline, error) {
2018-02-16 21:13:01 +00:00
return microsub.Timeline{
Paging: microsub.Pagination{},
2018-04-06 23:27:27 +00:00
Items: []microsub.Item{},
}, nil
2018-02-16 21:13:01 +00:00
}
2019-03-07 19:55:25 +00:00
// FollowGetList implements the follow list command
func (b *NullBackend) FollowGetList(uid string) ([]microsub.Feed, error) {
return []microsub.Feed{
{Name: "test", Type: "feed", URL: "https://example.com/"},
}, nil
2018-02-16 21:13:01 +00:00
}
2019-03-07 19:55:25 +00:00
// FollowURL follows a new url
func (b *NullBackend) FollowURL(uid string, url string) (microsub.Feed, error) {
return microsub.Feed{Type: "feed", URL: url}, nil
2018-02-16 21:13:01 +00:00
}
2019-03-07 19:55:25 +00:00
// UnfollowURL unfollows a url
func (b *NullBackend) UnfollowURL(uid string, url string) error {
return nil
2018-02-16 21:13:01 +00:00
}
2019-03-07 19:55:25 +00:00
// Search search for a query and return an example list of feeds
func (b *NullBackend) Search(query string) ([]microsub.Feed, error) {
return []microsub.Feed{
2019-03-23 19:42:13 +00:00
{Type: "feed", URL: "https://example.com/", Name: "Example", Photo: "test.jpg", Description: "test"},
}, nil
2018-02-16 21:13:01 +00:00
}
// ItemSearch returns a list of zero items
func (b *NullBackend) ItemSearch(channel, query string) ([]microsub.Item, error) {
return []microsub.Item{}, nil
}
2019-03-07 19:55:25 +00:00
// PreviewURL shows an empty feed
func (b *NullBackend) PreviewURL(url string) (microsub.Timeline, error) {
2018-02-16 21:13:01 +00:00
return microsub.Timeline{
Paging: microsub.Pagination{},
2018-04-06 23:27:27 +00:00
Items: []microsub.Item{},
}, nil
2018-02-16 21:13:01 +00:00
}
2018-03-27 22:40:04 +00:00
2019-03-07 19:55:25 +00:00
// MarkRead marks no items as read
func (b *NullBackend) MarkRead(channel string, uids []string) error {
return nil
2018-03-27 22:40:04 +00:00
}
// Events returns a closed channel.
func (b *NullBackend) Events() (chan sse.Message, error) {
ch := make(chan sse.Message)
close(ch)
return ch, nil
}