Changeset 162:8bffd58d7b6d


Ignore:
Timestamp:
Jan 8, 2012, 9:26:06 AM (8 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Message:

Expose locked state of a room on join response with room created status.

When the presence in response to a join includes the room created status code
(201), the client should configure the room before it can be used. To enable
this, the locked state of the room is now exposed through the Room.locked
attribute.

Also, update example MUC client to deal with newly created, locked rooms.

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • doc/examples/muc_client.tac

    r156 r162  
    1616
    1717from twisted.application import service
     18from twisted.python import log
    1819from twisted.words.protocols.jabber.jid import JID
    1920from wokkel.client import XMPPClient
     
    4243        """
    4344        Once authorized, join the room.
     45
     46        If the join action causes a new room to be created, the room will be
     47        locked until configured. Here we will just accept the default
     48        configuration by submitting an empty form using L{configure}, which
     49        usually results in a public non-persistent room.
     50
     51        Alternatively, you would use L{getConfiguration} to retrieve the
     52        configuration form, and then submit the filled in form with the
     53        required settings using L{configure}, possibly after presenting it to
     54        an end-user.
    4455        """
     56        def joinedRoom(room):
     57            if room.locked:
     58                # Just accept the default configuration.
     59                return self.configure(room.roomJID, {})
     60
    4561        MUCClient.connectionInitialized(self)
    46         self.join(self.roomJID, self.nick)
     62
     63        d = self.join(self.roomJID, self.nick)
     64        d.addCallback(joinedRoom)
     65        d.addCallback(lambda _: log.msg("Joined room"))
     66        d.addErrback(log.err, "Join failed")
     67
    4768
    4869    def receivedGroupChat(self, room, user, message):
  • wokkel/muc.py

    r161 r162  
    11341134    @type nick: C{unicode}
    11351135
    1136     @ivar state: The status code of the room.
    1137     @type state: L{int}
    1138 
    11391136    @ivar occupantJID: The JID of the occupant in the room. Generated from
    11401137        roomJID and nick.
    11411138    @type occupantJID: L{jid.JID}
    1142     """
    1143 
    1144 
    1145     def __init__(self, roomJID, nick, state=None):
     1139
     1140    @ivar locked: Flag signalling a locked room. A locked room first needs
     1141        to be configured before it can be used. See
     1142        L{MUCClientProtocol.getConfiguration} and
     1143        L{MUCClientProtocol.configure}.
     1144    @type locked: C{bool}
     1145    """
     1146
     1147    locked = False
     1148
     1149    def __init__(self, roomJID, nick):
    11461150        """
    11471151        Initialize the room.
     
    11491153        self.roomJID = roomJID
    11501154        self.setNick(nick)
    1151         self.state = state
    1152 
    1153         self.status = 0
    1154 
    11551155        self.roster = {}
    11561156
     
    14561456            We have presence that says we joined a room.
    14571457            """
    1458             room.state = 'joined'
     1458            if STATUS_CODE.ROOM_CREATED in presence.mucStatuses:
     1459                room.locked = True
     1460
    14591461            return room
    14601462
     
    14631465            return failure
    14641466
    1465         room = Room(roomJID, nick, state='joining')
     1467        room = Room(roomJID, nick)
    14661468        self._addRoom(room)
    14671469
  • wokkel/test/test_muc.py

    r161 r162  
    16641664        def cb(room):
    16651665            self.assertEqual(self.roomJID, room.roomJID)
    1666             self.assertTrue('joined', room.state)
     1666            self.assertFalse(room.locked)
    16671667
    16681668        d = self.protocol.join(self.roomJID, self.nick)
     
    16811681
    16821682
     1683    def test_joinLocked(self):
     1684        """
     1685        A new room is locked by default.
     1686        """
     1687
     1688        def cb(room):
     1689            self.assertTrue(room.locked, "Room is not marked as locked")
     1690
     1691        d = self.protocol.join(self.roomJID, self.nick)
     1692        d.addCallback(cb)
     1693
     1694        # send back user presence, they joined
     1695        xml = """
     1696            <presence from='%s@%s/%s'>
     1697              <x xmlns='http://jabber.org/protocol/muc#user'>
     1698                <item affiliation='owner' role='moderator'/>
     1699                <status code="110"/>
     1700                <status code="201"/>
     1701              </x>
     1702            </presence>
     1703        """ % (self.roomIdentifier, self.service, self.nick)
     1704        self.stub.send(parseXml(xml))
     1705        return d
     1706
     1707
    16831708    def test_joinForbidden(self):
    16841709        """
Note: See TracChangeset for help on using the changeset viewer.