Skip to content

Commit

Permalink
Channel pagination now uses provided value
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Barberio <[email protected]>
  • Loading branch information
insomniacslk committed Jan 25, 2021
1 parent 511ee49 commit 3cfeb31
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
12 changes: 7 additions & 5 deletions pkg/ircslack/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ import (

// Channels wraps the channel list with convenient operations and cache.
type Channels struct {
channels map[string]slack.Channel
mu sync.Mutex
channels map[string]slack.Channel
Pagination int
mu sync.Mutex
}

// NewChannels creates a new Channels object.
func NewChannels() *Channels {
func NewChannels(pagination int) *Channels {
return &Channels{
channels: make(map[string]slack.Channel),
channels: make(map[string]slack.Channel),
Pagination: pagination,
}
}

Expand All @@ -45,7 +47,7 @@ func (c *Channels) Fetch(client *slack.Client) error {
)
start := time.Now()
params := slack.GetConversationsParameters{
Limit: 100,
Limit: c.Pagination,
}
for err == nil {
chans, nextCursor, err := client.GetConversationsContext(ctx, &params)
Expand Down
8 changes: 4 additions & 4 deletions pkg/ircslack/channels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func TestChannelsNewChannels(t *testing.T) {
u := NewChannels()
u := NewChannels(100)
require.NotNil(t, u)
assert.NotNil(t, u.channels)
}
Expand Down Expand Up @@ -51,15 +51,15 @@ func (c fakeSlackHTTPClientChannels) Do(req *http.Request) (*http.Response, erro

func TestChannelsFetch(t *testing.T) {
client := slack.New("test-token", slack.OptionHTTPClient(fakeSlackHTTPClientChannels{}))
channels := NewChannels()
channels := NewChannels(100)
err := channels.Fetch(client)
require.NoError(t, err)
assert.Equal(t, 1, channels.Count())
}

func TestChannelsById(t *testing.T) {
client := slack.New("test-token", slack.OptionHTTPClient(fakeSlackHTTPClientChannels{}))
channels := NewChannels()
channels := NewChannels(100)
err := channels.Fetch(client)
require.NoError(t, err)
u := channels.ByID("1234")
Expand All @@ -70,7 +70,7 @@ func TestChannelsById(t *testing.T) {

func TestChannelsByName(t *testing.T) {
client := slack.New("test-token", slack.OptionHTTPClient(fakeSlackHTTPClientChannels{}))
channels := NewChannels()
channels := NewChannels(100)
err := channels.Fetch(client)
require.NoError(t, err)
u := channels.ByName("general")
Expand Down
2 changes: 1 addition & 1 deletion pkg/ircslack/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (s *Server) HandleMsg(conn net.Conn, msg string) {
ProxyPrefix: s.FileProxyPrefix,
},
Users: NewUsers(s.Pagination),
Channels: NewChannels(),
Channels: NewChannels(s.Pagination),
}
go ctx.Start()
UserContexts[conn.RemoteAddr()] = ctx
Expand Down

0 comments on commit 3cfeb31

Please sign in to comment.