Changeset 108:50e3c368f2f3 for wokkel/muc.py
- Timestamp:
- Sep 30, 2008, 7:08:45 PM (14 years ago)
- Branch:
- wokkel-muc-client-support-24
- Convert:
- svn:b33ecbfc-034c-dc11-8662-000475d9059e/branches/wokkel-muc-client-support-24@69
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
wokkel/muc.py
r107 r108 19 19 from wokkel import disco, data_form, shim, xmppim 20 20 from wokkel.subprotocols import IQHandlerMixin, XMPPHandler 21 from wokkel.iwokkel import IMUCClient , IMUCService21 from wokkel.iwokkel import IMUCClient 22 22 23 23 # Multi User Chat namespaces 24 NS _MUC= 'http://jabber.org/protocol/muc'25 NS_ MUC_USER = NS_MUC+ '#user'26 NS_ MUC_ADMIN = NS_MUC+ '#admin'27 NS_ MUC_OWNER = NS_MUC+ '#owner'28 NS_ MUC_ROOMINFO = NS_MUC+ '#roominfo'29 NS_ MUC_CONFIG = NS_MUC+ '#roomconfig'24 NS = 'http://jabber.org/protocol/muc' 25 NS_USER = NS + '#user' 26 NS_ADMIN = NS + '#admin' 27 NS_OWNER = NS + '#owner' 28 NS_ROOMINFO = NS + '#roominfo' 29 NS_CONFIG = NS + '#roomconfig' 30 30 31 31 # ad hoc commands … … 47 47 IQ_COMMAND = IQ+'/command' 48 48 49 MUC_ADMIN = IQ_QUERY+'[@xmlns="' + NS_ MUC_ADMIN + '"]'50 MUC_OWNER = IQ_QUERY+'[@xmlns="' + NS_ MUC_OWNER + '"]'49 MUC_ADMIN = IQ_QUERY+'[@xmlns="' + NS_ADMIN + '"]' 50 MUC_OWNER = IQ_QUERY+'[@xmlns="' + NS_OWNER + '"]' 51 51 52 52 MUC_AO = MUC_ADMIN + '|' + MUC_OWNER … … 69 69 """ 70 70 def __init__(self, condition, mucCondition, feature=None, text=None): 71 appCondition = domish.Element((NS _MUC_ERRORS, mucCondition))71 appCondition = domish.Element((NS, mucCondition)) 72 72 if feature: 73 73 appCondition['feature'] = feature … … 94 94 95 95 96 96 97 class Room(object): 97 98 """ … … 124 125 125 126 # add muc elements 126 x = self.addElement('x', NS _MUC)127 x = self.addElement('x', NS) 127 128 128 129 … … 138 139 self['from'] = frm 139 140 # add muc elements 140 x = self.addElement('x', NS_ MUC_USER)141 x = self.addElement('x', NS_USER) 141 142 if affiliation: 142 143 x['affiliation'] = affiliation … … 151 152 """ 152 153 153 def __init__(self, error, to=None ):154 def __init__(self, error, to=None, frm=None): 154 155 BasicPresence.__init__(self, to, type='error') 155 156 if frm: 157 self['from'] = frm 156 158 # add muc elements 157 x = self.addElement('x', NS _MUC)159 x = self.addElement('x', NS) 158 160 # add error 159 161 self.addChild(error) … … 170 172 def connectionInitialized(self): 171 173 self.rooms = {} 172 self.xmlstream.addObserver(PRESENCE, self._onPresence) 173 self.xmlstream.addObserver(GROUPCHAT, self._onGroupChat) 174 174 175 175 176 def _setRoom(self, room): … … 179 180 return self.rooms.get(room_jid.full().lower()) 180 181 181 def _onGroupChat(self, msg):182 """handle groupchat message stanzas183 """184 185 186 def _onPresence(self, prs):187 """handle groupchat presence188 """189 x = getattr(prs, 'x', None)190 if x.uri == NS_MUC_USER:191 self.userPresence(prs)192 182 193 183 … … 196 186 """ 197 187 room_jid = jid.internJID(prs['from']) 198 print type(prs) 199 print type(d) 188 200 189 # check for errors 201 190 if prs.hasAttribute('type') and prs['type'] == 'error': 202 print room_jid.full() 203 # change the state of the room 204 r = self._getRoom(room_jid) 205 r.state = 'joined' 206 d.callback(room_jid, r) 191 d.errback(prs) 192 else: 193 # change the state of the room 194 r = self._getRoom(room_jid) 195 r.state = 'joined' 196 d.callback(r) 207 197 208 198 def userPresence(self, prs): … … 211 201 pass 212 202 213 def joinRoom(self, server, room, nick): 203 204 def _cbDisco(self, iq): 205 # grab query 206 207 return iq.query 208 209 def disco(self, entity, type='info'): 210 """Send disco queries to a XMPP entity 211 """ 212 213 iq = disco.DiscoRequest(self.xmlstream, disco.NS_INFO, 'get') 214 iq['to'] = entity 215 216 return iq.send().addCallback(self._cbDisco) 217 218 219 def join(self, server, room, nick): 214 220 """ 215 221 """ … … 224 230 # add observer for joining the room 225 231 self.xmlstream.addOnetimeObserver(PRESENCE+"[@from='%s']" % (r.entity_id.full()), 226 self._joinedRoom, d)232 self._joinedRoom, 1, d) 227 233 228 234 return d
Note: See TracChangeset
for help on using the changeset viewer.