Compare commits
No commits in common. "c49afabaa881871be17259c1adb16adb3e3fb53d" and "b5ec260665bc1c513f3fa11c5bc2e3d56025b8de" have entirely different histories.
c49afabaa8
...
b5ec260665
|
|
@ -374,8 +374,13 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
} else {
|
} else {
|
||||||
page.CurrentSetting = channelSetting{}
|
page.CurrentSetting = channelSetting{}
|
||||||
}
|
}
|
||||||
|
// FIXME: similar code is found in timeline.go
|
||||||
if page.CurrentSetting.ChannelType == "" {
|
if page.CurrentSetting.ChannelType == "" {
|
||||||
page.CurrentSetting.ChannelType = "postgres-stream"
|
if v.UID == "notifications" {
|
||||||
|
page.CurrentSetting.ChannelType = "stream"
|
||||||
|
} else {
|
||||||
|
page.CurrentSetting.ChannelType = "sorted-set"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
page.ExcludedTypeNames = map[string]string{
|
page.ExcludedTypeNames = map[string]string{
|
||||||
"repost": "Reposts",
|
"repost": "Reposts",
|
||||||
|
|
|
||||||
|
|
@ -290,21 +290,6 @@ func (b *memoryBackend) ChannelsDelete(uid string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *memoryBackend) removeFeed(feedID string) error {
|
|
||||||
b.lock.Lock()
|
|
||||||
for uid := range b.Channels {
|
|
||||||
feeds := b.Feeds[uid]
|
|
||||||
for i, feed := range feeds {
|
|
||||||
if feed.URL == feedID {
|
|
||||||
feeds = append(feeds[:i], feeds[i+1:]...)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
b.Feeds[uid] = feeds
|
|
||||||
}
|
|
||||||
b.lock.Unlock()
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *memoryBackend) getFeeds() map[string][]string {
|
func (b *memoryBackend) getFeeds() map[string][]string {
|
||||||
feeds := make(map[string][]string)
|
feeds := make(map[string][]string)
|
||||||
b.lock.RLock()
|
b.lock.RLock()
|
||||||
|
|
@ -847,11 +832,17 @@ func Fetch2(fetchURL string) (*http.Response, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *memoryBackend) getTimeline(channel string) timeline.Backend {
|
func (b *memoryBackend) getTimeline(channel string) timeline.Backend {
|
||||||
// Set a default timeline type if not set
|
timelineType := "sorted-set"
|
||||||
timelineType := "postgres-stream"
|
if channel == "notifications" {
|
||||||
if setting, ok := b.Settings[channel]; ok && setting.ChannelType != "" {
|
timelineType = "stream"
|
||||||
|
} else {
|
||||||
|
if setting, ok := b.Settings[channel]; ok {
|
||||||
|
if setting.ChannelType != "" {
|
||||||
timelineType = setting.ChannelType
|
timelineType = setting.ChannelType
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tl := timeline.Create(channel, timelineType, b.pool, b.database)
|
tl := timeline.Create(channel, timelineType, b.pool, b.database)
|
||||||
if tl == nil {
|
if tl == nil {
|
||||||
log.Printf("no timeline found with name %q and type %q", channel, timelineType)
|
log.Printf("no timeline found with name %q and type %q", channel, timelineType)
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gomodule/redigo/redis"
|
"github.com/gomodule/redigo/redis"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"p83.nl/go/ekster/pkg/microsub"
|
"p83.nl/go/ekster/pkg/microsub"
|
||||||
"p83.nl/go/ekster/pkg/sse"
|
"p83.nl/go/ekster/pkg/sse"
|
||||||
)
|
)
|
||||||
|
|
@ -113,110 +112,3 @@ func Test_memoryBackend_ChannelsCreate(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_memoryBackend_removeFeed(t *testing.T) {
|
|
||||||
type fields struct {
|
|
||||||
Channels map[string]microsub.Channel
|
|
||||||
Feeds map[string][]microsub.Feed
|
|
||||||
}
|
|
||||||
type args struct {
|
|
||||||
feedID string
|
|
||||||
}
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
fields fields
|
|
||||||
args args
|
|
||||||
lens map[string]int
|
|
||||||
wantErr bool
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "remove from channel 1",
|
|
||||||
fields: fields{
|
|
||||||
Channels: map[string]microsub.Channel{
|
|
||||||
"123": {UID: "channel1", Name: "Channel 1"},
|
|
||||||
"124": {UID: "channel2", Name: "Channel 2"},
|
|
||||||
},
|
|
||||||
Feeds: map[string][]microsub.Feed{
|
|
||||||
"123": {{Type: "feed", URL: "feed1", Name: "Feed1"}},
|
|
||||||
"124": {{Type: "feed", URL: "feed2", Name: "Feed2"}},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
args: args{feedID: "feed1"},
|
|
||||||
lens: map[string]int{"123": 0, "124": 1},
|
|
||||||
wantErr: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "remove from channel 2",
|
|
||||||
fields: fields{
|
|
||||||
Channels: map[string]microsub.Channel{
|
|
||||||
"123": {UID: "channel1", Name: "Channel 1"},
|
|
||||||
"124": {UID: "channel2", Name: "Channel 2"},
|
|
||||||
},
|
|
||||||
Feeds: map[string][]microsub.Feed{
|
|
||||||
"123": {{Type: "feed", URL: "feed1", Name: "Feed1"}},
|
|
||||||
"124": {{Type: "feed", URL: "feed2", Name: "Feed2"}},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
args: args{feedID: "feed2"},
|
|
||||||
lens: map[string]int{"123": 1, "124": 0},
|
|
||||||
wantErr: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "remove unknown",
|
|
||||||
fields: fields{
|
|
||||||
Channels: map[string]microsub.Channel{
|
|
||||||
"123": {UID: "channel1", Name: "Channel 1"},
|
|
||||||
"124": {UID: "channel2", Name: "Channel 2"},
|
|
||||||
},
|
|
||||||
Feeds: map[string][]microsub.Feed{
|
|
||||||
"123": {{Type: "feed", URL: "feed1", Name: "Feed1"}},
|
|
||||||
"124": {{Type: "feed", URL: "feed2", Name: "Feed2"}},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
args: args{feedID: "feed3"},
|
|
||||||
lens: map[string]int{"123": 1, "124": 1},
|
|
||||||
wantErr: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "remove from 0 channels",
|
|
||||||
fields: fields{
|
|
||||||
Channels: map[string]microsub.Channel{},
|
|
||||||
Feeds: map[string][]microsub.Feed{},
|
|
||||||
},
|
|
||||||
args: args{feedID: "feed3"},
|
|
||||||
lens: map[string]int{},
|
|
||||||
wantErr: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "remove from multiple channels",
|
|
||||||
fields: fields{
|
|
||||||
Channels: map[string]microsub.Channel{
|
|
||||||
"123": {UID: "channel1", Name: "Channel 1"},
|
|
||||||
"124": {UID: "channel2", Name: "Channel 2"},
|
|
||||||
},
|
|
||||||
Feeds: map[string][]microsub.Feed{
|
|
||||||
"123": {{Type: "feed", URL: "feed1", Name: "Feed1"}},
|
|
||||||
"124": {{Type: "feed", URL: "feed1", Name: "Feed1"}},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
args: args{feedID: "feed1"},
|
|
||||||
lens: map[string]int{"123": 0, "124": 0},
|
|
||||||
wantErr: false,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, tt := range tests {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
b := &memoryBackend{
|
|
||||||
Channels: tt.fields.Channels,
|
|
||||||
Feeds: tt.fields.Feeds,
|
|
||||||
}
|
|
||||||
if err := b.removeFeed(tt.args.feedID); (err != nil) != tt.wantErr {
|
|
||||||
t.Errorf("removeFeed() error = %v, wantErr %v", err, tt.wantErr)
|
|
||||||
}
|
|
||||||
assert.Len(t, b.Channels, len(tt.lens))
|
|
||||||
for k, v := range tt.lens {
|
|
||||||
assert.Len(t, b.Feeds[k], v)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user