Class: Slk::Commands::Thread

Inherits:
Messages show all
Defined in:
lib/slk/commands/thread.rb

Overview

Views a message thread from a Slack URL

Instance Attribute Summary

Attributes inherited from Base

#options, #positional_args, #runner

Instance Method Summary collapse

Methods inherited from Messages

#missing_target_error, #output_messages

Methods included from Support::InlineImages

#convert_to_png, #in_tmux?, #inline_images_supported?, #iterm2_protocol_supported?, #kitty_graphics_supported?, #png_data?, #print_inline_image, #print_inline_image_with_text, #print_iterm_image, #print_kitty_image, #print_tmux_iterm_image, #print_tmux_kitty_image, #read_image_data_for_protocol, #tmux_client_is_kitty_compatible?

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Slk::Commands::Base

Instance Method Details

#executeObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/slk/commands/thread.rb', line 9

def execute
  result = validate_options
  return result if result

  resolve_and_display_thread
rescue ApiError => e
  error("Failed to fetch messages: #{e.message}")
  1
rescue ArgumentError => e
  error(e.message)
  1
end

#fetch_and_display_messages(resolved) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/slk/commands/thread.rb', line 33

def fetch_and_display_messages(resolved)
  ts = resolved.thread_ts || resolved.msg_ts
  return message_url_required_error unless ts

  api = runner.conversations_api(resolved.workspace.name)
  raw = fetch_all_thread_replies(api, resolved.channel_id, ts)
  messages = raw.map { |m| Models::Message.from_api(m, channel_id: resolved.channel_id) }

  output_messages(messages, resolved.workspace, resolved.channel_id)
  0
end

#resolve_and_display_threadObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/slk/commands/thread.rb', line 22

def resolve_and_display_thread
  target = positional_args.first
  return usage_error unless target

  parsed = Support::SlackUrlParser.new.parse(target)
  return url_required_error unless parsed&.message?

  resolved = target_resolver.resolve(target, default_workspace: target_workspaces.first)
  fetch_and_display_messages(resolved)
end