Skip to content

Commit

Permalink
Merge branch 'master' into dump-old-to-new
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdstaaij committed Mar 12, 2017
2 parents c3df251 + 9797581 commit 2a4c966
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 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 @@ -65,7 +65,7 @@ def start_dialog(dialog, progress)
def format_message(dialog, progress, 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 @@ -83,6 +83,7 @@ def format_message(dialog, progress, msg)
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 @@ -100,7 +101,6 @@ def format_message(dialog, progress, msg)
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 @@ -128,7 +128,7 @@ def format_message(dialog, progress, msg)
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 @@ -179,6 +179,15 @@ def format_message(dialog, progress, msg)
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
14 changes: 9 additions & 5 deletions lib/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,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
Expand Down

0 comments on commit 2a4c966

Please sign in to comment.