From fb8ea7387f37d10e26127f6cab7d4b361010ac99 Mon Sep 17 00:00:00 2001 From: Haw Loeung Date: Wed, 19 Aug 2026 21:02:16 +1000 Subject: [PATCH 1/4] Add DM channel handling --- channels.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/channels.go b/channels.go index 4ff0d51..72688f6 100644 --- a/channels.go +++ b/channels.go @@ -340,6 +340,37 @@ func (m *Client) GetDMChannelName(userID1 string, userID2 string) string { return model.GetDMNameFromIds(userID1, userID2) } +const mattermostIDLen = 26 + +// GetDMUserIDs extracts the two user IDs from a direct message channel name (userID1__userID2). +// It returns ok as false if the channel name does not conform to the DM naming format. +func (m *Client) GetDMUserIDs(channelName string) (userID1, userID2 string, ok bool) { + userID1, userID2, ok = strings.Cut(channelName, "__") + if !ok || len(userID1) != mattermostIDLen || len(userID2) != mattermostIDLen { + return "", "", false + } + + return userID1, userID2, true +} + +// GetDMOtherUserID extracts the opposite participant's user ID from a DM channel name. +func (m *Client) GetDMOtherUserID(channelName, myUserID string) (string, bool) { + userID1, userID2, ok := m.GetDMUserIDs(channelName) + if !ok { + return "", false + } + + if userID1 == myUserID { + return userID2, true + } + + if userID2 == myUserID { + return userID1, true + } + + return "", false +} + //nolint:funlen,gocognit,gocyclo func (m *Client) GetChannelUsers(ctx context.Context, channelID string) ([]*model.User, error) { m.Users.mu.RLock() @@ -552,6 +583,14 @@ func (m *Client) IsChannelMember(channelID string) bool { return exists } +// IsDMChannelName reports whether the given channel name matches the Mattermost +// direct message naming convention. +func (m *Client) IsDMChannelName(channelName string) bool { + _, _, ok := m.GetDMUserIDs(channelName) + + return ok +} + func (m *Client) JoinChannel(ctx context.Context, channelID string) error { m.Users.mu.RLock() _, joined := m.Users.joinedChannels[channelID] From e4c5da81061180f2831a76d0a31b55a5d0b07337 Mon Sep 17 00:00:00 2001 From: Haw Loeung Date: Wed, 19 Aug 2026 21:05:48 +1000 Subject: [PATCH 2/4] golangci-lint fixes --- channels.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/channels.go b/channels.go index 72688f6..197f83d 100644 --- a/channels.go +++ b/channels.go @@ -344,7 +344,7 @@ const mattermostIDLen = 26 // GetDMUserIDs extracts the two user IDs from a direct message channel name (userID1__userID2). // It returns ok as false if the channel name does not conform to the DM naming format. -func (m *Client) GetDMUserIDs(channelName string) (userID1, userID2 string, ok bool) { +func (m *Client) GetDMUserIDs(channelName string) (userID1 string, userID2 string, ok bool) { userID1, userID2, ok = strings.Cut(channelName, "__") if !ok || len(userID1) != mattermostIDLen || len(userID2) != mattermostIDLen { return "", "", false From 8ba8cd47d8fbe87903b80be078f981c6ab8c5944 Mon Sep 17 00:00:00 2001 From: Haw Loeung Date: Wed, 19 Aug 2026 21:09:52 +1000 Subject: [PATCH 3/4] golangci-lint fixes --- channels.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/channels.go b/channels.go index 197f83d..dab96fa 100644 --- a/channels.go +++ b/channels.go @@ -344,7 +344,7 @@ const mattermostIDLen = 26 // GetDMUserIDs extracts the two user IDs from a direct message channel name (userID1__userID2). // It returns ok as false if the channel name does not conform to the DM naming format. -func (m *Client) GetDMUserIDs(channelName string) (userID1 string, userID2 string, ok bool) { +func (m *Client) GetDMUserIDs(channelName string) (string, string, bool) { userID1, userID2, ok = strings.Cut(channelName, "__") if !ok || len(userID1) != mattermostIDLen || len(userID2) != mattermostIDLen { return "", "", false From c881c0bbddd63fb840be0db744017adba862b877 Mon Sep 17 00:00:00 2001 From: Haw Loeung Date: Wed, 19 Aug 2026 21:12:25 +1000 Subject: [PATCH 4/4] Fixes --- channels.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/channels.go b/channels.go index dab96fa..3862df8 100644 --- a/channels.go +++ b/channels.go @@ -345,7 +345,7 @@ const mattermostIDLen = 26 // GetDMUserIDs extracts the two user IDs from a direct message channel name (userID1__userID2). // It returns ok as false if the channel name does not conform to the DM naming format. func (m *Client) GetDMUserIDs(channelName string) (string, string, bool) { - userID1, userID2, ok = strings.Cut(channelName, "__") + userID1, userID2, ok := strings.Cut(channelName, "__") if !ok || len(userID1) != mattermostIDLen || len(userID2) != mattermostIDLen { return "", "", false }