Skip to content

Commit

Permalink
Show forwarded messages as forwarded in HTML formatter [#60]
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdstaaij committed Mar 5, 2017
1 parent 4cecd8e commit 9797581
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 4 additions & 0 deletions formatters/html-data/telegram-history-dump.css
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,7 @@ body {
padding-top: 15px;
}

.fwd-name {
font-style: normal;
font-weight: bold;
}
15 changes: 12 additions & 3 deletions formatters/html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def format_dialog(dialog, messages)
messages.reverse_each do |msg|
if not msg['out'] and dialog['type'] != 'user'
# If this is an incoming message in a group chat, display the author
author = '<div class=author>%s:</div>'% get_full_name(msg['from'])
author = CGI::escapeHTML(get_full_name(msg['from']))
else
author = ''
end
Expand All @@ -81,6 +81,7 @@ def format_dialog(dialog, messages)
end

msg_body = ''
author_newline = false
if msg['text']
msg_body = replace_urls(msg['text']).gsub("\n", '<br>')
if msg['media'] and msg['media']['type'] == 'webpage' and msg['media']['description']
Expand All @@ -98,7 +99,6 @@ def format_dialog(dialog, messages)
end
msg_body += '<div class="webpage">%s%s</div>' % [title, description]
end
author += ' ' if author != '' # In text messages (unlike media), author is followed by a space, not a new line
elsif msg['media'] and msg['media']['file']
relative_url = URI.escape(File.join("../../media", safe_name, File.basename(msg['media']['file'])))
extension = File.extname(msg['media']['file'])
Expand Down Expand Up @@ -126,7 +126,7 @@ def format_dialog(dialog, messages)
msg_body += ">Your browser does not support inline playback.</#{filetype}><br><a href='#{relative_url}'>Download #{filetype}</a>"
end
end
author += '<br>' if author != '' # In file messages (unlike text messages), author is followed by a new line
author_newline = true
elsif msg['media'] and msg['media']['type'] == 'geo'
lat = msg['media']['latitude'].to_s
lon = msg['media']['longitude'].to_s
Expand Down Expand Up @@ -177,6 +177,15 @@ def format_dialog(dialog, messages)
end
if msg_body != ''
in_out = (msg['out'] ? 'out' : 'in')
fwd_from_name = msg['fwd_from'] ? CGI::escapeHTML(get_full_name(msg['fwd_from'])) : nil
if fwd_from_name
author_newline = true
leadin = if author.empty? then 'F' else ' f' end
fwd_from_text = if fwd_from_name.empty? then '' else " from <span class=\"fwd-name\">#{fwd_from_name}</span>" end
author += "#{leadin}orwarded message#{fwd_from_text}"
end
author_suffix = if author_newline then '<br>' else ' ' end
author = "<div class=\"author\">#{author}:</div>#{author_suffix}" unless author.empty?
backup_file.puts("<div class='msg #{in_out}' title='#{date}'>#{author}#{msg_body}</div>")
end

Expand Down

0 comments on commit 9797581

Please sign in to comment.