-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
do not rely on chunks in user processing.
- Loading branch information
Showing
2 changed files
with
46 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,52 @@ | ||
package dirproc | ||
|
||
import "github.com/rusq/slackdump/v2/internal/chunk" | ||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/rusq/slackdump/v2/internal/chunk" | ||
"github.com/rusq/slackdump/v2/internal/chunk/processor" | ||
"github.com/slack-go/slack" | ||
) | ||
|
||
// Users is a users processor. | ||
type Users struct { | ||
*baseproc | ||
cb func([]slack.User) error | ||
} | ||
|
||
var _ processor.Users = &Users{} | ||
|
||
type UserOption func(*Users) | ||
|
||
// WithUsers sets the users callback. | ||
func WithUsers(cb func([]slack.User) error) UserOption { | ||
return func(u *Users) { | ||
u.cb = cb | ||
} | ||
} | ||
|
||
// NewUsers creates a new Users processor. | ||
func NewUsers(cd *chunk.Directory) (*Users, error) { | ||
func NewUsers(cd *chunk.Directory, opt ...UserOption) (*Users, error) { | ||
p, err := newBaseProc(cd, "users") | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &Users{baseproc: p}, nil | ||
u := &Users{baseproc: p} | ||
for _, o := range opt { | ||
o(u) | ||
} | ||
return u, nil | ||
} | ||
|
||
func (u *Users) Users(ctx context.Context, users []slack.User) error { | ||
if err := u.baseproc.Users(ctx, users); err != nil { | ||
return err | ||
} | ||
if u.cb != nil { | ||
if err := u.cb(users); err != nil { | ||
return fmt.Errorf("users callback: %w", err) | ||
} | ||
} | ||
return nil | ||
} |