From 4cecd8e8533566743443ade2182c5bbd707c8290 Mon Sep 17 00:00:00 2001 From: Tim van der Staaij Date: Sun, 5 Mar 2017 19:48:26 +0100 Subject: [PATCH 1/2] Use title as substitute for name when a user has no name (e.g. channel) --- lib/util.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/util.rb b/lib/util.rb index f143f86..2e3ebb4 100644 --- a/lib/util.rb +++ b/lib/util.rb @@ -8,12 +8,16 @@ def get_safe_name(name) end def get_full_name(user) - return '' if !user || user['first_name'].to_s == '' - name = user['first_name'] - if $config['display_last_name'] && user['last_name'].to_s != '' - name += ' %s' % user['last_name'] + if !user['first_name'].to_s.empty? + name = user['first_name'] + if $config['display_last_name'] && user['last_name'].to_s != '' + name += ' %s' % user['last_name'] + end + return name + elsif !user['title'].to_s.empty? + return user['title'] end - name + return '' end def get_backup_dir From 97975818a1e5f01356e80d0496eee768aa2aade2 Mon Sep 17 00:00:00 2001 From: Tim van der Staaij Date: Sun, 5 Mar 2017 19:51:36 +0100 Subject: [PATCH 2/2] Show forwarded messages as forwarded in HTML formatter [#60] --- formatters/html-data/telegram-history-dump.css | 4 ++++ formatters/html.rb | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/formatters/html-data/telegram-history-dump.css b/formatters/html-data/telegram-history-dump.css index 4c26158..3bc4599 100644 --- a/formatters/html-data/telegram-history-dump.css +++ b/formatters/html-data/telegram-history-dump.css @@ -121,3 +121,7 @@ body { padding-top: 15px; } +.fwd-name { + font-style: normal; + font-weight: bold; +} diff --git a/formatters/html.rb b/formatters/html.rb index 580a6d7..a197796 100644 --- a/formatters/html.rb +++ b/formatters/html.rb @@ -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 = '
%s:
'% get_full_name(msg['from']) + author = CGI::escapeHTML(get_full_name(msg['from'])) else author = '' end @@ -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", '
') if msg['media'] and msg['media']['type'] == 'webpage' and msg['media']['description'] @@ -98,7 +99,6 @@ def format_dialog(dialog, messages) end msg_body += '
%s%s
' % [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']) @@ -126,7 +126,7 @@ def format_dialog(dialog, messages) msg_body += ">Your browser does not support inline playback.
Download #{filetype}" end end - author += '
' 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 @@ -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 #{fwd_from_name}" end + author += "#{leadin}orwarded message#{fwd_from_text}" + end + author_suffix = if author_newline then '
' else ' ' end + author = "
#{author}:
#{author_suffix}" unless author.empty? backup_file.puts("
#{author}#{msg_body}
") end