Skip to content

Commit

Permalink
#202 channel members
Browse files Browse the repository at this point in the history
  • Loading branch information
rusq committed May 20, 2023
1 parent 90a3c3f commit 1832539
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 49 deletions.
102 changes: 67 additions & 35 deletions clienter_mock_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ require (
github.com/schollz/progressbar/v3 v3.13.0
github.com/slack-go/slack v0.12.2
github.com/stretchr/testify v1.8.2
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/term v0.7.0
golang.org/x/text v0.9.0
golang.org/x/time v0.3.0
Expand Down
3 changes: 1 addition & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ
github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rusq/chttp v1.0.1 h1:j3WE7+jQE9Rgw0E6mGMje8HxMCv09QRkKvR0oZ1R2vY=
github.com/rusq/chttp v1.0.1/go.mod h1:9H/mMp/iUc4xDkSOY0rL6ecxd/YyaW7zE9GhR+mZfRg=
github.com/rusq/chttp v1.0.2 h1:bc8FTKE/l318Kie3sb2KrGi7Fu5tSDQY+JiXMsq4fO8=
github.com/rusq/chttp v1.0.2/go.mod h1:bmuoQMUFs9fmigUmT7xbp8s0rHyzUrf7+78yLklr1so=
github.com/rusq/dlog v1.4.0 h1:64oHTSzHjzG6TXKvMbPKQzvqADCZRn6XgAWnp7ASr5k=
Expand Down Expand Up @@ -113,6 +111,7 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b
golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM=
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down
6 changes: 4 additions & 2 deletions internal/chunk/chunktype_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions slackdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,23 @@ type Session struct {
// WorkspaceInfo is an type alias for [slack.AuthTestResponse].
type WorkspaceInfo = slack.AuthTestResponse

// Slacker is the interface with some functions of slack.Client.
type Slacker interface {
// slacker is the interface with some functions of slack.Client.
type slacker interface {
AuthTestContext(context.Context) (response *slack.AuthTestResponse, err error)
GetConversationInfoContext(ctx context.Context, input *slack.GetConversationInfoInput) (*slack.Channel, error)
GetConversationHistoryContext(ctx context.Context, params *slack.GetConversationHistoryParameters) (*slack.GetConversationHistoryResponse, error)
GetConversationRepliesContext(ctx context.Context, params *slack.GetConversationRepliesParameters) (msgs []slack.Message, hasMore bool, nextCursor string, err error)
GetConversationsContext(ctx context.Context, params *slack.GetConversationsParameters) (channels []slack.Channel, nextCursor string, err error)
GetStarredContext(ctx context.Context, params slack.StarsParameters) ([]slack.StarredItem, *slack.Paging, error)
GetUsersPaginated(options ...slack.GetUsersOption) slack.UserPagination
GetUsersInConversationContext(ctx context.Context, params *slack.GetUsersInConversationParameters) ([]string, string, error)
ListBookmarks(channelID string) ([]slack.Bookmark, error)
}

// clienter is the interface with some functions of slack.Client with the sole
// purpose of mocking in tests (see client_mock.go)
type clienter interface {
Slacker
slacker
GetFile(downloadURL string, writer io.Writer) error
GetUsersContext(ctx context.Context, options ...slack.GetUsersOption) ([]slack.User, error)
GetEmojiContext(ctx context.Context) (map[string]string, error)
Expand Down
47 changes: 40 additions & 7 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/slack-go/slack"
"golang.org/x/sync/errgroup"
"golang.org/x/time/rate"

"github.com/rusq/slackdump/v2/internal/chunk/state"
Expand Down Expand Up @@ -36,7 +37,7 @@ const (
// use.
type Stream struct {
oldest, latest time.Time
client Slacker
client slacker
limits rateLimits
chanCache *chanCache
resultFn []func(sr StreamResult) error
Expand Down Expand Up @@ -133,7 +134,7 @@ func OptState(s *state.State) StreamOption {

// NewStream creates a new Stream instance that allows to stream different
// slack entities.
func NewStream(cl Slacker, l *Limits, opts ...StreamOption) *Stream {
func NewStream(cl slacker, l *Limits, opts ...StreamOption) *Stream {
cs := &Stream{
client: cl,
limits: limits(l),
Expand Down Expand Up @@ -551,13 +552,45 @@ func (cs *Stream) channelInfo(ctx context.Context, proc processor.ChannelInforme
var info *slack.Channel
if info = cs.chanCache.get(channelID); info == nil {
if err := network.WithRetry(ctx, cs.limits.channels, cs.limits.tier.Tier3.Retries, func() error {
var err error
info, err = cs.client.GetConversationInfoContext(ctx, &slack.GetConversationInfoInput{
ChannelID: channelID,
var eg errgroup.Group

eg.Go(func() error {
var err error
info, err = cs.client.GetConversationInfoContext(ctx, &slack.GetConversationInfoInput{
ChannelID: channelID,
})
if err != nil {
return fmt.Errorf("error getting channel information: %w", err)
}
return nil
})
return err

var uu []string
eg.Go(func() error {
var cursor string
for {
u, next, err := cs.client.GetUsersInConversationContext(ctx, &slack.GetUsersInConversationParameters{
ChannelID: channelID,
Cursor: cursor,
})
if err != nil {
return fmt.Errorf("error getting conversation users: %w", err)
}
uu = append(uu, u...)
if next == "" {
break
}
cursor = next
}
return nil
})
if err := eg.Wait(); err != nil {
return err
}
info.Members = uu
return nil
}); err != nil {
return nil, fmt.Errorf("error getting channel information for %s: %w", channelID, err)
return nil, fmt.Errorf("api error: %s: %w", channelID, err)
}
cs.chanCache.set(channelID, info)
}
Expand Down

0 comments on commit 1832539

Please sign in to comment.