Changeset 119:053b615f0e11


Ignore:
Timestamp:
Oct 20, 2008, 9:01:07 PM (13 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@115
Message:

basic user methods are implemented, admin and owner are left

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/muc.py

    r118 r119  
    166166
    167167
    168 class AffiliationRequest(xmlstream.IQ):
    169     """
    170     Register room request.
     168class AdminRequest(xmlstream.IQ):
     169    """
     170    A basic admin iq request
    171171
    172172    @ivar method: Type attribute of the IQ request. Either C{'set'} or C{'get'}
    173173    @type method: C{str}
    174174
     175    """
     176
     177    def __init__(self, xs, method='get'):
     178        xmlstream.IQ.__init__(self, xs, method)
     179        q = self.addElement((NS_MUC_ADMIN, 'query'))
     180
     181
     182class OwnerRequest(xmlstream.IQ):
     183    """
     184    A basic owner iq request
     185
     186    @ivar method: Type attribute of the IQ request. Either C{'set'} or C{'get'}
     187    @type method: C{str}
     188
     189    """
     190
     191    def __init__(self, xs, method='get'):
     192        xmlstream.IQ.__init__(self, xs, method)
     193        q = self.addElement((NS_MUC_OWNER, 'query'))
     194
     195   
     196
     197class AffiliationRequest(AdminRequest):
     198    """
     199    Register room request.
     200
     201    @ivar method: Type attribute of the IQ request. Either C{'set'} or C{'get'}
     202    @type method: C{str}
     203
    175204    @ivar affiliation: The affiliation type to send to room.
    176205    @type affiliation: C{str}
     
    179208
    180209    def __init__(self, xs, method='get', affiliation='none', a_jid=None, reason=None):
    181         xmlstream.IQ.__init__(self, xs, method)
    182        
    183         q = self.addElement((NS_MUC_ADMIN, 'query'))
    184         i = q.addElement('item')
     210        AdminRequest.__init__(self, xs, method)
     211
     212        i = self.query.addElement('item')
    185213
    186214        i['affiliation'] = affiliation
     
    713741        return d
    714742   
    715     def _changedNick(self, d, room_jid, prs):
    716         """Callback for changing the nick.
     743    def _changed(self, d, room_jid, prs):
     744        """Callback for changing the nick and status.
    717745        """
    718746
     
    747775        # add observer for joining the room
    748776        self.xmlstream.addOnetimeObserver(PRESENCE+"[@from='%s']" % (r.entity_id.full()),
    749                                           self._changedNick, 1, d, room_jid)
     777                                          self._changed, 1, d, room_jid)
    750778
    751779        return d
     
    768796   
    769797
    770    
     798    def status(self, room_jid, show=None, status=None):
     799        """Change user status.
     800
     801        See: http://xmpp.org/extensions/xep-0045.html#changepres
     802
     803        @param room_jid: The room jabber/xmpp entity id for the requested configuration form.
     804        @type  room_jid: L{jid.JID}
     805
     806        @param show: The availability of the entity. Common values are xa, available, etc
     807        @type  show: L{unicode}
     808
     809        @param show: The current status of the entity.
     810        @type  show: L{unicode}
     811
     812        """
     813        r = self._getRoom(room_jid)
     814        if r is None:
     815            raise Exception, 'Room not found'
     816
     817        p = BasicPresence(to=r.entityId())
     818        if status is not None:
     819            p.addElement('status', None, status)
     820           
     821        if show is not None:
     822            p.addElement('show', None, show)
     823           
     824        d = self.sendDeferred(p, timeout=DEFER_TIMEOUT)
     825
     826        # add observer for joining the room
     827        self.xmlstream.addOnetimeObserver(PRESENCE+"[@from='%s']" % (r.entity_id.full()),
     828                                          self._changed, 1, d, room_jid)
     829
     830        return d
    771831
    772832    def _sendMessage(self, msg, children=None):
     
    807867        return iq.send()
    808868
     869    def getMemberList(self, room_jid):
     870        """ Get a member list from a room.
     871
     872        @param room_jid: The room jabber/xmpp entity id for the requested member list.
     873        @type  room_jid: L{jid.JID}
     874
     875        """
     876        iq = AffiliationRequest(self.xmlstream,
     877                                method='get',
     878                                affiliation='member',
     879                                )
     880        iq['to'] = room_jid.full()
     881        return iq.send()       
     882       
     883
    809884    def getRegisterForm(self, room):
    810885        """
     886
     887        @param room: The room jabber/xmpp entity id for the requested registration form.
     888        @type  room: L{jid.JID}
     889
    811890        """
    812891        iq = RegisterRequest(self.xmlstream)
Note: See TracChangeset for help on using the changeset viewer.