Ignore:
Timestamp:
Sep 30, 2008, 7:08:45 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@69
Message:

add basic errors and disco stuff, still need iq and message parts re #24

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/muc.py

    r107 r108  
    1919from wokkel import disco, data_form, shim, xmppim
    2020from wokkel.subprotocols import IQHandlerMixin, XMPPHandler
    21 from wokkel.iwokkel import IMUCClient, IMUCService
     21from wokkel.iwokkel import IMUCClient
    2222
    2323# Multi User Chat namespaces
    24 NS_MUC          = 'http://jabber.org/protocol/muc'
    25 NS_MUC_USER     = NS_MUC + '#user'
    26 NS_MUC_ADMIN    = NS_MUC + '#admin'
    27 NS_MUC_OWNER    = NS_MUC + '#owner'
    28 NS_MUC_ROOMINFO = NS_MUC + '#roominfo'
    29 NS_MUC_CONFIG   = NS_MUC + '#roomconfig'
     24NS          = 'http://jabber.org/protocol/muc'
     25NS_USER     = NS + '#user'
     26NS_ADMIN    = NS + '#admin'
     27NS_OWNER    = NS + '#owner'
     28NS_ROOMINFO = NS + '#roominfo'
     29NS_CONFIG   = NS + '#roomconfig'
    3030
    3131# ad hoc commands
     
    4747IQ_COMMAND   = IQ+'/command'
    4848
    49 MUC_ADMIN = IQ_QUERY+'[@xmlns="' + NS_MUC_ADMIN + '"]'
    50 MUC_OWNER = IQ_QUERY+'[@xmlns="' + NS_MUC_OWNER + '"]'
     49MUC_ADMIN = IQ_QUERY+'[@xmlns="' + NS_ADMIN + '"]'
     50MUC_OWNER = IQ_QUERY+'[@xmlns="' + NS_OWNER + '"]'
    5151
    5252MUC_AO = MUC_ADMIN + '|' + MUC_OWNER
     
    6969    """
    7070    def __init__(self, condition, mucCondition, feature=None, text=None):
    71         appCondition = domish.Element((NS_MUC_ERRORS, mucCondition))
     71        appCondition = domish.Element((NS, mucCondition))
    7272        if feature:
    7373            appCondition['feature'] = feature
     
    9494
    9595
     96
    9697class Room(object):
    9798    """
     
    124125       
    125126        # add muc elements
    126         x = self.addElement('x', NS_MUC)
     127        x = self.addElement('x', NS)
    127128
    128129
     
    138139            self['from'] = frm
    139140        # add muc elements
    140         x = self.addElement('x', NS_MUC_USER)
     141        x = self.addElement('x', NS_USER)
    141142        if affiliation:
    142143            x['affiliation'] = affiliation
     
    151152    """
    152153
    153     def __init__(self, error, to=None):
     154    def __init__(self, error, to=None, frm=None):
    154155        BasicPresence.__init__(self, to, type='error')
    155        
     156        if frm:
     157            self['from'] = frm
    156158        # add muc elements
    157         x = self.addElement('x', NS_MUC)
     159        x = self.addElement('x', NS)
    158160        # add error
    159161        self.addChild(error)
     
    170172    def connectionInitialized(self):
    171173        self.rooms = {}
    172         self.xmlstream.addObserver(PRESENCE, self._onPresence)
    173         self.xmlstream.addObserver(GROUPCHAT, self._onGroupChat)
     174       
    174175
    175176    def _setRoom(self, room):
     
    179180        return self.rooms.get(room_jid.full().lower())
    180181
    181     def _onGroupChat(self, msg):
    182         """handle groupchat message stanzas
    183         """
    184 
    185 
    186     def _onPresence(self, prs):
    187         """handle groupchat presence
    188         """
    189         x = getattr(prs, 'x', None)
    190         if x.uri == NS_MUC_USER:
    191             self.userPresence(prs)
    192182
    193183
     
    196186        """
    197187        room_jid = jid.internJID(prs['from'])
    198         print type(prs)
    199         print type(d)
     188       
    200189        # check for errors
    201190        if prs.hasAttribute('type') and prs['type'] == 'error':           
    202             print room_jid.full()
    203         # change the state of the room
    204         r = self._getRoom(room_jid)
    205         r.state = 'joined'
    206         d.callback(room_jid, r)
     191            d.errback(prs)
     192        else:   
     193            # change the state of the room
     194            r = self._getRoom(room_jid)
     195            r.state = 'joined'
     196            d.callback(r)
    207197
    208198    def userPresence(self, prs):
     
    211201        pass
    212202       
    213     def joinRoom(self, server, room, nick):
     203
     204    def _cbDisco(self, iq):
     205        # grab query
     206       
     207        return iq.query
     208       
     209    def disco(self, entity, type='info'):
     210        """Send disco queries to a XMPP entity
     211        """
     212
     213        iq = disco.DiscoRequest(self.xmlstream, disco.NS_INFO, 'get')
     214        iq['to'] = entity
     215
     216        return iq.send().addCallback(self._cbDisco)
     217       
     218
     219    def join(self, server, room, nick):
    214220        """
    215221        """
     
    224230        # add observer for joining the room
    225231        self.xmlstream.addOnetimeObserver(PRESENCE+"[@from='%s']" % (r.entity_id.full()),
    226                                           self._joinedRoom, d)
     232                                          self._joinedRoom, 1, d)
    227233
    228234        return d
Note: See TracChangeset for help on using the changeset viewer.