Changeset 123:b55a7560f174
- Timestamp:
- Oct 20, 2008, 11:34:19 PM (14 years ago)
- Branch:
- wokkel-muc-client-support-24
- Convert:
- svn:b33ecbfc-034c-dc11-8662-000475d9059e/branches/wokkel-muc-client-support-24@119
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
wokkel/muc.py
r122 r123 354 354 @ivar maxchars: Limit the total number of characters in the history to "X" 355 355 (where the character count is the characters of the complete XML stanzas, not only their XML character data). 356 @ itype maxchars: L{int}356 @type maxchars: L{int} 357 357 358 358 @ivar maxstanzas: Limit the total number of messages in the history to "X". 359 @ itype mazstanzas: L{int}359 @type mazstanzas: L{int} 360 360 361 361 @ivar seconds: Send only the messages received in the last "X" seconds. 362 @ itype seconds: L{int}362 @type seconds: L{int} 363 363 364 364 @ivar since: Send only the messages received since the datetime specified (which MUST conform to the DateTime profile specified in XMPP Date and Time Profiles [14]). 365 @ itype since: L{datetime.datetime}365 @type since: L{datetime.datetime} 366 366 367 367 """ … … 536 536 class MUCClient(XMPPHandler): 537 537 """ 538 Multi-User chat client protocol. 538 Multi-User chat client protocol. This is a subclass of L{XMPPHandler} and implements L{IMUCCLient}. 539 539 540 """ 540 541 … … 548 549 549 550 def connectionInitialized(self): 551 """ This method is called when the client has successfully authenticated. 552 It initializes several xpath events to handle MUC stanzas that come in. 553 After those are initialized then the method initialized is called to signal that we have finished. 554 """ 550 555 self.xmlstream.addObserver(PRESENCE+"[not(@type) or @type='available']/x", self._onXPresence) 551 556 self.xmlstream.addObserver(PRESENCE+"[@type='unavailable']", self._onUnavailablePresence) … … 558 563 559 564 def _setRoom(self, room): 565 """Add a room to the room collection. 566 """ 560 567 self.rooms[room.entity_id.userhost().lower()] = room 561 568 562 569 def _getRoom(self, room_jid): 570 """Grab a room from the room collection. 571 """ 563 572 return self.rooms.get(room_jid.userhost().lower()) 564 573 565 574 def _removeRoom(self, room_jid): 575 """Delete a room from the room collection. 576 """ 566 577 if self.rooms.has_key(room_jid.userhost().lower()): 567 578 del self.rooms[room_jid.userhost().lower()] … … 569 580 570 581 def _onUnavailablePresence(self, prs): 571 """ 582 """ This method is called when the stanza matches the xpath observer. 583 The client has received a presence stanza with the 'type' attribute of unavailable. 584 It means a user has exited a MUC room. 572 585 """ 573 586 … … 578 591 579 592 def _onPresenceError(self, prs): 580 """ 593 """This method is called when a presence stanza with the 'type' attribute of error. 594 There are various reasons for receiving a presence error and it means that the user has left the room. 581 595 """ 582 596 if not prs.hasAttribute('from'): … … 587 601 588 602 def _getExceptionFromElement(self, stanza): 603 # find an exception based on the error stanza 589 604 muc_condition = 'exception' 590 605 … … 597 612 598 613 def _userLeavesRoom(self, room_jid): 614 # when a user leaves a room we need to update it 599 615 room = self._getRoom(room_jid) 600 616 if room is None: … … 610 626 611 627 def _onXPresence(self, prs): 612 """ 628 """ A muc presence has been received. 613 629 """ 614 630 if not prs.hasAttribute('from'): … … 906 922 907 923 def leave(self, room_jid): 908 """ 924 """Leave a MUC room. 925 926 See: http://xmpp.org/extensions/xep-0045.html#exit 927 928 @param room_jid: The room entity id you want to exit. 929 @type room_jid: L{jid.JID} 930 909 931 """ 910 932 r = self._getRoom(room_jid) … … 1001 1023 1002 1024 1025 def _getRoleList(self, room_jid, role): 1026 iq = RoleRequest(self.xmlstream, 1027 method='get', 1028 role=role, 1029 ) 1030 iq['to'] = room_jid.full() 1031 return iq.send() 1032 1033 1034 def self._setAffiliationList(self, affiliation, room_jid, iq): 1035 r = self._getRoom(room_jid) 1036 if r is not None: 1037 affiliation_list = [] 1038 setattr(r, affiliation, []) 1039 1040 for item in iq.query.elements(): 1041 nick = item.getAttribute('nick', None) 1042 entity = item.getAttribute('jid', None) 1043 u = None 1044 if nick is None and entity is None: 1045 raise Exception, 'bad attributes in item list' 1046 if nick is not None: 1047 u = room.getUser(nick) 1048 if u is None: 1049 u = User(nick, user_jid=jid.internJID(entity)) 1050 u.affiliation = 'member' 1051 1052 affiliation_list.append(u) 1053 1054 setattr(r, affiliation, affiliation_list) 1055 return r 1003 1056 1004 1057 def getMemberList(self, room_jid): … … 1009 1062 1010 1063 """ 1011 return self._getAffiliationList(room_jid, 'member') 1012 1064 d = self._getAffiliationList(room_jid, 'member') 1065 d.addCallback(self._setAffiliationList, 'members', room_jid) 1066 return d 1013 1067 1014 1068 def getAdminList(self, room_jid): … … 1019 1073 1020 1074 """ 1021 return self._getAffiliationList(room_jid, 'admin') 1075 d = self._getAffiliationList(room_jid, 'admin') 1076 d.addCallback(self._setAffiliationList, 'members', room_jid) 1077 return d 1022 1078 1023 1079 def getBanList(self, room_jid): … … 1028 1084 1029 1085 """ 1030 return self._getAffiliationList(room_jid, 'outcast') 1086 d = self._getAffiliationList(room_jid, 'outcast') 1087 d.addCallback(self._setAffiliationList, 'members', room_jid) 1088 return d 1031 1089 1032 1090 def getOwnerList(self, room_jid): … … 1037 1095 1038 1096 """ 1039 return self._getAffiliationList(room_jid, 'owner') 1040 1097 d = self._getAffiliationList(room_jid, 'owner') 1098 d.addCallback(self._setAffiliationList, 'members', room_jid) 1099 return d 1041 1100 1042 1101 def getRegisterForm(self, room): … … 1120 1179 return iq.send() 1121 1180 1181 def _cbRequest(self, room_jid, iq): 1182 r = self._getRoom(room_jid) 1183 if r is None: 1184 raise NotFound 1185 1186 return r 1187 1122 1188 def grantVoice(self, frm, room_jid, reason=None): 1123 return self._setAffiliation(frm, room_jid, 'participant', reason=reason) 1124 1189 return self._setRole(frm, room_jid, role='participant', reason=reason) 1190 1191 def grantVisitor(self, frm, room_jid, reason=None): 1192 return self._setRole(frm, room_jid, role='visitor', reason=reason) 1193 1194 def grantModerator(self, frm, room_jid, reason=None): 1195 return self._setRole(frm, room_jid, role='moderator', reason=reason) 1125 1196 1126 1197 def ban(self, to, ban_jid, frm, reason=None): 1127 1198 return self._setAffiliation(frm, to, 'outcast', a_jid=ban_jid, reason=reason) 1128 1199 1129 1130 1200 def kick(self, to, kick_jid, frm, reason=None): 1131 1201 return self._setAffiliation(frm, to, 'none', a_jid=kick_jid, reason=reason)
Note: See TracChangeset
for help on using the changeset viewer.