2021-11-20 21:26:39 +00:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2018-12-09 16:39:36 +00:00
|
|
|
package server
|
2018-02-16 21:13:01 +00:00
|
|
|
|
|
|
|
import (
|
2018-07-28 15:52:59 +00:00
|
|
|
"p83.nl/go/ekster/pkg/microsub"
|
2019-03-24 15:21:38 +00:00
|
|
|
"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
|
2018-07-07 14:40:04 +00:00
|
|
|
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}},
|
2018-07-07 14:40:04 +00:00
|
|
|
}, nil
|
2018-02-16 21:13:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ChannelsCreate creates no channels
|
2018-07-07 14:40:04 +00:00
|
|
|
func (b *NullBackend) ChannelsCreate(name string) (microsub.Channel, error) {
|
2018-02-16 21:13:01 +00:00
|
|
|
return microsub.Channel{
|
|
|
|
UID: "1234",
|
|
|
|
Name: name,
|
2018-07-07 14:40:04 +00:00
|
|
|
}, nil
|
2018-02-16 21:13:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ChannelsUpdate updates no channels
|
2018-07-07 14:40:04 +00:00
|
|
|
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,
|
2018-07-07 14:40:04 +00:00
|
|
|
}, nil
|
2018-02-16 21:13:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ChannelsDelete delets no channels
|
2018-07-07 14:40:04 +00:00
|
|
|
func (b *NullBackend) ChannelsDelete(uid string) error {
|
|
|
|
return nil
|
2018-02-16 21:13:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TimelineGet gets no timeline
|
2018-07-07 14:40:04 +00:00
|
|
|
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{},
|
2018-07-07 14:40:04 +00:00
|
|
|
}, nil
|
2018-02-16 21:13:01 +00:00
|
|
|
}
|
|
|
|
|
2019-03-07 19:55:25 +00:00
|
|
|
// FollowGetList implements the follow list command
|
2018-07-07 14:40:04 +00:00
|
|
|
func (b *NullBackend) FollowGetList(uid string) ([]microsub.Feed, error) {
|
2018-12-09 16:39:36 +00:00
|
|
|
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
|
2018-07-07 14:40:04 +00:00
|
|
|
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
|
2018-07-07 14:40:04 +00:00
|
|
|
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
|
2018-07-07 14:40:04 +00:00
|
|
|
func (b *NullBackend) Search(query string) ([]microsub.Feed, error) {
|
2018-12-09 16:39:36 +00:00
|
|
|
return []microsub.Feed{
|
2019-03-23 19:42:13 +00:00
|
|
|
{Type: "feed", URL: "https://example.com/", Name: "Example", Photo: "test.jpg", Description: "test"},
|
2018-12-09 16:39:36 +00:00
|
|
|
}, nil
|
2018-02-16 21:13:01 +00:00
|
|
|
}
|
|
|
|
|
2021-05-30 20:01:34 +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
|
2018-07-07 14:40:04 +00:00
|
|
|
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{},
|
2018-07-07 14:40:04 +00:00
|
|
|
}, 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
|
2018-07-07 14:40:04 +00:00
|
|
|
func (b *NullBackend) MarkRead(channel string, uids []string) error {
|
|
|
|
return nil
|
2018-03-27 22:40:04 +00:00
|
|
|
}
|
2019-03-24 15:21:38 +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
|
|
|
|
}
|