class SmsBackupRenderer::ConversationPage

Attributes

messages[R]

Returns an Array of Message instances to be shown on this page.

Public Class Methods

build_filename(participants) click to toggle source

Returns a filename for a conversation page for the given participants, such as ‘123456789.html’. Should always return the same name for the same list of participants. The normalized addresses are used when they are numeric, but non-numeric addresses (such as email addresses) will be hex-encoded to avoid any problems with file name restrictions.

participants - an Array of Participant instances

Returns a String filename.

# File lib/sms_backup_renderer/renderer.rb, line 110
def self.build_filename(participants)
  participants.map do |participant|
    if participant.normalized_address =~ /\A\d+\z/
      participant.normalized_address
    else
      '0x' + Digest.hexencode(participant.address)
    end
  end.sort.join('_') + '.html'
end
new(output_file_path, assets_dir_path, messages) click to toggle source
Calls superclass method SmsBackupRenderer::BasePage::new
# File lib/sms_backup_renderer/renderer.rb, line 58
def initialize(output_file_path, assets_dir_path, messages)
  super(output_file_path, assets_dir_path)
  @messages = messages.sort_by(&:date_time)
end

Public Instance Methods

message_date_time_span(message, previous_message) click to toggle source
# File lib/sms_backup_renderer/renderer.rb, line 77
def message_date_time_span(message, previous_message)
  formatted = if previous_message && message.date_time.to_date == previous_message.date_time.to_date
    if message.date_time.to_time - previous_message.date_time.to_time < 600
      nil
    else
      message.date_time.strftime('%-I:%M%P')
    end
  else
    message.date_time.strftime('%A, %b %-d, %Y at %-I:%M%P %Z')
  end
  return '' unless formatted
  "<span class=\"message-date-time\">#{formatted}</span>"
end
sender_span(message, previous_message) click to toggle source
# File lib/sms_backup_renderer/renderer.rb, line 91
def sender_span(message, previous_message)
  if previous_message &&
      message.outgoing == previous_message.outgoing &&
      (message.outgoing || message.sender.normalized_address == previous_message.sender.normalized_address)
    ''
  else
    sender = message.outgoing ? 'You' : (message.sender.name || message.sender.normalized_address)
    "<span class=\"sender\">#{ERB::Util.html_escape(sender)}</span>"
  end
end
template_name() click to toggle source
# File lib/sms_backup_renderer/renderer.rb, line 63
def template_name
  'conversation.html.erb'
end
title() click to toggle source
# File lib/sms_backup_renderer/renderer.rb, line 67
def title
  messages.first.participants.reject(&:owner).map do |participant|
    if participant.name
      "#{participant.name} (#{participant.normalized_address})"
    else
      participant.normalized_address
    end
  end.sort.join(', ')
end