From 152002e6cc7b9df431182b74a74b083518148bef Mon Sep 17 00:00:00 2001 From: John Smith Date: Mon, 3 Jun 2019 13:17:50 +0700 Subject: Correctly add recent messages to the list --- gateway.py | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/gateway.py b/gateway.py index c3a6452..11435ce 100644 --- a/gateway.py +++ b/gateway.py @@ -499,15 +499,11 @@ class VK(object): "start_message_id": mid, "count": count}) if response: - messages.extend(response[0].get("items", [])) - # skipping count-only reponses - # if len(message) > 1: - # if isinstance(message, list): - # first = message[0] - # # removing the unread count - # if isinstance(first, (int, long)): - # message.remove(first) - # messages.extend(message) + for item in response: + item = item.get("items") + if not item: + continue + messages.extend(item) else: # not sure if that's okay # VK is totally unpredictable now @@ -527,10 +523,9 @@ class VK(object): """ if uid == 0: conversations = self.method("messages.getConversations", {"count": count, "filter": filter_}) + conversations = conversations.get("items") else: conversations = {"unread_count": 1, "1": {"conversation": {"peer": {"id": uid}}}} - if isinstance(conversations, dict): - conversations = conversations.values() peers = VK.getPeerIds(conversations, self.source) return self.getMessagesBulk(peers, count=count, mid=mid) @@ -854,10 +849,10 @@ class User(object): sendMessage(self.source, fromjid, escape("", body), date, mid=mid) if messages: newLastMsgID = messages[-1]["id"] - # if self.lastMsgID < newLastMsgID: - self.lastMsgID = newLastMsgID - runDatabaseQuery("update users set lastMsgID=? where jid=?", - (newLastMsgID, self.source), True) + if self.lastMsgID < newLastMsgID: + self.lastMsgID = newLastMsgID + runDatabaseQuery("update users set lastMsgID=? where jid=?", + (newLastMsgID, self.source), True) def updateTypingUsers(self, cTime): """ -- cgit v1.2.3