Skip to content

Commit

Permalink
extract file processing
Browse files Browse the repository at this point in the history
  • Loading branch information
rusq committed Apr 27, 2023
1 parent 22be5db commit 48a96a0
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,8 @@ func procChanMsg(ctx context.Context, proc processor.Conversations, threadC chan
},
})
}
if len(mm[i].Files) > 0 {
if err := proc.Files(ctx, channel, mm[i], false, mm[i].Files); err != nil {
return len(trs), err
}
if err := procFiles(ctx, proc, channel, false, mm[i]); err != nil {
return len(trs), err
}
}
if err := proc.Messages(ctx, channel.ID, len(trs), isLast, mm); err != nil {
Expand All @@ -474,12 +472,11 @@ func procChanMsg(ctx context.Context, proc processor.Conversations, threadC chan

func procThreadMsg(ctx context.Context, proc processor.Conversations, channel *slack.Channel, threadTS string, isLast bool, msgs []slack.Message) error {
// extract files from thread messages
for _, m := range msgs[1:] {
if len(m.Files) > 0 {
if err := proc.Files(ctx, channel, m, true, m.Files); err != nil {
return err
}
}
if len(msgs) == 0 {
return errors.New("empty messages slice")
}
if err := procFiles(ctx, proc, channel, true, msgs[1:]...); err != nil {
return err
}
// slack returns the thread starter as the first message with every
// call, so we use it as a parent message.
Expand All @@ -489,6 +486,20 @@ func procThreadMsg(ctx context.Context, proc processor.Conversations, channel *s
return nil
}

func procFiles(ctx context.Context, proc processor.Filer, channel *slack.Channel, isThread bool, msgs ...slack.Message) error {
if len(msgs) == 0 {
return nil
}
for _, m := range msgs {
if len(m.Files) > 0 {
if err := proc.Files(ctx, channel, m, isThread, m.Files); err != nil {
return err
}
}
}
return nil
}

// channelInfo fetches the channel info and passes it to the processor.
func (cs *Stream) channelInfo(ctx context.Context, proc processor.Conversations, channelID string, isThread bool) (*slack.Channel, error) {
ctx, task := trace.NewTask(ctx, "channelInfo")
Expand Down

0 comments on commit 48a96a0

Please sign in to comment.