Class: Slk::Commands::Messages

Inherits:
Base
  • Object
show all
Includes:
Support::InlineImages
Defined in:
lib/slk/commands/messages.rb

Overview

Reads messages from channels, DMs, or threads rubocop:disable Metrics/ClassLength

Direct Known Subclasses

Thread

Instance Attribute Summary

Attributes inherited from Base

#options, #positional_args, #runner

Instance Method Summary collapse

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

rubocop:disable Metrics/MethodLength



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/slk/commands/messages.rb', line 14

def execute
  result = validate_options
  return result if result

  target = positional_args.first
  return missing_target_error unless target

  resolved = target_resolver.resolve(target, default_workspace: target_workspaces.first)
  fetch_and_display_messages(resolved)
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



37
38
39
40
41
42
43
44
# File 'lib/slk/commands/messages.rb', line 37

def fetch_and_display_messages(resolved)
  apply_default_limit(resolved.msg_ts)
  messages = fetch_messages(resolved.workspace, resolved.channel_id, resolved.thread_ts, oldest: resolved.msg_ts)
  messages = enrich_reactions(messages, resolved.workspace, resolved.channel_id) if @options[:reaction_timestamps]

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

#missing_target_errorObject

rubocop:enable Metrics/MethodLength



32
33
34
35
# File 'lib/slk/commands/messages.rb', line 32

def missing_target_error
  error('Usage: slk messages <channel|@user|url>')
  1
end

#output_messages(messages, workspace, channel_id) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/slk/commands/messages.rb', line 46

def output_messages(messages, workspace, channel_id)
  if @options[:json]
    output_json_messages(messages, workspace, channel_id)
  else
    display_messages(messages, workspace, channel_id)
  end
end