Skip to content

Commit

Permalink
Fix serialization when message has reply_to_message, new_chat_partici…
Browse files Browse the repository at this point in the history
…pant or new_chat_photo #42
  • Loading branch information
leandrotoledo committed Aug 19, 2015
1 parent 80371c9 commit ba5902c
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions telegram/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ def de_json(data):
else:
left_chat_participant = None

if 'new_chat_photo' in data:
from telegram import PhotoSize
new_chat_photo = [PhotoSize.de_json(x) for x in data['new_chat_photo']]
else:
new_chat_photo = None

return Message(message_id=data.get('message_id', None),
from_user=from_user,
date=date,
Expand All @@ -194,7 +200,7 @@ def de_json(data):
new_chat_participant=new_chat_participant,
left_chat_participant=left_chat_participant,
new_chat_title=data.get('new_chat_title', None),
new_chat_photo=data.get('new_chat_photo', None),
new_chat_photo=new_chat_photo,
delete_chat_photo=data.get('delete_chat_photo', None),
group_chat_created=data.get('group_chat_created', None))

Expand All @@ -218,7 +224,7 @@ def to_dict(self):
if self.forward_from:
data['forward_from'] = self.forward_from.to_dict()
if self.reply_to_message:
data['reply_to_message'] = self.reply_to_message
data['reply_to_message'] = self.reply_to_message.to_dict()
if self.text:
data['text'] = self.text
if self.audio:
Expand All @@ -240,13 +246,13 @@ def to_dict(self):
if self.location:
data['location'] = self.location.to_dict()
if self.new_chat_participant:
data['new_chat_participant'] = self.new_chat_participant
data['new_chat_participant'] = self.new_chat_participant.to_dict()
if self.left_chat_participant:
data['left_chat_participant'] = self.left_chat_participant
data['left_chat_participant'] = self.left_chat_participant.to_dict()
if self.new_chat_title:
data['new_chat_title'] = self.new_chat_title
if self.new_chat_photo:
data['new_chat_photo'] = self.new_chat_photo
data['new_chat_photo'] = [p.to_dict() for p in self.new_chat_photo]
if self.delete_chat_photo:
data['delete_chat_photo'] = self.delete_chat_photo
if self.group_chat_created:
Expand Down

0 comments on commit ba5902c

Please sign in to comment.