diff options
author | John Smith <mrdoctorwho@gmail.com> | 2016-11-22 13:17:40 +0300 |
---|---|---|
committer | John Smith <mrdoctorwho@gmail.com> | 2016-11-22 13:17:40 +0300 |
commit | b52b9d23e2c7ff33ac89022a374e9022dc5ddab8 (patch) | |
tree | ad4a9a4637a9d612212ccae30e766780bc1e9a2a | |
parent | f350ed3a99282e8bc232bab1ff2f468fb77d9edf (diff) |
fix invites in groupchats
-rw-r--r-- | extensions/groupchats.py | 41 | ||||
-rw-r--r-- | modules/mod_groupchat_msg.py | 3 | ||||
-rw-r--r-- | modules/mod_groupchat_prs.py | 6 |
3 files changed, 26 insertions, 24 deletions
diff --git a/extensions/groupchats.py b/extensions/groupchats.py index 5eb5e47..9b80a6d 100644 --- a/extensions/groupchats.py +++ b/extensions/groupchats.py @@ -161,7 +161,7 @@ def handleOutgoingChatMessage(user, vkChat): if not chat.created: if chat.creation_failed: return None - # we can add user, vkChat to the create() function to prevent losing or messing up the messages + # we can add user, vkChat to the create() method to prevent losing or messing up the messages chat.create(user) # read the comments above the handleMessage function if not chat.created: @@ -171,6 +171,22 @@ def handleOutgoingChatMessage(user, vkChat): return "" +def createChat(user, source): + """ + Creates a chat + Args: + user: the User object + source: the chat's jid + """ + if not hasattr(user, "chats"): + user.chats = {} + if source in user.chats: + chat = user.chats[source] + else: + user.chats[source] = chat = Chat() + return chat + + class Chat(object): """ Class used to handle multi-user dialogs @@ -247,7 +263,7 @@ class Chat(object): if not self.raw_users: vkChat = self.getVKChat(user, self.id) # getting the chat users if not vkChat and not self.invited: - logger.error("groupchats: damn vk didn't answer to the chat list"\ + logger.error("groupchats: damn vk didn't answer to the chat list " "request, starting timer to try again (jid: %s)", user.source) utils.runThread(self.initialize, (user, chat), delay=10) return False @@ -266,7 +282,7 @@ class Chat(object): def update(self, userObject, vkChat): """ Updates chat users and sends messages - Uses two users list to prevent losing anyone + Uses two user lists to prevent losing of any of them """ all_users = vkChat["chat_active"].split(",") all_users = [int(user) for user in all_users if user] @@ -317,7 +333,7 @@ class Chat(object): chat = stanza.getFrom().getStripped() if xmpp.isResultNode(stanza): self.created = True - logger.debug("groupchats: stanza \"result\" received from %s," + logger.debug("groupchats: stanza \"result\" received from %s, " "continuing initialization (jid: %s)", chat, user.source) utils.execute(self.initialize, (user, chat)) else: @@ -415,23 +431,6 @@ class Chat(object): return None -def createFakeChat(user, source): - """ - Creates a fake chat to use it before we actually know that it exists - Args: - user: the User object - source: the chat's jid - """ - if not hasattr(user, "chats"): - user.chats = {} - if source not in user.chats: - user.chats[source] = chat = Chat() - chat.invited = True # the user has joined themselves and we don't need to intvite them - else: - chat = user.chats[source] - return chat - - def updateLastUsed(chat): """ Updates the last_used field in the database diff --git a/modules/mod_groupchat_msg.py b/modules/mod_groupchat_msg.py index 77b9898..f1f2fa2 100644 --- a/modules/mod_groupchat_msg.py +++ b/modules/mod_groupchat_msg.py @@ -42,7 +42,8 @@ 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) - chat = createFakeChat(user, source) + chat = createChat(user, source) + chat.invited = True # the user has joined themselves, so we don't need to invite them if html and html.getTag("body"): logger.debug("groupchats: fetched xhtml image (jid: %s)" % source) try: diff --git a/modules/mod_groupchat_prs.py b/modules/mod_groupchat_prs.py index 068e0a2..88486b6 100644 --- a/modules/mod_groupchat_prs.py +++ b/modules/mod_groupchat_prs.py @@ -47,7 +47,7 @@ def handleChatErrors(source, prs): runDatabaseQuery("update groupchats where jid=? set nick=?", (source, chat.owner_nickname), set=True) elif error or status: - logger.debug("groupchats: presence error (error #%s, status #%s)" + logger.debug("groupchats: presence error (error #%s, status #%s) " "from source %s (jid: %s)" % (error, status, source, user.source if user else "unknown")) raise xmpp.NodeProcessed() @@ -86,7 +86,9 @@ def handleChatPresences(source, prs): raise xmpp.NodeProcessed() elif user and prs.getType() != "unavailable": - createFakeChat(user, source) + chat = createChat(user, source) + chat.invited = True # assume the user's joined themselves + @utils.safe |