Module: Slk::Support::UserResolver

Included in:
Commands::Catchup, Commands::Unread
Defined in:
lib/slk/support/user_resolver.rb

Overview

Shared logic for resolving user and channel names from Slack data. Include this module in commands that need to look up user/channel names.

Required Interface

Including classes must provide these methods:

  • runner: Returns the Runner instance for API access

  • cache_store: Returns the CacheStore for name lookups

  • debug(message): Logs debug messages (can be a no-op)

Instance Method Summary collapse

Instance Method Details

#extract_user_from_message(msg, workspace) ⇒ String

Extracts the user name from a message hash

Parameters:

  • msg (Hash)

    The message data from API

  • workspace (Models::Workspace)

    The workspace context

Returns:

  • (String)

    User name, user_id as fallback, or “unknown” if neither found



84
85
86
87
88
89
# File 'lib/slk/support/user_resolver.rb', line 84

def extract_user_from_message(msg, workspace)
  (msg) ||
    name_from_username(msg) ||
    name_from_cache(msg, workspace) ||
    msg['user'] || msg['bot_id'] || 'unknown'
end

#resolve_conversation_label(workspace, channel_id) ⇒ String

Resolves a channel ID to a formatted label (@username or #channel)

Parameters:

  • workspace (Models::Workspace)

    The workspace to look up in

  • channel_id (String)

    The channel ID

Returns:

  • (String)

    Formatted label like “@username” or “#channel”



74
75
76
77
78
# File 'lib/slk/support/user_resolver.rb', line 74

def resolve_conversation_label(workspace, channel_id)
  return resolve_dm_label(workspace, channel_id) if channel_id.start_with?('D')

  resolve_channel_label(workspace, channel_id)
end

#resolve_dm_user_name(workspace, channel_id, conversations) ⇒ String

Resolves a DM channel ID to the user’s display name

Parameters:

  • workspace (Models::Workspace)

    The workspace to look up in

  • channel_id (String)

    The DM channel ID (starts with D)

  • conversations (Api::Conversations)

    API client for conversation info

Returns:

  • (String)

    User name or channel ID if not found



19
20
21
22
23
24
25
26
27
# File 'lib/slk/support/user_resolver.rb', line 19

def resolve_dm_user_name(workspace, channel_id, conversations)
  user_id = get_dm_user_id(channel_id, conversations)
  return channel_id unless user_id

  lookup_user_name(workspace, user_id) || user_id
rescue ApiError => e
  debug("DM info lookup failed for #{channel_id}: #{e.message}")
  channel_id
end