Skip to content

Commit

Permalink
Pisg formatter: switch to peer ids, include 'to' and 'action' users i…
Browse files Browse the repository at this point in the history
…n usermap

Solves a problem where some user ids do not appear in the usermap in certain situations.
  • Loading branch information
tvdstaaij committed Nov 12, 2016
1 parent cdf59c2 commit cc492bd
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions formatters/pisg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,21 @@ def end_dialog(dialog)
end

def format_message(dialog, message, output_stream)
involved_users = []
involved_users << message['from'] if message['from']
if message['to'] && message['to']['peer_type'] == 'user'
involved_users << message['to']
end
if message['action'] && message['action']['user']
involved_users << message['action']['user']
end
involved_users.each do |user|
@users[user['peer_id']] = user if user['peer_id']
end

return unless message['date'] and message['from']
return if message['from']['print_name'].to_s == ''
@oldest_message_date ||= Time.at(message['date'])
@users[message['from']['id']] = message['from']
lines = message['text'].to_s.split("\n")
lines.push('') if lines.empty?
lines.reverse_each do |message_line|
Expand All @@ -51,7 +62,7 @@ def format_message(dialog, message, output_stream)

def dump_message_line(message, message_line, output_stream)
date_str = Time.at(message['date']).strftime('[%H:%M:%S] ')
user_ref = 'u' + message['from']['id'].to_s
user_ref = 'u' + message['from']['peer_id'].to_s

line = case message['event'].downcase
when 'message'
Expand All @@ -60,7 +71,7 @@ def dump_message_line(message, message_line, output_stream)
else nil end
when 'service'
target = message['action']['user']
target_ref = target ? 'u' + target['id'].to_s : ''
target_ref = target ? 'u' + target['peer_id'].to_s : ''
case message['action']['type'].downcase
when 'chat_add_user'
"*** Joins: #{target_ref} (tg@#{target_ref}.users.telegram)"
Expand Down

0 comments on commit cc492bd

Please sign in to comment.