fritzy / SleekXMPP

Python 2.6+/3.1+ XMPP Library
http://groups.google.com/group/sleekxmpp-discussion
Other
1.1k stars 299 forks source link

groupcat_invite event patch for xep_0045 #52

Closed damium closed 13 years ago

damium commented 14 years ago

The following patch adds a new event for received xep_0045 invite messages: groupchat_invite


--- a/sleekxmpp/plugins/xep_0045.py
+++ b/sleekxmpp/plugins/xep_0045.py
@@ -128,6 +128,7 @@ class xep_0045(base.base_plugin):
                self.xmpp.stanzaPlugin(Presence, MUCPresence)
                self.xmpp.registerHandler(Callback('MUCPresence', MatchXMLMask("" % self.xmpp.default_ns), self.handle_groupchat_presence))
                self.xmpp.registerHandler(Callback('MUCMessage', MatchXMLMask("" % self.xmpp.default_ns), self.handle_groupchat_message))
+               self.xmpp.registerHandler(Callback('MUCInvite', MatchXMLMask("" % self.xmpp.default_ns), self.handle_groupchat_invite))

        def handle_groupchat_presence(self, pr):
                """ Handle a presence in a muc.
@@ -141,6 +142,13 @@ class xep_0045(base.base_plugin):
                        self.rooms[entry['room']][entry['nick']] = entry
                logging.debug("MUC presence from %s/%s : %s" % (entry['room'],entry['nick'], entry))
                self.xmpp.event("groupchat_presence", pr)
+
+       def handle_groupchat_invite(self, inv):
+               """ Handle an invite into a muc. """
+               logging.debug("MUC invite to %s from %s: %s" % (inv['from'], inv["from"], inv))
+               if inv['from'] in self.rooms.keys():
+                       return
+               self.xmpp.event("groupchat_invite", inv)

        def handle_groupchat_message(self, msg):
                """ Handle a message event in a muc.
talfonsin commented 13 years ago

This patch didn't work. In the link below you will find a modified patch working on current trunk. Please test and consider applying it to trunk.

Thanks in advance

Edited: I apoligize for the previous patch, it was wrong. The link below is a patch which works with trunk version

http://pastebin.com/u0238Ki6

legastero commented 13 years ago

Thanks for the patch!

I've added it with some slight tweaking to the develop branch.