Add dedicated announce/motd module
This commit is contained in:
		
							parent
							
								
									9dbac0f098
								
							
						
					
					
						commit
						f601ca0d7b
					
				
					 5 changed files with 42 additions and 13 deletions
				
			
		| 
						 | 
				
			
			@ -277,9 +277,7 @@ def on_update_motd(action, param):
 | 
			
		|||
 | 
			
		||||
def on_delete_motd(action, param):
 | 
			
		||||
    account = param.get_string()
 | 
			
		||||
    server = app.config.get_per('accounts', account, 'hostname')
 | 
			
		||||
    server += '/announce/motd/delete'
 | 
			
		||||
    app.connections[account].send_motd(server)
 | 
			
		||||
    app.connections[account].get_module('Announce').delete_motd()
 | 
			
		||||
 | 
			
		||||
# Help Actions
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1566,14 +1566,6 @@ class Connection(CommonConnection, ConnectionHandlers):
 | 
			
		|||
            app.nec.push_incoming_event(OurShowEvent(None, conn=self,
 | 
			
		||||
                show=show))
 | 
			
		||||
 | 
			
		||||
    def send_motd(self, jid, subject='', msg='', xhtml=None):
 | 
			
		||||
        if not app.account_is_connected(self.name):
 | 
			
		||||
            return
 | 
			
		||||
        msg_iq = nbxmpp.Message(to=jid, body=msg, subject=subject,
 | 
			
		||||
            xhtml=xhtml)
 | 
			
		||||
 | 
			
		||||
        self.connection.send(msg_iq)
 | 
			
		||||
 | 
			
		||||
    def _nec_message_outgoing(self, obj):
 | 
			
		||||
        if obj.account != self.name:
 | 
			
		||||
            return
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -73,6 +73,7 @@ MODULES = [
 | 
			
		|||
    'user_tune',
 | 
			
		||||
    'vcard_avatars',
 | 
			
		||||
    'vcard_temp',
 | 
			
		||||
    'announce',
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
_imported_modules = []  # type: List[tuple]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										37
									
								
								gajim/common/modules/announce.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								gajim/common/modules/announce.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,37 @@
 | 
			
		|||
# This file is part of Gajim.
 | 
			
		||||
#
 | 
			
		||||
# Gajim is free software; you can redistribute it and/or modify
 | 
			
		||||
# it under the terms of the GNU General Public License as published
 | 
			
		||||
# by the Free Software Foundation; version 3 only.
 | 
			
		||||
#
 | 
			
		||||
# Gajim is distributed in the hope that it will be useful,
 | 
			
		||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 | 
			
		||||
# GNU General Public License for more details.
 | 
			
		||||
#
 | 
			
		||||
# You should have received a copy of the GNU General Public License
 | 
			
		||||
# along with Gajim.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
# Server MOTD and Announce
 | 
			
		||||
 | 
			
		||||
import nbxmpp
 | 
			
		||||
 | 
			
		||||
from gajim.common.modules.base import BaseModule
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Announce(BaseModule):
 | 
			
		||||
    def __init__(self, con):
 | 
			
		||||
        BaseModule.__init__(self, con)
 | 
			
		||||
 | 
			
		||||
    def delete_motd(self):
 | 
			
		||||
        server = self._con.get_own_jid().getDomain()
 | 
			
		||||
        jid = '%s/announce/motd/delete' % server
 | 
			
		||||
        self.set_announce(jid)
 | 
			
		||||
 | 
			
		||||
    def set_announce(self, jid, subject=None, body=None):
 | 
			
		||||
        message = nbxmpp.Message(to=jid, body=body, subject=subject)
 | 
			
		||||
        self._nbxmpp().send(message)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_instance(*args, **kwargs):
 | 
			
		||||
    return Announce(*args, **kwargs), 'Announce'
 | 
			
		||||
| 
						 | 
				
			
			@ -308,8 +308,9 @@ class SingleMessageWindow(Gtk.ApplicationWindow):
 | 
			
		|||
                return True
 | 
			
		||||
 | 
			
		||||
            if '/announce/' in to_whom_jid:
 | 
			
		||||
                app.connections[self.account].send_motd(to_whom_jid, subject,
 | 
			
		||||
                    message)
 | 
			
		||||
                con = app.connections[self.account]
 | 
			
		||||
                con.get_module('Announce').set_announce(
 | 
			
		||||
                    to_whom_jid, subject, message)
 | 
			
		||||
                continue
 | 
			
		||||
 | 
			
		||||
            recipient_list.append(to_whom_jid)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue