Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 51 additions & 14 deletions pkg/provider/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ type ChannelsCache struct {
}

type Channel struct {
ID string `json:"id"`
Name string `json:"name"`
Topic string `json:"topic"`
Purpose string `json:"purpose"`
MemberCount int `json:"memberCount"`
IsMpIM bool `json:"mpim"`
IsIM bool `json:"im"`
IsPrivate bool `json:"private"`
ID string `json:"id"`
Name string `json:"name"`
Topic string `json:"topic"`
Purpose string `json:"purpose"`
MemberCount int `json:"memberCount"`
IsMpIM bool `json:"mpim"`
IsIM bool `json:"im"`
IsPrivate bool `json:"private"`
User string `json:"user,omitempty"` // User ID for IM channels
Members []string `json:"members,omitempty"` // Member IDs for the channel
}

type SlackAPI interface {
Expand Down Expand Up @@ -481,11 +483,26 @@ func (ap *ApiProvider) RefreshChannels(ctx context.Context) error {
zap.String("cache_file", ap.channelsCache),
zap.Error(err))
} else {
// Re-map channels with current users cache to ensure DM names are populated
usersMap := ap.ProvideUsersMap().Users
for _, c := range cachedChannels {
ap.channels[c.ID] = c
ap.channelsInv[c.Name] = c.ID
// For IM channels, re-generate the name and purpose using current users cache
if c.IsIM {
// Re-map the channel to get updated user name if available
remappedChannel := mapChannel(
c.ID, "", "", c.Topic, c.Purpose,
c.User, c.Members, c.MemberCount,
c.IsIM, c.IsMpIM, c.IsPrivate,
usersMap,
)
ap.channels[c.ID] = remappedChannel
ap.channelsInv[remappedChannel.Name] = c.ID
} else {
ap.channels[c.ID] = c
ap.channelsInv[c.Name] = c.ID
}
}
ap.logger.Info("Loaded channels from cache",
ap.logger.Info("Loaded channels from cache and re-mapped DM names",
zap.Int("count", len(cachedChannels)),
zap.String("cache_file", ap.channelsCache))
ap.channelsReady = true
Expand Down Expand Up @@ -688,14 +705,32 @@ func mapChannel(
finalTopic := topic
finalMemberCount := numMembers

var userID string
if isIM {
finalMemberCount = 2
if u, ok := usersMap[user]; ok {
userID = user // Store the user ID for later re-mapping

// If user field is empty but we have members, try to extract from members
if userID == "" && len(members) > 0 {
// For IM channels, members should contain the other user's ID
// Try each member to find a valid user in the users map
for _, memberID := range members {
if _, ok := usersMap[memberID]; ok {
userID = memberID
break
}
}
}

if u, ok := usersMap[userID]; ok {
channelName = "@" + u.Name
finalPurpose = "DM with " + u.RealName
} else if userID != "" {
channelName = "@" + userID
finalPurpose = "DM with " + userID
} else {
channelName = "@" + user
finalPurpose = "DM with " + user
channelName = "@"
finalPurpose = "DM with "
}
finalTopic = ""
} else if isMpIM {
Expand Down Expand Up @@ -726,5 +761,7 @@ func mapChannel(
IsIM: isIM,
IsMpIM: isMpIM,
IsPrivate: isPrivate,
User: userID,
Members: members,
}
}
7 changes: 7 additions & 0 deletions pkg/provider/edge/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ type IM struct {
}

func (c IM) SlackChannel() slack.Channel {
// Add Members array with just the User for IM channels
var members []string
if c.User != "" {
members = []string{c.User}
}

return slack.Channel{
GroupConversation: slack.GroupConversation{
Conversation: slack.Conversation{
Expand All @@ -112,6 +118,7 @@ func (c IM) SlackChannel() slack.Channel {
LastRead: c.LastRead.SlackString(),
},
IsArchived: c.IsArchived,
Members: members,
},
}

Expand Down
23 changes: 22 additions & 1 deletion pkg/provider/edge/client_boot.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,27 @@ type UserBootChannel struct {
}

func (c *UserBootChannel) SlackChannel() slack.Channel {
// For IM channels, extract the other user's ID from Members
// Members contains current user and the DM partner
var userID string
if c.IsIM && len(c.Members) > 0 {
// For IMs, Members typically has 2 users. We need the one that's not "self"
// Since we don't have access to self user ID here, we'll take the first member
// The API provider will handle filtering later
if len(c.Members) == 1 {
userID = c.Members[0]
} else if len(c.Members) >= 2 {
// Take the second member assuming first is often the current user
// But actually, we should take the first non-empty one
for _, member := range c.Members {
if member != "" {
userID = member
break
}
}
}
}

return slack.Channel{
GroupConversation: slack.GroupConversation{
Conversation: slack.Conversation{
Expand All @@ -152,7 +173,7 @@ func (c *UserBootChannel) SlackChannel() slack.Channel {
NameNormalized: c.NameNormalized,
NumMembers: len(c.Members),
Priority: 0,
User: "",
User: userID,
ConnectedTeamIDs: []string{},
SharedTeamIDs: []string{},
InternalTeamIDs: []string{},
Expand Down
Loading