Class: Slk::Services::UserMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/slk/services/user_matcher.rb

Overview

Finds all users whose name/display/real/first+last matches a query (case-insensitive). Combines users.list with previously-resolved profiles cached locally — Slack Connect external users don’t appear in users.list but do show up in the meta cache once users.info has been fetched.

Instance Method Summary collapse

Constructor Details

#initialize(api_client:, workspace:, cache_store:, on_debug: nil) ⇒ UserMatcher

Returns a new instance of UserMatcher.



10
11
12
13
14
15
# File 'lib/slk/services/user_matcher.rb', line 10

def initialize(api_client:, workspace:, cache_store:, on_debug: nil)
  @api = api_client
  @workspace = workspace
  @cache = cache_store
  @on_debug = on_debug
end

Instance Method Details

#find_all(name) ⇒ Object

Returns users.list-shaped hashes (deduped by id). Raises ApiError on network/auth failures so callers don’t conflate them with “no matches”.



19
20
21
22
23
24
25
# File 'lib/slk/services/user_matcher.rb', line 19

def find_all(name)
  return [] if name.to_s.empty? || @api.nil?

  target = name.downcase
  candidates = list_members + cached_profile_users
  unique_by_id(candidates.select { |u| matches?(u, target) })
end

#matches?(user, target_lower) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/slk/services/user_matcher.rb', line 27

def matches?(user, target_lower)
  name_candidates(user).any? { |c| c.downcase == target_lower }
end

#name_candidates(user) ⇒ Object



31
32
33
34
35
36
# File 'lib/slk/services/user_matcher.rb', line 31

def name_candidates(user)
  profile = user['profile'] || {}
  full = [profile['first_name'], profile['last_name']].compact.join(' ').strip
  [user['name'], profile['display_name'], profile['real_name'], full]
    .map(&:to_s).reject(&:empty?)
end