Class: Slk::Api::Threads

Inherits:
Object
  • Object
show all
Defined in:
lib/slk/api/threads.rb

Overview

Wrapper for Slack thread subscription API endpoints

Instance Method Summary collapse

Constructor Details

#initialize(api_client, workspace) ⇒ Threads

Returns a new instance of Threads.



7
8
9
10
# File 'lib/slk/api/threads.rb', line 7

def initialize(api_client, workspace)
  @api = api_client
  @workspace = workspace
end

Instance Method Details

#get_view(limit: 20) ⇒ Hash

Get unread threads

Parameters:

  • limit (Integer) (defaults to: 20)

    Max threads to return

Returns:

  • (Hash)

    Response with threads and total_unread_replies



15
16
17
# File 'lib/slk/api/threads.rb', line 15

def get_view(limit: 20)
  @api.post(@workspace, 'subscriptions.thread.getView', { limit: limit })
end

#mark(channel:, thread_ts:, timestamp:) ⇒ Object

Mark a thread as read

Parameters:

  • channel (String)

    Channel ID

  • thread_ts (String)

    Thread timestamp

  • timestamp (String)

    Latest reply timestamp to mark as read



23
24
25
26
27
28
29
# File 'lib/slk/api/threads.rb', line 23

def mark(channel:, thread_ts:, timestamp:)
  @api.post_form(@workspace, 'subscriptions.thread.mark', {
                   channel: channel,
                   thread_ts: thread_ts,
                   ts: timestamp
                 })
end

#unread_countInteger

Get unread thread count

Returns:

  • (Integer)

    Number of unread thread replies



33
34
35
36
# File 'lib/slk/api/threads.rb', line 33

def unread_count
  response = get_view(limit: 1)
  response['total_unread_replies'] || 0
end

#unreads?Boolean

Check if there are unread threads

Returns:

  • (Boolean)


40
41
42
# File 'lib/slk/api/threads.rb', line 40

def unreads?
  unread_count.positive?
end