diff options
author | John Smith <mrdoctorwho@gmail.com> | 2018-07-10 12:07:37 +0300 |
---|---|---|
committer | John Smith <mrdoctorwho@gmail.com> | 2018-07-10 12:07:37 +0300 |
commit | 55826a3503bf6ad5f70574a3125a34999ef0bb2d (patch) | |
tree | 3fc2a680759fe6d0846961c1f4f294fe02371b23 | |
parent | a230674edd7c730b70e6441d0205c0dcb4255781 (diff) |
attempt to fix offline message reception; add getMessagesBulk method code
-rw-r--r-- | gateway.py | 18 | ||||
-rw-r--r-- | js/getMessagesBulk.js | 14 |
2 files changed, 24 insertions, 8 deletions
@@ -482,11 +482,11 @@ class VK(object): if mid: mid -= 20 # preventing message loss; receiving last 20 messages before the current one if uid == 0: - conversations = self.method("messages.getConversations", {"filters": "unread", "start_message_id": mid, "count": count}) + conversations = self.method("messages.getConversations", {"filters": "unread", "count": count}) else: conversations = {"unread_count": 1, "1": {"conversation": {"peer": {"id": uid}}}} messages = [] - # what a horrible decision to have two different data types in the response + # what a horrible decision to have two different data types in the response? if isinstance(conversations, dict): unreadCount = conversations.get("unread_count", 0) if unreadCount > 0: @@ -752,9 +752,9 @@ class User(object): return None messages = sorted([message[1] for message in messages], sortMsg) for message in messages: - # If message wasn'tsent by our user - # and not message["read_state"] - if not message["out"] : + # If message wasn't sent by our user + # and not message["read_state"] + if not message["out"]: Stats["msgin"] += 1 frm = message["uid"] if frm in self.typing: @@ -780,9 +780,11 @@ class User(object): date = message["date"] sendMessage(self.source, fromjid, escape("", body), date) if messages: - self.lastMsgID = messages[-1]["mid"] - runDatabaseQuery("update users set lastMsgID=? where jid=?", - (self.lastMsgID, self.source), True) + newLastMsgID = messages[-1]["mid"] + if self.lastMsgID < newLastMsgID: + self.lastMsgID = newLastMsgID + runDatabaseQuery("update users set lastMsgID=? where jid=?", + (newLastMsgID, self.source), True) def updateTypingUsers(self, cTime): """ diff --git a/js/getMessagesBulk.js b/js/getMessagesBulk.js new file mode 100644 index 0000000..b1aaac1 --- /dev/null +++ b/js/getMessagesBulk.js @@ -0,0 +1,14 @@ +var users = Args.users.split(","); +var startMessageId = Args.start_message_id; +if (startMessageId == null) { + startMessageId = 0; +} +var history = []; +var length = users.length; +while (length > 0) { + var uid = users[length - 1]; + var userHistory = API.messages.getHistory({"user_id": uid, "start_message_id": startMessageId}); + history.push(userHistory); + length = length - 1; +} +return history;
\ No newline at end of file |