Module: Protege::ThreadsHelper

Included in:
ApplicationHelper
Defined in:
app/helpers/protege/threads_helper.rb

Overview

View helpers for thread pages — the inbox list, compose selectors, sidebar display, and the thread detail header.

Instance Method Summary collapse

Instance Method Details

#available_persona_optionsArray<Array(String, Integer)>

Format the available personas as [label, id] pairs for a select dropdown.

Returns:

  • (Array<Array(String, Integer)>)

    option label/value pairs



24
25
26
# File 'app/helpers/protege/threads_helper.rb', line 24

def available_persona_options
  available_personas.map { |persona| ["#{persona.name} <#{persona.email_address}>", persona.id] }
end

#available_personasActiveRecord::Relation<Protege::Persona>

List the active personas eligible for the compose form.

Returns:

  • (ActiveRecord::Relation<Protege::Persona>)

    personas eligible for selection



17
18
19
# File 'app/helpers/protege/threads_helper.rb', line 17

def available_personas
  Persona.active
end

#inbox_threadsActiveRecord::Relation<Protege::EmailThread>

Fetch every EmailThread ordered by most recent activity.

Returns:



10
11
12
# File 'app/helpers/protege/threads_helper.rb', line 10

def inbox_threads
  EmailThread.order(last_message_at: :desc)
end

#thread_date(thread) ⇒ String?

Format the thread's last-activity date for sidebar display.

Parameters:

Returns:

  • (String, nil)

    the short m/d/yy date, or nil when no activity



44
45
46
# File 'app/helpers/protege/threads_helper.rb', line 44

def thread_date(thread)
  thread.last_message_at&.strftime('%-m/%-d/%y')
end

#thread_header(thread) { ... } ⇒ ActiveSupport::SafeBuffer

Render the thread detail header — subject, persona, message count, last activity, and thread ID. An optional block renders actions beside the title.

Parameters:

Yields:

  • optional content rendered to the right of the subject

Returns:

  • (ActiveSupport::SafeBuffer)

    the header markup



62
63
64
65
66
67
68
# File 'app/helpers/protege/threads_helper.rb', line 62

def thread_header(thread, &block)
  tag.div(class: 'flex-shrink-0 px-5 py-3') do
    thread_header_title(thread, &block) +
      thread_header_meta(thread) +
      thread_header_id(thread)
  end
end

#thread_preview(thread) ⇒ String

Build a one-line preview from the first line of the latest message.

Parameters:

Returns:

  • (String)

    the trimmed first line, or an em dash when empty



52
53
54
# File 'app/helpers/protege/threads_helper.rb', line 52

def thread_preview(thread)
  thread.latest_message&.text_body.to_s.lines.first.to_s.strip.presence || ''
end

#thread_title(thread) ⇒ String

Format a thread subject with its message count for sidebar display. Truncation is handled by the sidebar_item helper.

thread_title(thread) # => "Hello (3)"

Parameters:

Returns:

  • (String)

    the subject, suffixed with the count when it exceeds one



35
36
37
38
# File 'app/helpers/protege/threads_helper.rb', line 35

def thread_title(thread)
  subject = thread.subject.presence || '(no subject)'
  thread.message_count > 1 ? "#{thread.persona.name} - #{subject} (#{thread.message_count})" : subject
end