Resolve DMs with external users by username; prefer 1:1 DM over group DM - #5
Merged
Merged
Conversation
_resolve_user only tried display_name -> real_name -> raw ID. External / Slack Connect users (e.g. HKU collaborators) often have both names empty, so their DM rendered as a bare @U... ID and carried no name to match on. A query like "yufan" then fell through to the only conversation containing the substring -- the group DM whose Slack name is mpdm-oded--peter--yufan.liu-1. - _resolve_user: fall back to the username ("name") before the raw ID. - _resolve_channel_ref: when a query matches several conversations but exactly one is a 1:1 DM, prefer it -- a person's name means their DM, not a group that happens to include them. Add a regression test covering an external-user DM alongside a same-named group DM.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
read_history(channel: "yufan")resolved to the group DM#mpdm-oded--peter--yufan.liu-1instead of the 1:1 DM with Yufan.Root cause
Yufan is an external / Slack Connect user (different team id). For such users Slack returns an empty
display_nameand emptyreal_name._resolve_useronly trieddisplay_name -> real_name -> raw ID, so his DM rendered as a bare@U0A8QJCNUNMand carried no "yufan" text to match on. The only conversation whose terms contained "yufan" was the group DM's Slack namempdm-oded--peter--yufan.liu-1, so the resolver landed there.Fix
_resolve_user: fall back to the username (name, e.g.yufan.liu) before the raw ID, so external-user DMs resolve to@yufan.liu. Also un-breaks other bare-ID DMs in the list._resolve_channel_ref: when a query matches several conversations but exactly one is a 1:1 DM, prefer it — typing a person's name means their DM, not a group that happens to include them.Test
Adds
test_prefers_direct_dm_over_group_dm_for_external_userand updates the fake client to model empty display/real names. All 6 tests pass.