From f601ca0d7b8ac0b471491bf5181e7b6cb18e096b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Sat, 18 May 2019 00:33:28 +0200 Subject: [PATCH] Add dedicated announce/motd module --- gajim/app_actions.py | 4 +--- gajim/common/connection.py | 8 ------- gajim/common/modules/__init__.py | 1 + gajim/common/modules/announce.py | 37 ++++++++++++++++++++++++++++++++ gajim/gtk/single_message.py | 5 +++-- 5 files changed, 42 insertions(+), 13 deletions(-) create mode 100644 gajim/common/modules/announce.py diff --git a/gajim/app_actions.py b/gajim/app_actions.py index 1fc68f77e..6f923149a 100644 --- a/gajim/app_actions.py +++ b/gajim/app_actions.py @@ -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 diff --git a/gajim/common/connection.py b/gajim/common/connection.py index d15826331..f25e89ad5 100644 --- a/gajim/common/connection.py +++ b/gajim/common/connection.py @@ -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 diff --git a/gajim/common/modules/__init__.py b/gajim/common/modules/__init__.py index 393d7f645..6840db04d 100644 --- a/gajim/common/modules/__init__.py +++ b/gajim/common/modules/__init__.py @@ -73,6 +73,7 @@ MODULES = [ 'user_tune', 'vcard_avatars', 'vcard_temp', + 'announce', ] _imported_modules = [] # type: List[tuple] diff --git a/gajim/common/modules/announce.py b/gajim/common/modules/announce.py new file mode 100644 index 000000000..58536adf0 --- /dev/null +++ b/gajim/common/modules/announce.py @@ -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 . + +# 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' diff --git a/gajim/gtk/single_message.py b/gajim/gtk/single_message.py index 69f08cf13..a69801183 100644 --- a/gajim/gtk/single_message.py +++ b/gajim/gtk/single_message.py @@ -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)