Move timeline backend to own package
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
5b5b344f82
commit
a23b31cefe
|
|
@ -60,19 +60,6 @@ type Debug interface {
|
||||||
Debug()
|
Debug()
|
||||||
}
|
}
|
||||||
|
|
||||||
type redisItem struct {
|
|
||||||
ID string
|
|
||||||
Published string
|
|
||||||
Read bool
|
|
||||||
Data []byte
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ri *redisItem) Item() microsub.Item {
|
|
||||||
var item microsub.Item
|
|
||||||
_ = json.Unmarshal(ri.Data, &item)
|
|
||||||
return item
|
|
||||||
}
|
|
||||||
|
|
||||||
type fetch2 struct{}
|
type fetch2 struct{}
|
||||||
|
|
||||||
func (f *fetch2) Fetch(url string) (*http.Response, error) {
|
func (f *fetch2) Fetch(url string) (*http.Response, error) {
|
||||||
|
|
@ -743,7 +730,7 @@ func (b *memoryBackend) createChannel(name string) microsub.Channel {
|
||||||
channel := microsub.Channel{
|
channel := microsub.Channel{
|
||||||
UID: uid,
|
UID: uid,
|
||||||
Name: name,
|
Name: name,
|
||||||
Unread: microsub.Unread{microsub.UnreadCount, false, 0},
|
Unread: microsub.Unread{Type: microsub.UnreadCount},
|
||||||
}
|
}
|
||||||
return channel
|
return channel
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,10 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"p83.nl/go/ekster/pkg/microsub"
|
"p83.nl/go/ekster/pkg/timeline"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TimelineBackend specifies the interface for Timeline. It supports everything that is needed
|
func (b *memoryBackend) getTimeline(channel string) timeline.Backend {
|
||||||
// for Ekster to implement the channel protocol for Microsub
|
|
||||||
type TimelineBackend interface {
|
|
||||||
Items(before, after string) (microsub.Timeline, error)
|
|
||||||
Count() (int, error)
|
|
||||||
|
|
||||||
AddItem(item microsub.Item) error
|
|
||||||
MarkRead(uids []string) error
|
|
||||||
|
|
||||||
// Not used at the moment
|
|
||||||
// MarkUnread(uids []string) error
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *memoryBackend) getTimeline(channel string) TimelineBackend {
|
|
||||||
// TODO: fetch timeline type from channel
|
|
||||||
timelineType := "sorted-set"
|
timelineType := "sorted-set"
|
||||||
if channel == "notifications" {
|
if channel == "notifications" {
|
||||||
timelineType = "stream"
|
timelineType = "stream"
|
||||||
|
|
@ -30,29 +16,5 @@ func (b *memoryBackend) getTimeline(channel string) TimelineBackend {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if timelineType == "sorted-set" {
|
return timeline.Create(channel, timelineType, b.pool)
|
||||||
timeline := &redisSortedSetTimeline{channel: channel, pool: b.pool}
|
|
||||||
err := timeline.Init()
|
|
||||||
if err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return timeline
|
|
||||||
}
|
|
||||||
if timelineType == "stream" {
|
|
||||||
timeline := &redisStreamTimeline{channel: channel, pool: b.pool}
|
|
||||||
err := timeline.Init()
|
|
||||||
if err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return timeline
|
|
||||||
}
|
|
||||||
if timelineType == "null" {
|
|
||||||
timeline := &nullTimeline{channel: channel}
|
|
||||||
err := timeline.Init()
|
|
||||||
if err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return timeline
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,3 @@
|
||||||
/*
|
|
||||||
Microsub server
|
|
||||||
Copyright (C) 2018 Peter Stuifzand
|
|
||||||
|
|
||||||
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
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
@ -82,7 +65,7 @@ func (b *NullBackend) UnfollowURL(uid string, url string) error {
|
||||||
// Search search for a query and return an example list of feeds
|
// Search search for a query and return an example list of feeds
|
||||||
func (b *NullBackend) Search(query string) ([]microsub.Feed, error) {
|
func (b *NullBackend) Search(query string) ([]microsub.Feed, error) {
|
||||||
return []microsub.Feed{
|
return []microsub.Feed{
|
||||||
{"feed", "https://example.com/", "Example", "test.jpg", "test", microsub.Card{}},
|
{Type: "feed", URL: "https://example.com/", Name: "Example", Photo: "test.jpg", Description: "test"},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package timeline
|
||||||
|
|
||||||
import "p83.nl/go/ekster/pkg/microsub"
|
import "p83.nl/go/ekster/pkg/microsub"
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package timeline
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package timeline
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
67
pkg/timeline/timeline.go
Normal file
67
pkg/timeline/timeline.go
Normal file
|
|
@ -0,0 +1,67 @@
|
||||||
|
package timeline
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"github.com/gomodule/redigo/redis"
|
||||||
|
"p83.nl/go/ekster/pkg/microsub"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Backend specifies the interface for Timeline. It supports everything that is needed
|
||||||
|
// for Ekster to implement the channel protocol for Microsub
|
||||||
|
type Backend interface {
|
||||||
|
Items(before, after string) (microsub.Timeline, error)
|
||||||
|
Count() (int, error)
|
||||||
|
|
||||||
|
AddItem(item microsub.Item) error
|
||||||
|
MarkRead(uids []string) error
|
||||||
|
|
||||||
|
// Not used at the moment
|
||||||
|
// MarkUnread(uids []string) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create creates a channel of the specfied type. Return nil when the type
|
||||||
|
// is not known.
|
||||||
|
func Create(channel, timelineType string, pool *redis.Pool) Backend {
|
||||||
|
if timelineType == "sorted-set" {
|
||||||
|
timeline := &redisSortedSetTimeline{channel: channel, pool: pool}
|
||||||
|
err := timeline.Init()
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return timeline
|
||||||
|
}
|
||||||
|
|
||||||
|
if timelineType == "stream" {
|
||||||
|
timeline := &redisStreamTimeline{channel: channel, pool: pool}
|
||||||
|
err := timeline.Init()
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return timeline
|
||||||
|
}
|
||||||
|
|
||||||
|
if timelineType == "null" {
|
||||||
|
timeline := &nullTimeline{channel: channel}
|
||||||
|
err := timeline.Init()
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return timeline
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type redisItem struct {
|
||||||
|
ID string
|
||||||
|
Published string
|
||||||
|
Read bool
|
||||||
|
Data []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ri *redisItem) Item() microsub.Item {
|
||||||
|
var item microsub.Item
|
||||||
|
_ = json.Unmarshal(ri.Data, &item)
|
||||||
|
return item
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user