From 78e7841b5ef3c3e3a3ab8f008eef4c5f85b939c9 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Wed, 12 Dec 2018 22:53:23 +0100 Subject: [PATCH] Extend `MessageReaction` when encountering unknown values --- fbchat/graphql.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/fbchat/graphql.py b/fbchat/graphql.py index f130a0d..bcc3c1f 100644 --- a/fbchat/graphql.py +++ b/fbchat/graphql.py @@ -214,7 +214,16 @@ def graphql_to_message(message): rtn.timestamp = message.get('timestamp_precise') if message.get('unread') is not None: rtn.is_read = not message['unread'] - rtn.reactions = {str(r['user']['id']):MessageReaction(r['reaction']) for r in message.get('message_reactions')} + + for r in message.get('message_reactions'): + try: + reaction = MessageReaction(r['reaction']) + except ValueError: + log.warning("Failed parsing reaction {}. Extending enum.".format(r['reaction'])) + aenum.extend_enum(MessageReaction, "UNKNOWN_{}".format(r['reaction']), r['reaction']) + reaction = MessageReaction(r['reaction']) + rtn.reactions[str(r['user']['id'])] = reaction + if message.get('blob_attachments') is not None: rtn.attachments = [graphql_to_attachment(attachment) for attachment in message['blob_attachments']] # TODO: This is still missing parsing: