From 28e433e4952934958a9f0aab09c256092d4bb930 Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Sat, 8 Apr 2017 11:21:27 +0100 Subject: [PATCH] Fix crash on formatting plaintext history https://github.com/tvdstaaij/telegram-history-dump/issues/79 --- formatters/plaintext.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/formatters/plaintext.rb b/formatters/plaintext.rb index d102261..0253c1a 100644 --- a/formatters/plaintext.rb +++ b/formatters/plaintext.rb @@ -11,9 +11,11 @@ def format_message(dialog, message, output_stream) line = case message['event'].downcase when 'message' - fwd_from_name = get_full_name(message['fwd_from']) - if !fwd_from_name.empty? - from_name += ' (forwarded from %s)' % fwd_from_name + if message['fwd_from'] + fwd_from_name = get_full_name(message['fwd_from']) + if !fwd_from_name.empty? + from_name += ' (forwarded from %s)' % fwd_from_name + end elsif message['reply_id'] reply_target = find_earlier_message(message['reply_id']) if reply_target @@ -49,10 +51,10 @@ def format_message(dialog, message, output_stream) end when 'service' - user = message['action']['user'] - user_name = get_full_name(user) case message['action']['type'].downcase when 'chat_add_user' + user = message['action']['user'] + user_name = get_full_name(user) if message['from']['peer_id'] == user['peer_id'] || !message['from']['peer_id'] "#{user_name} joined" @@ -62,6 +64,8 @@ def format_message(dialog, message, output_stream) when 'chat_add_user_link' "#{from_name} joined with an invite link" when 'chat_del_user' + user = message['action']['user'] + user_name = get_full_name(user) if message['from']['peer_id'] == user['peer_id'] || !message['from']['peer_id'] "#{user_name} left"