changeset 3334:2cd54c72fae4

plugin XEP-0077: None can now be used in `to_jid` argument in `unregister`: if None is used, the XMPP account of the profile will be deleted.
author Goffi <goffi@goffi.org>
date Thu, 13 Aug 2020 23:46:18 +0200
parents ac9342f359e9
children 83bc9d46a417
files sat/plugins/plugin_xep_0077.py
diffstat 1 files changed, 14 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0077.py	Thu Aug 13 23:46:18 2020 +0200
+++ b/sat/plugins/plugin_xep_0077.py	Thu Aug 13 23:46:18 2020 +0200
@@ -17,17 +17,17 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+from twisted.words.protocols.jabber import jid, xmlstream, client, error as jabber_error
+from twisted.internet import defer, reactor
+from wokkel import data_form
 from sat.core.i18n import _
 from sat.core.constants import Const as C
 from sat.core import exceptions
 from sat.core.log import getLogger
+from sat.core.xmpp import SatXMPPEntity
+from sat.tools import xml_tools
 
 log = getLogger(__name__)
-from twisted.words.protocols.jabber import jid, xmlstream, client, error as jabber_error
-from twisted.internet import defer, reactor
-from sat.tools import xml_tools
-
-from wokkel import data_form
 
 NS_REG = "jabber:iq:register"
 
@@ -281,15 +281,21 @@
         client = self.host.getClient(profile_key)
         return self.unregister(client, jid.JID(to_jid_s))
 
-    def unregister(self, client, to_jid):
+    def unregister(
+            self,
+            client: SatXMPPEntity,
+            to_jid: jid.JID
+    ) -> defer.Deferred:
         """remove registration from a server/service
 
         BEWARE! if you remove registration from profile own server, this will
         DELETE THE XMPP ACCOUNT WITHOUT WARNING
-        @param to_jid(jid.JID): jid of the service or server
+        @param to_jid: jid of the service or server
+            None to delete client's account (DANGEROUS!)
         """
         iq_elt = client.IQ()
-        iq_elt["to"] = to_jid.full()
+        if to_jid is not None:
+            iq_elt["to"] = to_jid.full()
         query_elt = iq_elt.addElement((NS_REG, "query"))
         query_elt.addElement("remove")
         return iq_elt.send()