Skip to content

Commit

Permalink
remove debugging limit from channel listing and fix user resolve pani…
Browse files Browse the repository at this point in the history
…c for external contacts
  • Loading branch information
rusq committed Nov 3, 2021
1 parent 049a06b commit 6e43755
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
13 changes: 10 additions & 3 deletions channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ type Channels struct {
// the type of messages to fetch. See github.com/rusq/slack docs for possible
// values
func (sd *SlackDumper) getChannels(chanTypes []string) (*Channels, error) {

throttle := getThrottler(slackTier2)

if chanTypes == nil {
Expand All @@ -29,7 +28,7 @@ func (sd *SlackDumper) getChannels(chanTypes []string) (*Channels, error) {

params := &slack.GetConversationsParameters{Types: chanTypes}
allChannels := make([]slack.Channel, 0, 50)
for i := 0; i <= 2; i++ {
for {
chans, nextcur, err := sd.api.GetConversations(params)
if err != nil {
return nil, err
Expand Down Expand Up @@ -81,7 +80,7 @@ func (cs Channels) ToText(w io.Writer) (err error) {
func (sd *SlackDumper) whoThisChannelFor(channel *slack.Channel) (who string) {
switch {
case channel.IsIM:
who = "@" + sd.UserForID[channel.User].Name
who = "@" + sd.username(channel.User)
case channel.IsMpIM:
who = strings.Replace(channel.Purpose.Value, " messaging with", "", -1)
case channel.IsPrivate:
Expand All @@ -104,3 +103,11 @@ func (sd *SlackDumper) IsChannel(c string) (ok bool) {
}
return
}

func (sd *SlackDumper) username(id string) string {
user, ok := sd.UserForID[id]
if !ok {
return "<external>:" + id
}
return user.Name
}
2 changes: 1 addition & 1 deletion messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (m *Messages) GetUserForMessage(msg *slack.Message) string {
}

if userid != "" {
return m.SD.UserForID[userid].Name
return m.SD.username(userid)
}

return ""
Expand Down
4 changes: 3 additions & 1 deletion slackdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,17 @@ func New(token string, cookie string) (*SlackDumper, error) {
var chans *Channels

go func() {
defer close(errC)
var err error
chanTypes := allChanTypes
log.Println("> caching channels, might take a while...")
chans, err = sd.getChannels(chanTypes)
if err != nil {
errC <- err
}
close(errC)
}()

log.Println("> caching users...")
if _, err := sd.GetUsers(); err != nil {
return nil, fmt.Errorf("error fetching users: %s", err)
}
Expand Down

0 comments on commit 6e43755

Please sign in to comment.