Disable subject change if room doesnt allow it
This commit is contained in:
		
							parent
							
								
									77fb424cb0
								
							
						
					
					
						commit
						c5f8fe915a
					
				
					 3 changed files with 25 additions and 6 deletions
				
			
		| 
						 | 
					@ -449,7 +449,8 @@ class MucCapsCache:
 | 
				
			||||||
                features.append(child.getAttr('var'))
 | 
					                features.append(child.getAttr('var'))
 | 
				
			||||||
            elif child.getName() == 'x':
 | 
					            elif child.getName() == 'x':
 | 
				
			||||||
                if child.getNamespace() == nbxmpp.NS_DATA:
 | 
					                if child.getNamespace() == nbxmpp.NS_DATA:
 | 
				
			||||||
                    data.append(nbxmpp.DataForm(node=child))
 | 
					                    from gajim.common import dataforms
 | 
				
			||||||
 | 
					                    data.append(dataforms.ExtendForm(node=child))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if nbxmpp.NS_MUC not in features:
 | 
					        if nbxmpp.NS_MUC not in features:
 | 
				
			||||||
            # Not a MUC, dont cache info
 | 
					            # Not a MUC, dont cache info
 | 
				
			||||||
| 
						 | 
					@ -483,3 +484,16 @@ class MucCapsCache:
 | 
				
			||||||
                return nbxmpp.NS_MAM_1
 | 
					                return nbxmpp.NS_MAM_1
 | 
				
			||||||
        except (KeyError, AttributeError):
 | 
					        except (KeyError, AttributeError):
 | 
				
			||||||
            return
 | 
					            return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def is_subject_change_allowed(self, jid, affiliation):
 | 
				
			||||||
 | 
					        allowed = True
 | 
				
			||||||
 | 
					        if affiliation in ('owner, admin'):
 | 
				
			||||||
 | 
					            return allowed
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if jid in self.cache:
 | 
				
			||||||
 | 
					            for form in self.cache[jid].data:
 | 
				
			||||||
 | 
					                try:
 | 
				
			||||||
 | 
					                    allowed = form['muc#roominfo_changesubject'].value
 | 
				
			||||||
 | 
					                except KeyError:
 | 
				
			||||||
 | 
					                    pass
 | 
				
			||||||
 | 
					        return allowed
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -101,8 +101,8 @@ class ConnectionDisco:
 | 
				
			||||||
        id_ = self._discover(nbxmpp.NS_DISCO_INFO, jid, node, id_prefix)
 | 
					        id_ = self._discover(nbxmpp.NS_DISCO_INFO, jid, node, id_prefix)
 | 
				
			||||||
        self.disco_info_ids.append(id_)
 | 
					        self.disco_info_ids.append(id_)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def discoverMUC(self, jid, callback):
 | 
					    def discoverMUC(self, jid, callback, update=False):
 | 
				
			||||||
        if muc_caps_cache.is_cached(jid):
 | 
					        if muc_caps_cache.is_cached(jid) and not update:
 | 
				
			||||||
            callback()
 | 
					            callback()
 | 
				
			||||||
            return
 | 
					            return
 | 
				
			||||||
        disco_info = nbxmpp.Iq(typ='get', to=jid, queryNS=nbxmpp.NS_DISCO_INFO)
 | 
					        disco_info = nbxmpp.Iq(typ='get', to=jid, queryNS=nbxmpp.NS_DISCO_INFO)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -603,9 +603,12 @@ class GroupchatControl(ChatControlBase):
 | 
				
			||||||
            online and role == 'visitor')
 | 
					            online and role == 'visitor')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Change Subject
 | 
					        # Change Subject
 | 
				
			||||||
        # Get this from Room Disco
 | 
					        subject = False
 | 
				
			||||||
 | 
					        if contact is not None:
 | 
				
			||||||
 | 
					            subject = muc_caps_cache.is_subject_change_allowed(
 | 
				
			||||||
 | 
					                self.room_jid, contact.affiliation)
 | 
				
			||||||
        win.lookup_action('change-subject-' + self.control_id).set_enabled(
 | 
					        win.lookup_action('change-subject-' + self.control_id).set_enabled(
 | 
				
			||||||
            online)
 | 
					            online and subject)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Change Nick
 | 
					        # Change Nick
 | 
				
			||||||
        win.lookup_action('change-nick-' + self.control_id).set_enabled(
 | 
					        win.lookup_action('change-nick-' + self.control_id).set_enabled(
 | 
				
			||||||
| 
						 | 
					@ -1522,6 +1525,8 @@ class GroupchatControl(ChatControlBase):
 | 
				
			||||||
        if '104' in obj.status_code:
 | 
					        if '104' in obj.status_code:
 | 
				
			||||||
            changes.append(_('A setting not related to privacy has been '
 | 
					            changes.append(_('A setting not related to privacy has been '
 | 
				
			||||||
                             'changed'))
 | 
					                             'changed'))
 | 
				
			||||||
 | 
					            app.connections[self.account].discoverMUC(
 | 
				
			||||||
 | 
					                self.room_jid, self.update_actions, update=True)
 | 
				
			||||||
        if '170' in obj.status_code:
 | 
					        if '170' in obj.status_code:
 | 
				
			||||||
            # Can be a presence (see chg_contact_status in groupchat_control.py)
 | 
					            # Can be a presence (see chg_contact_status in groupchat_control.py)
 | 
				
			||||||
            changes.append(_('Room logging is now enabled'))
 | 
					            changes.append(_('Room logging is now enabled'))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue