diff --git a/internal/chunk/file.go b/internal/chunk/file.go index f91da429..067b4470 100644 --- a/internal/chunk/file.go +++ b/internal/chunk/file.go @@ -277,6 +277,10 @@ func (f *File) AllChannelInfos() ([]slack.Channel, error) { return nil, err } for i := range chans { + if chans[i].IsArchived { + logger.Default.Debugf("skipping archived channel %s", chans[i].ID) + continue + } members, err := f.ChannelUsers(chans[i].ID) if err != nil { if errors.Is(err, ErrNotFound) { @@ -335,11 +339,13 @@ func (f *File) ChannelInfo(channelID string) (*slack.Channel, error) { if err != nil { return nil, err } - users, err := f.ChannelUsers(channelID) - if err != nil { - return nil, fmt.Errorf("failed getting channel users for %q: %w", channelID, err) + if !info.IsArchived { + users, err := f.ChannelUsers(channelID) + if err != nil { + return nil, fmt.Errorf("failed getting channel users for %q: %w", channelID, err) + } + info.Members = users } - info.Members = users return info, nil } diff --git a/internal/chunk/file_test.go b/internal/chunk/file_test.go index b7478165..d34e4c53 100644 --- a/internal/chunk/file_test.go +++ b/internal/chunk/file_test.go @@ -112,6 +112,21 @@ var testThreadsIndex = index{ "tC1234567890:1234567890.123458": []int64{619}, } +var archivedChannel = []Chunk{ + {Type: CChannelInfo, ChannelID: TestChannelID, Channel: &slack.Channel{GroupConversation: slack.GroupConversation{IsArchived: true, Conversation: slack.Conversation{ID: TestChannelID}}}}, + {Type: CMessages, ChannelID: TestChannelID, Messages: []slack.Message{ + {Msg: slack.Msg{Timestamp: "1234567890.100000", Text: "message1"}}, + {Msg: slack.Msg{Timestamp: "1234567890.200000", Text: "message2"}}, + {Msg: slack.Msg{Timestamp: "1234567890.300000", Text: "message3"}}, + {Msg: slack.Msg{Timestamp: "1234567890.400000", Text: "message4"}}, + {Msg: slack.Msg{Timestamp: "1234567890.500000", Text: "message5"}}, + }}, + {Type: CMessages, ChannelID: TestChannelID, Messages: []slack.Message{ + {Msg: slack.Msg{Timestamp: "1234567890.600000", Text: "Hello, again!"}}, + {Msg: slack.Msg{Timestamp: "1234567890.700000", Text: "And again!"}}, + }}, +} + var testChunks = []Chunk{ {Type: CChannelInfo, ChannelID: TestChannelID, Channel: &slack.Channel{GroupConversation: slack.GroupConversation{Conversation: slack.Conversation{ID: TestChannelID}}}}, {Type: CChannelUsers, ChannelID: TestChannelID, ChannelUsers: []string{"user1", "user2"}}, @@ -804,3 +819,54 @@ func TestFile_AllChannelInfoWithMembers(t *testing.T) { }) } } + +func TestFile_ChannelInfo(t *testing.T) { + chanWithUsers := *testChunks[0].Channel + chanWithUsers.Members = testChunks[1].ChannelUsers + type args struct { + channelID string + } + tests := []struct { + name string + file *File + args args + want *slack.Channel + wantErr bool + }{ + { + name: "normal channel", + file: &File{ + rs: marshalChunks(testChunks...), + idx: mkindex(marshalChunks(testChunks...)), + }, + args: args{ + channelID: TestChannelID, + }, + want: &chanWithUsers, + wantErr: false, + }, + { + name: "archived channel", + file: &File{ + rs: marshalChunks(archivedChannel...), + idx: mkindex(marshalChunks(archivedChannel...)), + }, + args: args{ + channelID: TestChannelID, + }, + want: archivedChannel[0].Channel, + wantErr: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + f := tt.file + got, err := f.ChannelInfo(tt.args.channelID) + if (err != nil) != tt.wantErr { + t.Errorf("File.ChannelInfo() error = %v, wantErr %v", err, tt.wantErr) + return + } + assert.Equal(t, tt.want, got) + }) + } +} diff --git a/internal/structures/user_index.go b/internal/structures/user_index.go index 549461f1..1a8cb0f6 100644 --- a/internal/structures/user_index.go +++ b/internal/structures/user_index.go @@ -96,6 +96,7 @@ func (idx UserIndex) IsDeleted(id string) bool { // ChannelName return the "beautified" name of the channel. func (idx UserIndex) ChannelName(ch slack.Channel) (who string) { t := ChannelType(ch) + switch t { case CIM: who = "@" + idx.Username(ch.User) @@ -106,5 +107,12 @@ func (idx UserIndex) ChannelName(ch slack.Channel) (who string) { default: who = "#" + NVL(ch.NameNormalized, ch.Name) } - return who + return who + iftrue(ch.IsArchived, " (archived)", "") +} + +func iftrue[T any](b bool, t, f T) T { + if b { + return t + } + return f }