Skip to content

Commit

Permalink
[VkLongPoll] Fix Event.user_id parsing for messages from chat
Browse files Browse the repository at this point in the history
  • Loading branch information
python273 committed Oct 4, 2018
1 parent 3f4366b commit 8ed8392
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions vk_api/longpoll.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,17 @@ def __init__(self, raw):
self.flags = None
self.extra = None
self.extra_values = None
self.type_id = None

try:
self.type = VkEventType(self.raw[0])
self._list_to_attr(self.raw[1:], EVENT_ATTRS_MAPPING[self.type])
except ValueError:
pass

if self.extra_values:
self._dict_to_attr(self.extra_values)

if self.type in PARSE_PEER_ID_EVENTS:
self._parse_peer_id()

Expand Down Expand Up @@ -380,9 +384,6 @@ def __init__(self, raw):
if self.timestamp:
self.datetime = datetime.utcfromtimestamp(self.timestamp)

if self.extra_values:
self._dict_to_attr(self.extra_values)

def _list_to_attr(self, raw, attrs):
for i in range(min(len(raw), len(attrs))):
self.__setattr__(attrs[i], raw[i])
Expand All @@ -400,8 +401,8 @@ def _parse_peer_id(self):
self.from_chat = True
self.chat_id = self.peer_id - CHAT_START_ID

if 'from' in self.attachments:
self.user_id = int(self.attachments['from'])
if self.extra_values and 'from' in self.extra_values:
self.user_id = int(self.extra_values['from'])

else: # Сообщение от/для пользователя
self.from_user = True
Expand Down

0 comments on commit 8ed8392

Please sign in to comment.