Ignore:
Timestamp:
Oct 17, 2008, 10:47:01 PM (14 years ago)
Author:
Christopher Zorn <tofu@…>
Branch:
wokkel-muc-client-support-24
Convert:
svn:b33ecbfc-034c-dc11-8662-000475d9059e/branches/wokkel-muc-client-support-24@111
Message:

we now have basic support with nick change, also added some doc strings, still need more re #24

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/muc.py

    r116 r117  
    280280        self.status = 0
    281281
    282         self.entity_id = jid.internJID(name+'@'+server+'/'+nick)
     282        self.entity_id = self.entityId()
    283283               
    284284        self.roster = {}
    285285
    286        
     286    def entityId(self):
     287        """
     288        """
     289        self.entity_id = jid.internJID(self.name+'@'+self.server+'/'+self.nick)
     290
     291        return self.entity_id
    287292
    288293    def addUser(self, user):
     
    608613    def configure(self, room_jid, fields=[]):
    609614        """Configure a room
     615
     616        @param room_jid: The room jabber/xmpp entity id for the requested configuration form.
     617        @type  room_jid: L{jid.JID}
     618
    610619        """
    611620        request = ConfigureRequest(self.xmlstream, method='set', fields=fields)
     
    615624
    616625    def getConfigureForm(self, room_jid):
     626        """Grab the configuration form from the room. This sends an iq request to the room.
     627
     628        @param room_jid: The room jabber/xmpp entity id for the requested configuration form.
     629        @type  room_jid: L{jid.JID}
     630
     631        """
    617632        request = ConfigureRequest(self.xmlstream)
    618633        request['to'] = room_jid
     
    621636
    622637    def join(self, server, room, nick):
    623         """
     638        """ Join a MUC room by sending presence to it. Returns a defered that is called when
     639        the entity is in the room or an error has occurred.
     640       
     641        @param server: The server where the room is located.
     642        @type  server: L{unicode}
     643
     644        @param room: The room name the entity is joining.
     645        @type  room: L{unicode}
     646
     647        @param nick: The nick name for the entitity joining the room.
     648        @type  nick: L{unicode}
     649       
    624650        """
    625651        d = defer.Deferred()
     
    637663        return d
    638664   
     665    def _changedNick(self, d, room_jid, prs):
     666        """Callback for changing the nick.
     667        """
     668
     669        r = self._getRoom(room_jid)
     670
     671        d.callback(r)
     672
     673
     674    def nick(self, room_jid, new_nick):
     675        """ Change an entities nick name in a MUC room.
     676       
     677        See: http://xmpp.org/extensions/xep-0045.html#changenick
     678
     679        @param room_jid: The room jabber/xmpp entity id for the requested configuration form.
     680        @type  room_jid: L{jid.JID}
     681
     682        @param new_nick: The nick name for the entitity joining the room.
     683        @type  new_nick: L{unicode}
     684       
     685        """
     686
     687        d = defer.Deferred()
     688        r = self._getRoom(room_jid)
     689        if r is None:
     690            raise Exception, 'Room not found'
     691        r.nick = new_nick # change the nick
     692        # create presence
     693        # make sure we call the method to generate the new entity xmpp id
     694        p = BasicPresence(to=r.entityId())
     695        self.xmlstream.send(p)
     696
     697        # add observer for joining the room
     698        self.xmlstream.addOnetimeObserver(PRESENCE+"[@from='%s']" % (r.entity_id.full()),
     699                                          self._changedNick, 1, d, room_jid)
     700
     701        return d
     702       
    639703
    640704   
Note: See TracChangeset for help on using the changeset viewer.