Changeset 122:1c21cf10bb60 for wokkel


Ignore:
Timestamp:
Oct 20, 2008, 10:41:53 PM (11 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@118
Message:

abstract role and affiliation requests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/muc.py

    r121 r122  
    279279
    280280           
    281        
     281class RoleRequest(AdminRequest):
     282    def __init__(self, xs, method='get', role='none', a_jid=None, reason=None):
     283        AdminRequest.__init__(self, xs, method)
     284
     285        i = self.query.addElement('item')
     286
     287        i['role'] = role
     288        if a_jid:
     289            i['jid'] = a_jid.full()
     290           
     291        if reason:
     292            i.addElement('reason', None, reason)
    282293
    283294class GroupChat(domish.Element):
     
    368379            a = getattr(self, key, a)
    369380            if a is not None:
    370                 h[key] = str(a)
     381                if key == 'since':
     382                    h[key] = a.strftime('%Y%m%dT%H:%M:%S')
     383                else:
     384                    h[key] = str(a)
    371385       
    372386        return h
     
    10691083
    10701084
     1085
    10711086    def history(self, to, message_list):
    10721087        """
     
    10851100            self.xmlstream.send(m)
    10861101
    1087     def ban(self, to, ban_jid, frm, reason=None):
    1088        
     1102    def _setAffiliation(self, frm, room_jid, affiliation, reason=None, a_jid=None):
    10891103        iq = AffiliationRequest(self.xmlstream,
    10901104                                method='set',
    1091                                 affiliation='outcast',
    1092                                 a_jid=ban_jid,
     1105                                affiliation=affiliation,
     1106                                a_jid=a_jid,
    10931107                                reason=reason)
    1094         iq['to'] = to.userhost() # this is a room jid, only send to room
     1108        iq['to'] = room_jid.userhost() # this is a room jid, only send to room
    10951109        iq['from'] = frm.full()
    10961110        return iq.send()
    10971111
    1098 
    1099     def kick(self, to, kick_jid, frm, reason=None):
    1100        
    1101         iq = AffiliationRequest(self.xmlstream,
    1102                                 method='set',
    1103                                 a_jid=kick_jid,
    1104                                 reason=reason)
    1105         iq['to'] = to.userhost() # this is a room jid, only send to room
     1112    def _setRole(self, frm, room_jid, a_jid=None, reason=None, role='none'):
     1113        iq = RoleRequest(self.xmlstream,
     1114                         method='set',
     1115                         a_jid=a_jid,
     1116                         role=role,
     1117                         reason=reason)
     1118        iq['to'] = room_jid.userhost() # this is a room jid, only send to room
    11061119        iq['from'] = frm.full()
    11071120        return iq.send()
     1121
     1122    def grantVoice(self, frm, room_jid, reason=None):
     1123        return self._setAffiliation(frm, room_jid, 'participant', reason=reason)
     1124
     1125
     1126    def ban(self, to, ban_jid, frm, reason=None):
     1127        return self._setAffiliation(frm, to, 'outcast', a_jid=ban_jid, reason=reason)
     1128
     1129
     1130    def kick(self, to, kick_jid, frm, reason=None):       
     1131        return self._setAffiliation(frm, to, 'none', a_jid=kick_jid, reason=reason)
     1132       
Note: See TracChangeset for help on using the changeset viewer.