Skip to content

Commit

Permalink
fix channel transform
Browse files Browse the repository at this point in the history
  • Loading branch information
rusq committed Apr 27, 2023
1 parent 439c495 commit 2aa50c0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions internal/chunk/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ type Chunk struct {
// header
Type ChunkType `json:"t"`
Timestamp int64 `json:"ts"`
ChannelID string `json:"id"`
Count int `json:"n"` // number of messages or files
ChannelID string `json:"id,omitempty"`
Count int `json:"n,omitempty"` // number of messages or files

// the rest
IsThread bool `json:"r,omitempty"`
Expand Down
15 changes: 5 additions & 10 deletions internal/chunk/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package chunk

import (
"compress/gzip"
"encoding/json"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -112,20 +111,16 @@ func readChanInfo(rs io.ReadSeeker) ([]slack.Channel, error) {
// loadChannelsJSON loads channels json file and returns a slice of
// slack.Channel. It expects it to be GZIP compressed.
func loadChannelsJSON(fullpath string) ([]slack.Channel, error) {
cf, err := openChunks(fullpath)
f, err := openChunks(fullpath)
if err != nil {
return nil, err
}
defer cf.Close()
return readChannelsJSON(cf)
}

func readChannelsJSON(r io.Reader) ([]slack.Channel, error) {
var ch []slack.Channel
if err := json.NewDecoder(r).Decode(&ch); err != nil {
defer f.Close()
cf, err := FromReader(f)
if err != nil {
return nil, err
}
return ch, nil
return cf.AllChannels()
}

// openChunks opens an existing chunk file and returns a ReadSeekCloser. It
Expand Down
9 changes: 9 additions & 0 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,15 @@ func (cs *Stream) ListChannels(ctx context.Context, proc processor.Channels, p *
if err != nil {
return err
}

// this can happen if we're running the stream under the guest user.
// slack returns empty chunks.
if len(ch) == 0 {
if next == "" {
break
}
continue
}
if err := proc.Channels(ctx, ch); err != nil {
return err
}
Expand Down

0 comments on commit 2aa50c0

Please sign in to comment.