diff options
author | John Smith <mrdoctorwho@gmail.com> | 2016-11-17 15:48:56 +0300 |
---|---|---|
committer | John Smith <mrdoctorwho@gmail.com> | 2016-11-17 15:48:56 +0300 |
commit | d77546bb403578bf4b4af722775c3eb9e40b1ecf (patch) | |
tree | 633a4b55f91a520437c5e475173ae9cd4f427e26 /modules | |
parent | 8f370bfda4ba731ae3a76a4ce04a03882167cb7a (diff) |
Update chat's last_used field on a presence
Diffstat (limited to 'modules')
-rw-r--r-- | modules/mod_groupchat_msg.py | 6 | ||||
-rw-r--r-- | modules/mod_groupchat_prs.py | 8 |
2 files changed, 9 insertions, 5 deletions
diff --git a/modules/mod_groupchat_msg.py b/modules/mod_groupchat_msg.py index 23223f0..77b9898 100644 --- a/modules/mod_groupchat_msg.py +++ b/modules/mod_groupchat_msg.py @@ -30,7 +30,6 @@ def incoming_message_handler(cl, msg): if not msg.getTimestamp() and body and destination == TransportID: user = Chat.getUserObject(source) creator, id, domain = Chat.getParts(source) - send = False owner_nickname = None if user: if source in getattr(user, "chats", {}): @@ -43,7 +42,7 @@ def incoming_message_handler(cl, msg): # If we don't and nick (as in settings) is tied to the chat, then we can determine who sent the message send = ((nick == owner_nickname and user.settings.tie_chat_to_nickname) or user.settings.force_vk_date_group) - createFakeChat(user, source) + chat = createFakeChat(user, source) if html and html.getTag("body"): logger.debug("groupchats: fetched xhtml image (jid: %s)" % source) try: @@ -56,7 +55,8 @@ def incoming_message_handler(cl, msg): if send: with user.sync: user.vk.sendMessage(body, id, "chat_id") - runDatabaseQuery("update groupchats set last_used=? where jid=?", (time.time(), source), set=True) + if chat.isUpdateRequired(): + updateLastUsed(chat) raise xmpp.NodeProcessed() diff --git a/modules/mod_groupchat_prs.py b/modules/mod_groupchat_prs.py index dd1954f..068e0a2 100644 --- a/modules/mod_groupchat_prs.py +++ b/modules/mod_groupchat_prs.py @@ -56,8 +56,8 @@ def handleChatPresences(source, prs): """ Makes the old users leave Args: - * source: stanza source - * prs: xmpp.Presence object + source: stanza source + prs: xmpp.Presence object """ jid = prs.getJid() or "" if "@" in jid: @@ -76,6 +76,10 @@ def handleChatPresences(source, prs): if jid != TransportID: runDatabaseQuery("update groupchats set owner=? where jid=?", (source, jid), set=True) + if chat.isUpdateRequired(): + updateLastUsed(chat) + + # TODO: don't rewrite it every time we get a presence if jid.split("/")[0] == user.source: chat.owner_nickname = prs.getFrom().getResource() runDatabaseQuery("update groupchats set nick=? where jid=? ", (chat.owner_nickname, source), set=True) |