Changeset 131:d72d60360630 for wokkel
- Timestamp:
- Jun 14, 2009, 8:42:38 PM (13 years ago)
- Branch:
- wokkel-muc-client-support-24
- Location:
- wokkel
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
wokkel/muc.py
r130 r131 89 89 A jid malformed error from the server. 90 90 91 92 91 """ 93 92 condition = 'modify' … … 219 218 @ivar method: Type attribute of the IQ request. Either C{'set'} or C{'get'} 220 219 @type method: C{str} 221 222 220 """ 223 221 … … 239 237 class AdminRequest(xmlstream.IQ): 240 238 """ 241 A basic admin iq request 239 A basic admin iq request. 242 240 243 241 @ivar method: Type attribute of the IQ request. Either C{'set'} or C{'get'} 244 242 @type method: C{str} 245 246 243 """ 247 244 … … 254 251 class OwnerRequest(xmlstream.IQ): 255 252 """ 256 A basic owner iq request 253 A basic owner iq request. 257 254 258 255 @ivar method: Type attribute of the IQ request. Either C{'set'} or C{'get'} 259 256 @type method: C{str} 260 261 257 """ 262 258 … … 276 272 @ivar affiliation: The affiliation type to send to room. 277 273 @type affiliation: C{str} 278 279 """ 280 281 def __init__(self, xs, method='get', affiliation='none', a_jid=None, reason=None, nick=None):274 """ 275 276 def __init__(self, xs, method='get', affiliation='none', 277 entityOrNick=None, reason=None): 282 278 AdminRequest.__init__(self, xs, method) 283 279 284 280 self.affiliation = affiliation 285 if a_jid is not None or nick is not None: 286 i = self.query.addElement('item') 287 i['affiliation'] = affiliation 288 289 if a_jid: 290 i['jid'] = a_jid.full() 291 292 if nick: 293 i['nick'] = nick 281 self.reason = reason 282 if entityOrNick: 283 self.items([entityOrNick]) 284 285 def items(self, entities=None): 286 """ 287 Set or Get the items list for this affiliation request. 288 """ 289 if entities: 290 for entityOrNick in entities: 291 item = self.query.addElement('item') 292 item['affiliation'] = self.affiliation 293 try: 294 item['jid'] = entityOrNick.full() 295 except AttributeError: 296 item['nick'] = entityOrNick 297 298 if self.reason: 299 item.addElement('reason', content=self.reason) 300 301 return self.query.elements() 302 303 304 305 class RoleRequest(AdminRequest): 306 def __init__(self, xs, method='get', role='none', 307 entityOrNick=None, reason=None): 308 AdminRequest.__init__(self, xs, method) 309 310 item = self.query.addElement('item') 311 item['role'] = role 312 try: 313 item['jid'] = entityOrNick.full() 314 except AttributeError: 315 item['nick'] = entityOrNick 294 316 295 317 if reason: 296 i.addElement('reason', None, reason) 297 298 299 def items(self, jid_list=None): 300 """ 301 Set or Get the items list for this affiliation request. 302 """ 303 if jid_list: 304 for j in jid_list: 305 i = self.query.addElement('item') 306 i['affiliation'] = self.affiliation 307 if isinstance(j, jid.JID): 308 i['jid'] = j.full() 309 else: 310 i['nick'] = j 311 312 return self.query.elements() 313 314 315 316 class RoleRequest(AdminRequest): 317 def __init__(self, xs, method='get', role='none', a_jid=None, reason=None, nick=None): 318 AdminRequest.__init__(self, xs, method) 319 i = self.query.addElement('item') 320 321 i['role'] = role 322 if a_jid: 323 i['jid'] = a_jid.full() 324 if nick: 325 i['nick'] = nick 326 327 if reason: 328 i.addElement('reason', None, reason) 318 item.addElement('reason', content=self.reason) 329 319 330 320 … … 334 324 A message stanza of type groupchat. Used to send a message to a MUC room that will be 335 325 broadcasted to people in the room. 336 337 326 """ 338 327 def __init__(self, to, body=None, subject=None, frm=None): … … 363 352 364 353 @param to: The xmpp entity you are sending this chat to. 365 @type 354 @type to: L{unicode} or L{jid.JID} 366 355 367 356 @param body: The message you are sending. 368 @type 357 @type body: L{unicode} 369 358 370 359 @param frm: The entity that is sending the message. 371 360 @param frm: L{unicode} 372 373 361 """ 374 362 domish.Element.__init__(self, (None, 'message')) … … 426 414 @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]). 427 415 @type since: L{datetime.datetime} 428 429 416 """ 430 417 attributes = ['maxchars', 'maxstanzas', 'seconds', 'since'] … … 494 481 @ivar roomJID: The JID of the occupant in the room. Generated from roomIdentifier, service, and nick. 495 482 @type roomJID: L{jid.JID} 496 497 483 """ 498 484 self.state = state … … 525 511 526 512 @param user: The user object that is being added to the room. 527 @type user: L{User} 528 513 @type user: L{User} 529 514 """ 530 515 self.roster[user.nick.lower()] = user … … 536 521 537 522 @param user: The user object to check. 538 @type user: L{User} 539 523 @type user: L{User} 540 524 """ 541 525 … … 548 532 549 533 @param nick: The nick for the user in the MUC room. 550 @type nick: L{unicode} 551 534 @type nick: L{unicode} 552 535 """ 553 536 return self.roster.get(nick.lower()) … … 559 542 560 543 @param user: The user object to check. 561 @type user: L{User} 562 544 @type user: L{User} 563 545 """ 564 546 if self.inRoster(user): … … 570 552 """ 571 553 This behaves like an object providing L{domish.IElement}. 572 573 554 """ 574 555 … … 583 564 """ 584 565 This behaves like an object providing L{domish.IElement}. 585 586 566 """ 587 567 … … 602 582 """ 603 583 This behaves like an object providing L{domish.IElement}. 604 605 584 """ 606 585 … … 647 626 """ 648 627 This behaves like an object providing L{domish.IElement}. 649 650 628 """ 651 629 … … 744 722 if not prs.hasAttribute('from'): 745 723 return 746 room _jid= jid.internJID(prs.getAttribute('from', ''))747 self._userLeavesRoom(room _jid)724 roomJID = jid.internJID(prs.getAttribute('from', '')) 725 self._userLeavesRoom(roomJID) 748 726 749 727 … … 755 733 if not prs.hasAttribute('from'): 756 734 return 757 room _jid= jid.internJID(prs.getAttribute('from', ''))735 roomJID = jid.internJID(prs.getAttribute('from', '')) 758 736 # add an error hook here? 759 self._userLeavesRoom(room _jid)737 self._userLeavesRoom(roomJID) 760 738 761 739 … … 772 750 773 751 774 def _userLeavesRoom(self, room _jid):752 def _userLeavesRoom(self, roomJID): 775 753 # when a user leaves a room we need to update it 776 room = self._getRoom(room _jid)754 room = self._getRoom(roomJID) 777 755 if room is None: 778 756 # not in the room yet 779 757 return 780 758 # check if user is in roster 781 user = room.getUser(room _jid.resource)759 user = room.getUser(roomJID.resource) 782 760 if user is None: 783 761 return … … 793 771 if not prs.hasAttribute('from'): 794 772 return 795 room _jid= jid.internJID(prs.getAttribute('from', ''))773 roomJID = jid.internJID(prs.getAttribute('from', '')) 796 774 797 775 status = getattr(prs, 'status', None) … … 799 777 800 778 # grab room 801 room = self._getRoom(room _jid)779 room = self._getRoom(roomJID) 802 780 if room is None: 803 781 # not in the room yet 804 782 return 805 user = self._changeUserStatus(room, room _jid, status, show)783 user = self._changeUserStatus(room, roomJID, status, show) 806 784 807 785 if room.inRoster(user): … … 826 804 # need to return an error here 827 805 return 828 room _jid= jid.internJID(msg.getAttribute('from', ''))829 830 room = self._getRoom(room _jid)806 roomJID = jid.internJID(msg.getAttribute('from', '')) 807 808 room = self._getRoom(roomJID) 831 809 if room is None: 832 810 # not in the room yet 833 811 return 834 user = room.getUser(room _jid.resource)812 user = room.getUser(roomJID.resource) 835 813 delay = None 836 814 # need to check for delay and x stanzas for delay namespace for backwards compatability … … 852 830 if not msg.hasAttribute('from'): 853 831 return 854 room _jid= jid.internJID(msg['from'])832 roomJID = jid.internJID(msg['from']) 855 833 856 834 # grab room 857 room = self._getRoom(room _jid)835 room = self._getRoom(roomJID) 858 836 if room is None: 859 837 # not in the room yet 860 838 return 861 839 862 self.receivedSubject(room _jid, unicode(msg.subject))840 self.receivedSubject(roomJID, unicode(msg.subject)) 863 841 864 842 … … 929 907 930 908 @param room: The room the user has joined. 931 @type 909 @type room: L{Room} 932 910 933 911 @param user: The user that joined the MUC room. 934 @type user: L{User} 935 912 @type user: L{User} 936 913 """ 937 914 pass … … 946 923 947 924 @param room: The room the user has joined. 948 @type 925 @type room: L{Room} 949 926 950 927 @param user: The user that joined the MUC room. 951 @type user: L{User} 952 928 @type user: L{User} 953 929 """ 954 930 pass … … 957 933 def userUpdatedStatus(self, room, user, show, status): 958 934 """ 959 User Presence has been received 935 User Presence has been received. 960 936 961 937 This method will need to be modified inorder for clients to 962 938 do something when this event occurs. 963 964 939 """ 965 940 pass … … 970 945 This method will need to be modified inorder for clients to 971 946 do something when this event occurs. 972 973 947 """ 974 948 pass … … 994 968 995 969 @param obj: The object to send over the wire. 996 @type 970 @type obj: L{domish.Element} or L{unicode} 997 971 998 972 @param timeout: The number of seconds to wait before the deferred is timed out. 999 @type 973 @type timeout: L{int} 1000 974 1001 975 The deferred object L{defer.Deferred} is returned. … … 1027 1001 1028 1002 1029 def configure(self, room_jid, fields=[]):1030 """ 1031 Configure a room 1032 1033 @param room_jid: The room jabber/xmpp entity id for the requested configuration form.1034 @type room_jid: L{jid.JID}1003 def configure(self, bareRoomJID, fields=[]): 1004 """ 1005 Configure a room. 1006 1007 @param bareRoomJID: The bare JID of the room. 1008 @type bareRoomJID: L{jid.JID} 1035 1009 1036 1010 @param fields: The fields we want to modify. 1037 @type fields: A L{list} or L{dataform.Field} 1038 1011 @type fields: A L{list} or L{dataform.Field} 1039 1012 """ 1040 1013 request = ConfigureRequest(self.xmlstream, method='set', fields=fields) 1041 request['to'] = room_jid1014 request['to'] = bareRoomJID 1042 1015 1043 1016 return request.send() 1044 1017 1045 1018 1046 def getConfigureForm(self, room_jid):1019 def getConfigureForm(self, bareRoomJID): 1047 1020 """ 1048 1021 Grab the configuration form from the room. This sends an iq request to the room. 1049 1022 1050 @param room_jid: The room jabber/xmpp entity id for the requested configuration form. 1051 @type room_jid: L{jid.JID} 1052 1023 @param bareRoomJID: The bare JID of the room. 1024 @type bareRoomJID: L{jid.JID} 1053 1025 """ 1054 1026 request = ConfigureRequest(self.xmlstream) 1055 request['to'] = room_jid1027 request['to'] = bareRoomJID 1056 1028 return request.send() 1057 1029 … … 1062 1034 1063 1035 @param server: The server where the room is located. 1064 @type server: L{unicode} 1036 @type server: L{unicode} 1037 1065 1038 @param room: The room name the entity is joining. 1066 @type room: L{unicode} 1039 @type room: L{unicode} 1040 1067 1041 @param nick: The nick name for the entitity joining the room. 1068 @type nick: L{unicode} 1042 @type nick: L{unicode} 1043 1069 1044 @param history: The maximum number of history stanzas you would like. 1070 1045 … … 1132 1107 @param new_nick: The nick name for the entitity joining the room. 1133 1108 @type new_nick: L{unicode} 1134 1135 1109 """ 1136 1110 … … 1163 1137 @param roomJID: The Room JID of the room to leave. 1164 1138 @type roomJID: L{jid.JID} 1165 1166 1139 """ 1167 1140 room = self._getRoom(roomJID) … … 1184 1157 1185 1158 @param roomJID: The room jabber/xmpp entity id for the requested configuration form. 1186 @type 1159 @type roomJID: L{jid.JID} 1187 1160 1188 1161 @param show: The availability of the entity. Common values are xa, available, etc 1189 @type 1162 @type show: L{unicode} 1190 1163 1191 1164 @param show: The current status of the entity. 1192 @type show: L{unicode} 1193 1165 @type show: L{unicode} 1194 1166 """ 1195 1167 room = self._getRoom(roomJID) … … 1226 1198 def groupChat(self, to, message, children=None): 1227 1199 """ 1228 Send a groupchat message 1200 Send a groupchat message. 1229 1201 """ 1230 1202 msg = GroupChat(to, body=message) … … 1233 1205 1234 1206 1235 def chat(self, room _jid, message, children=None):1207 def chat(self, roomJID, message, children=None): 1236 1208 """ 1237 1209 Send a private chat message to a user in a MUC room. … … 1239 1211 See: http://xmpp.org/extensions/xep-0045.html#privatemessage 1240 1212 1241 @param room_jid: The room entity id. 1242 @type room_jid: L{jid.JID} 1243 1244 """ 1245 1246 msg = PrivateChat(room_jid, body=message) 1213 @param roomJID: The Room JID of the other user. 1214 @type roomJID: L{jid.JID} 1215 """ 1216 1217 msg = PrivateChat(roomJID, body=message) 1247 1218 1248 1219 self._sendMessage(msg, children=children) … … 1257 1228 @param bareRoomJID: The bare JID of the room. 1258 1229 @type bareRoomJID: L{jid.JID} 1230 1259 1231 @param reason: The reason for the invite. 1260 1232 @type reason: L{unicode} 1233 1261 1234 @param invitee: The entity that is being invited. 1262 1235 @type invitee: L{jid.JID} 1263 1264 1236 """ 1265 1237 msg = InviteMessage(bareRoomJID, reason=reason, invitee=invitee) … … 1267 1239 1268 1240 1269 def password(self, room_jid, password):1241 def password(self, bareRoomJID, password): 1270 1242 """ 1271 1243 Send a password to a room so the entity can join. … … 1273 1245 See: http://xmpp.org/extensions/xep-0045.html#enter-pw 1274 1246 1275 @param room_jid: The room entity id.1276 @type room_jid: L{jid.JID}1247 @param bareRoomJID: The bare JID of the room. 1248 @type bareRoomJID: L{jid.JID} 1277 1249 1278 1250 @param password: The MUC room password. 1279 @type password: L{unicode} 1280 1281 """ 1282 p = PasswordPresence(room_jid, password) 1251 @type password: L{unicode} 1252 """ 1253 p = PasswordPresence(bareRoomJID, password) 1283 1254 1284 1255 self.xmlstream.send(p) 1285 1256 1286 1257 1287 def register(self, room_jid, fields=[]):1258 def register(self, bareRoomJID, fields=[]): 1288 1259 """ 1289 1260 Send a request to register for a room. 1290 1261 1291 @param room_jid: The room entity id.1292 @type room_jid: L{jid.JID}1262 @param bareRoomJID: The bare JID of the room. 1263 @type bareRoomJID: L{jid.JID} 1293 1264 1294 1265 @param fields: The fields you need to register. 1295 @type fields: L{list} of L{dataform.Field} 1296 1266 @type fields: L{list} of L{dataform.Field} 1297 1267 """ 1298 1268 iq = RegisterRequest(self.xmlstream, method='set', fields=fields) 1299 iq['to'] = room_jid.userhost()1269 iq['to'] = bareRoomJID.userhost() 1300 1270 return iq.send() 1301 1271 1302 1272 1303 def _getAffiliationList(self, room_jid, affiliation): 1304 # send a request for an affiliation list in a room. 1273 def _getAffiliationList(self, bareRoomJID, affiliation): 1274 """ 1275 Send a request for an affiliation list in a room. 1276 """ 1305 1277 iq = AffiliationRequest(self.xmlstream, 1306 1278 method='get', 1307 1279 affiliation=affiliation, 1308 1280 ) 1309 iq['to'] = room_jid.full()1281 iq['to'] = bareRoomJID.userhost() 1310 1282 return iq.send() 1311 1283 1312 1284 1313 def _getRoleList(self, room_jid, role): 1314 # send a role request 1285 def _getRoleList(self, bareRoomJID, role): 1286 """ 1287 Send a role request. 1288 """ 1315 1289 iq = RoleRequest(self.xmlstream, 1316 1317 1318 1319 iq['to'] = room_jid.full()1290 method='get', 1291 role=role, 1292 ) 1293 iq['to'] = bareRoomJID.full() 1320 1294 return iq.send() 1321 1295 … … 1354 1328 1355 1329 @param bareRoomJID: The bare JID of the room. 1356 @type bareRoomJID: L{jid.JID} 1357 1330 @type bareRoomJID: L{jid.JID} 1358 1331 """ 1359 1332 d = self._getAffiliationList(bareRoomJID, 'member') … … 1367 1340 1368 1341 @param bareRoomJID: The bare JID of the room. 1369 @type bareRoomJID: L{jid.JID} 1370 1342 @type bareRoomJID: L{jid.JID} 1371 1343 """ 1372 1344 d = self._getAffiliationList(bareRoomJID, 'admin') … … 1380 1352 1381 1353 @param bareRoomJID: The bare JID of the room. 1382 @type bareRoomJID: L{jid.JID} 1383 1354 @type bareRoomJID: L{jid.JID} 1384 1355 """ 1385 1356 d = self._getAffiliationList(bareRoomJID, 'outcast') … … 1393 1364 1394 1365 @param bareRoomJID: The room jabber/xmpp entity id for the requested member list. 1395 @type bareRoomJID: L{jid.JID} 1396 1366 @type bareRoomJID: L{jid.JID} 1397 1367 """ 1398 1368 d = self._getAffiliationList(bareRoomJID, 'owner') … … 1406 1376 1407 1377 @param room: The room jabber/xmpp entity id for the requested registration form. 1408 @type room: L{jid.JID} 1409 1378 @type room: L{jid.JID} 1410 1379 """ 1411 1380 iq = RegisterRequest(self.xmlstream) … … 1414 1383 1415 1384 1416 def destroy(self, room_jid, reason=None):1385 def destroy(self, bareRoomJID, reason=None, alternate=None): 1417 1386 """ 1418 1387 Destroy a room. 1419 1388 1420 @param room_jid: The room jabber/xmpp entity id.1421 @type room_jid: L{jid.JID}1422 1423 @ ivarreason: The reason we are destroying the room.1389 @param bareRoomJID: The bare JID of the room. 1390 @type bareRoomJID: L{jid.JID} 1391 1392 @param reason: The reason we are destroying the room. 1424 1393 @type reason: L{unicode} 1425 1394 1395 @param alternate: The bare JID of the room suggested as an alternate 1396 venue. 1397 @type alternate: L{jid.JID} 1398 1426 1399 """ 1427 1400 def destroyed(iq): 1428 self._removeRoom( room_jid)1401 self._removeRoom(bareRoomJID) 1429 1402 return True 1430 1403 1431 1404 iq = OwnerRequest(self.xmlstream, method='set') 1405 iq['to'] = bareRoomJID.userhost() 1432 1406 d = iq.query.addElement('destroy') 1433 d['jid'] = room_jid.userhost() 1407 1408 if alternate is not None: 1409 d['jid'] = alternate.userhost() 1434 1410 if reason is not None: 1435 1411 d.addElement('reason', None, reason) … … 1438 1414 1439 1415 1440 def subject(self, room_jid, subject):1416 def subject(self, bareRoomJID, subject): 1441 1417 """ 1442 1418 Change the subject of a MUC room. … … 1444 1420 See: http://xmpp.org/extensions/xep-0045.html#subject-mod 1445 1421 1446 @param room_jid: The room jabber/xmpp entity id.1447 @type room_jid: L{jid.JID}1422 @param bareRoomJID: The bare JID of the room. 1423 @type bareRoomJID: L{jid.JID} 1448 1424 1449 1425 @param subject: The subject you want to set. 1450 @type subject: L{unicode} 1451 1452 """ 1453 msg = GroupChat(room_jid, subject=subject) 1426 @type subject: L{unicode} 1427 """ 1428 msg = GroupChat(bareRoomJID.userhostJID(), subject=subject) 1454 1429 self.xmlstream.send(msg) 1455 1430 1456 1431 1457 def voice(self, room_jid):1432 def voice(self, bareRoomJID): 1458 1433 """ 1459 1434 Request voice for a moderated room. 1460 1435 1461 @param room_jid: The room jabber/xmpp entity id. 1462 @type room_jid: L{jid.JID} 1463 1464 """ 1465 msg = MessageVoice(to=room_jid) 1436 @param bareRoomJID: The room jabber/xmpp entity id. 1437 @type bareRoomJID: L{jid.JID} 1438 """ 1439 msg = MessageVoice(to=bareRoomJID.userhostJID()) 1466 1440 self.xmlstream.send(msg) 1467 1441 1468 1442 1469 def history(self, room_jid, message_list):1443 def history(self, bareRoomJID, messages): 1470 1444 """ 1471 1445 Send history to create a MUC based on a one on one chat. … … 1473 1447 See: http://xmpp.org/extensions/xep-0045.html#continue 1474 1448 1475 @param room_jid: The room jabber/xmpp entity id. 1476 @type room_jid: L{jid.JID} 1477 1478 @param message_list: A list of history to send to the room. 1479 @type message_list: L{list} of L{domish.Element} 1480 1481 """ 1482 1483 for m in message_list: 1484 m['type'] = 'groupchat' 1485 mto = m['to'] 1486 frm = m.getAttribute('from', None) 1487 m['to'] = room_jid.userhost() 1488 1489 d = m.addElement('delay', NS_DELAY) 1490 d['stamp'] = self._makeTimeStamp() 1491 d['from'] = mto 1492 1493 self.xmlstream.send(m) 1494 1495 1496 def _setAffiliation(self, frm, room_jid, affiliation, reason=None, a_jid=None, nick=None): 1497 # Send an affiliation request to change an entities affiliation to a MUC room. 1449 @param bareRoomJID: The room jabber/xmpp entity id. 1450 @type bareRoomJID: L{jid.JID} 1451 1452 @param messages: The history to send to the room as an ordered list of 1453 message, represented by a dictionary with the keys 1454 C{'stanza'}, holding the original stanza a 1455 L{domish.Element}, and C{'timestamp'} with the 1456 timestamp. 1457 @type messages: L{list} of L{domish.Element} 1458 """ 1459 1460 for message in messages: 1461 stanza = message['stanza'] 1462 stanza['type'] = 'groupchat' 1463 1464 delay = stanza.addElement('delay', NS_DELAY) 1465 delay['stamp'] = message['timestamp'] 1466 1467 sender = stanza.getAttribute('from', None) 1468 if sender is not None: 1469 delay['from'] = sender 1470 1471 stanza['to'] = bareRoomJID.userhost() 1472 if stanza.hasAttribute('from'): 1473 del stanza['from'] 1474 1475 self.xmlstream.send(stanza) 1476 1477 1478 def _setAffiliation(self, bareRoomJID, entityOrNick, affiliation, 1479 reason=None, sender=None): 1480 """ 1481 Send a request to change an entity's affiliation to a MUC room. 1482 """ 1498 1483 iq = AffiliationRequest(self.xmlstream, 1499 1484 method='set', 1485 entityOrNick=entityOrNick, 1500 1486 affiliation=affiliation, 1501 a_jid=a_jid,1502 nick=nick,1503 1487 reason=reason) 1504 iq['to'] = room_jid.userhost() # this is a room jid, only send to room 1505 iq['from'] = frm.full() 1488 iq['to'] = bareRoomJID.userhost() 1489 if sender is not None: 1490 iq['from'] = unicode(sender) 1491 1506 1492 return iq.send() 1507 1493 1508 1494 1509 def _setRole(self, frm, room_jid, a_jid=None, reason=None, role='none', nick=None): 1495 def _setRole(self, bareRoomJID, entityOrNick, role, 1496 reason=None, sender=None): 1510 1497 # send a role request 1511 1498 iq = RoleRequest(self.xmlstream, 1512 1499 method='set', 1513 a_jid=a_jid,1514 1500 role=role, 1515 nick=nick,1501 entityOrNick=entityOrNick, 1516 1502 reason=reason) 1517 1503 1518 iq['to'] = room_jid.userhost() # this is a room jid, only send to room 1519 iq['from'] = frm.full() 1504 iq['to'] = bareRoomJID.userhost() 1505 if sender is not None: 1506 iq['from'] = unicode(sender) 1520 1507 return iq.send() 1521 1508 1522 1509 1523 def _cbRequest(self, room_jid, iq): 1524 r = self._getRoom(room_jid) 1525 if r is None: 1526 raise NotFound 1527 1528 return r 1529 1530 1531 def modifyAffiliationList(self, frm, room_jid, jid_list, affiliation): 1510 def modifyAffiliationList(self, frm, bareRoomJID, jid_list, affiliation): 1532 1511 """ 1533 1512 Modify an affiliation list. 1534 1513 1535 1514 @param frm: The entity sending the request. 1536 @type 1537 1538 @param room_jid: The room jabber/xmpp entity id.1539 @type room_jid: L{jid.JID}1540 1541 @param jid_list: The list of jabber ids to change in a room. This can be a nick or a full jid.1542 @type 1515 @type frm: L{jid.JID} 1516 1517 @param bareRoomJID: The bare JID of the room. 1518 @type bareRoomJID: L{jid.JID} 1519 1520 @param entities: The list of entities to change in a room. This can be a nick or a full jid. 1521 @type jid_list: L{list} of L{unicode} for nicks. L{list} of L{jid.JID} for jids. 1543 1522 1544 1523 @param affiliation: The affilation to change. 1545 @type affiliation: L{unicode} 1546 1524 @type affiliation: L{unicode} 1547 1525 1548 1526 """ … … 1552 1530 ) 1553 1531 iq.items(jid_list) 1554 iq['to'] = room_jid.userhost() # this is a room jid, only send to room1532 iq['to'] = bareRoomJID.userhost() 1555 1533 iq['from'] = frm.full() 1556 1534 return iq.send() 1557 1535 1558 1536 1559 def grantVoice(self, frm, room_jid, voice_jid=None, reason=None, nick=None):1537 def grantVoice(self, bareRoomJID, nick, reason=None, sender=None): 1560 1538 """ 1561 1539 Grant voice to an entity. 1562 1540 1563 1541 @param frm: The entity sending the request. 1564 @type 1542 @type frm: L{jid.JID} 1565 1543 1566 1544 @param room_jid: The room jabber/xmpp entity id. 1567 @type 1545 @type room_jid: L{jid.JID} 1568 1546 1569 1547 @param reason: The reason for granting voice to the entity. 1570 @type 1548 @type reason: L{unicode} 1571 1549 1572 1550 @param nick: The nick name for the client in this room. 1573 @type nick: L{unicode} 1574 1575 """ 1576 return self._setRole(frm, room_jid, role='participant', a_jid=voice_jid, nick=nick, reason=reason) 1577 1578 1579 def grantVisitor(self, frm, room_jid, reason=None, nick=None): 1580 """ 1581 Change a participant to a visitor. This will disallow the entity to send messages to a moderated room. 1551 @type nick: L{unicode} 1552 """ 1553 return self._setRole(bareRoomJID, entityOrNick=nick, 1554 role='participant', 1555 reason=reason, sender=sender) 1556 1557 1558 def revokeVoice(self, bareRoomJID, nick, reason=None, sender=None): 1559 """ 1560 Revoke voice from a participant. 1561 1562 This will disallow the entity to send messages to a moderated room. 1563 1582 1564 @param frm: The entity sending the request. 1583 @type 1565 @type frm: L{jid.JID} 1584 1566 1585 1567 @param room_jid: The room jabber/xmpp entity id. 1586 @type 1568 @type room_jid: L{jid.JID} 1587 1569 1588 1570 @param reason: The reason for granting voice to the entity. 1589 @type 1571 @type reason: L{unicode} 1590 1572 1591 1573 @param nick: The nick name for the client in this room. 1592 @type 1593 1594 """1595 return self._setRole(frm, room_jid, role='visitor', reason=reason, nick=nick)1574 @type nick: L{unicode} 1575 """ 1576 return self._setRole(bareRoomJID, entityOrNick=nick, role='visitor', 1577 reason=reason, sender=sender) 1596 1578 1597 1579 … … 1601 1583 1602 1584 @param frm: The entity sending the request. 1603 @type 1585 @type frm: L{jid.JID} 1604 1586 1605 1587 @param room_jid: The room jabber/xmpp entity id. 1606 @type room_jid: L{jid.JID} 1607 1588 @type room_jid: L{jid.JID} 1608 1589 """ 1609 1590 return self._setRole(frm, room_jid, role='moderator', reason=reason, nick=nick) 1610 1591 1611 1592 1612 def ban(self, room_jid, ban_jid, frm, reason=None, nick=None):1593 def ban(self, bareRoomJID, entity, reason=None, sender=None): 1613 1594 """ 1614 1595 Ban a user from a MUC room. 1615 1596 1616 1597 @param room_jid: The room jabber/xmpp entity id. 1617 @type 1598 @type room_jid: L{jid.JID} 1618 1599 1619 1600 @param ban_jid: The room jabber/xmpp entity id. 1620 @type 1601 @type ban_jid: L{jid.JID} 1621 1602 1622 1603 @param frm: The entity sending the request. 1623 @type 1604 @type frm: L{jid.JID} 1624 1605 1625 1606 @param reason: The reason for banning the entity. 1626 @type 1607 @type reason: L{unicode} 1627 1608 1628 1609 @param nick: The nick name for the client in this room. 1629 @type 1630 1631 """1632 return self._setAffiliation(frm, room_jid, 'outcast', nick=nick, a_jid=ban_jid, reason=reason)1633 1634 1635 def kick(self, room_jid, kick_jid, frm, reason=None, nick=None):1610 @type nick: L{unicode} 1611 """ 1612 return self._setAffiliation(bareRoomJID, entity, 'outcast', 1613 reason=reason, sender=sender) 1614 1615 1616 def kick(self, bareRoomJID, entityOrNick, reason=None, sender=None): 1636 1617 """ 1637 1618 Kick a user from a MUC room. 1638 1619 1639 1620 @param room_jid: The room jabber/xmpp entity id. 1640 @type 1621 @type room_jid: L{jid.JID} 1641 1622 1642 1623 @param kick_jid: The room jabber/xmpp entity id. 1643 @type 1624 @type kick_jid: L{jid.JID} 1644 1625 1645 1626 @param frm: The entity sending the request. 1646 @type 1627 @type frm: L{jid.JID} 1647 1628 1648 1629 @param reason: The reason given for the kick. 1649 @type 1630 @type reason: L{unicode} 1650 1631 1651 1632 @param nick: The nick for the user in the MUC room. 1652 @type nick: L{unicode} 1653 1654 """ 1655 return self._setAffiliation(frm, room_jid, 'none', a_jid=kick_jid, nick=nick, reason=reason) 1633 @type nick: L{unicode} 1634 """ 1635 return self._setAffiliation(bareRoomJID, entityOrNick, 'none', reason=reason, sender=sender) -
wokkel/test/test_muc.py
r130 r131 227 227 self._createRoom() 228 228 # add user to room 229 u = muc.User(self.room_jid.resource)229 user = muc.User(self.room_jid.resource) 230 230 231 231 room = self.protocol._getRoom(self.room_jid) 232 room.addUser(u )232 room.addUser(user) 233 233 234 234 def userPresence(room, user): … … 250 250 251 251 252 d = self.protocol.ban(self.room_jid, banned, self.user_jid, reason='Spam') 252 d = self.protocol.ban(self.room_jid, banned, reason='Spam', 253 sender=self.user_jid) 253 254 d.addCallback(cb) 254 255 … … 268 269 Kick an entity from a room. 269 270 """ 270 kicked = JID('kick@jabber.org/TroubleMakger') 271 nick = 'TroubleMakger' 272 271 273 def cb(kicked): 272 274 self.failUnless(kicked, 'Did not kick user') 273 275 274 275 d = self.protocol.kick(self.room_jid, kicked, self.user_jid, reason='Spam')276 d = self.protocol.kick(self.room_jid, nick, reason='Spam', 277 sender=self.user_jid) 276 278 d.addCallback(cb) 277 279 … … 331 333 msg.addElement('thread', None, thread) 332 334 333 archive.append( msg)335 archive.append({'stanza': msg, 'timestamp': '2002-10-13T23:58:37Z'}) 334 336 335 337 msg = domish.Element((None, 'message')) … … 339 341 msg.addElement('thread', None, thread) 340 342 341 archive.append( msg)343 archive.append({'stanza': msg, 'timestamp': '2002-10-13T23:58:43Z'}) 342 344 343 345 self.protocol.history(self.room_jid, archive) … … 405 407 Client requesting voice for a room. 406 408 """ 407 self.protocol.voice(self.room_jid .userhost())409 self.protocol.voice(self.room_jid) 408 410 409 411 m = self.stub.output[-1] … … 488 490 489 491 """ 490 give_voice = JID('voice@jabber.org/TroubleMakger')492 nick = 'TroubleMakger' 491 493 def cb(give_voice): 492 494 self.failUnless(give_voice, 'Did not give voice user') 493 495 494 496 495 d = self.protocol.grantVoice(self. user_jid, self.room_jid, give_voice)497 d = self.protocol.grantVoice(self.room_jid, nick, sender=self.user_jid) 496 498 d.addCallback(cb) 497 499 … … 512 514 """ 513 515 self._createRoom() 514 r = self.protocol._getRoom(self.room_jid)515 u = muc.User(self.room_jid.resource)516 r .addUser(u)516 room = self.protocol._getRoom(self.room_jid) 517 user = muc.User(self.room_jid.resource) 518 room.addUser(user) 517 519 518 520 def cb(room): 519 521 self.assertEquals(self.test_room, room.roomIdentifier) 520 u = room.getUser(self.room_jid.resource)521 self.failUnless(u is not None, 'User not found')522 self.failUnless(u .status == 'testing MUC', 'Wrong status')523 self.failUnless(u .show == 'xa', 'Wrong show')522 user = room.getUser(self.room_jid.resource) 523 self.failUnless(user is not None, 'User not found') 524 self.failUnless(user.status == 'testing MUC', 'Wrong status') 525 self.failUnless(user.show == 'xa', 'Wrong show') 524 526 525 527 d = self.protocol.status(self.room_jid, 'xa', 'testing MUC')
Note: See TracChangeset
for help on using the changeset viewer.