git » sdk » commit 31a8655

Disable push on logout

author Stephen Paul Weber
2025-03-04 16:22:33 UTC
committer Stephen Paul Weber
2025-03-04 16:41:00 UTC
parent 9282d5aa1c4448ebe0c54d2beac0599e7ebdd1a9

Disable push on logout

snikket/Client.hx +7 -3
snikket/queries/Push2Disable.hx +36 -0

diff --git a/snikket/Client.hx b/snikket/Client.hx
index 8213bf3..8e5151a 100644
--- a/snikket/Client.hx
+++ b/snikket/Client.hx
@@ -25,6 +25,7 @@ import snikket.queries.GenericQuery;
 import snikket.queries.HttpUploadSlot;
 import snikket.queries.JabberIqGatewayGet;
 import snikket.queries.PubsubGet;
+import snikket.queries.Push2Disable;
 import snikket.queries.Push2Enable;
 import snikket.queries.RosterGet;
 import snikket.queries.VcardTempGet;
@@ -601,10 +602,13 @@ class Client extends EventEmitter {
 		@param completely if true chats, messages, etc will be deleted as well
 	**/
 	public function logout(completely: Bool) {
-		// TODO: unregister from all push notifications
-		stream.disconnect();
-		// TODO: FAST invalidate https://xmpp.org/extensions/xep-0484.html#invalidation
 		persistence.removeAccount(accountId(), completely);
+		final disable = new Push2Disable(jid.asBare().asString());
+		disable.onFinished(() -> {
+			stream.disconnect();
+		});
+		sendQuery(disable);
+		// TODO: FAST invalidate https://xmpp.org/extensions/xep-0484.html#invalidation
 	}
 
 	/**
diff --git a/snikket/queries/Push2Disable.hx b/snikket/queries/Push2Disable.hx
new file mode 100644
index 0000000..cff4808
--- /dev/null
+++ b/snikket/queries/Push2Disable.hx
@@ -0,0 +1,36 @@
+package snikket.queries;
+
+import haxe.io.Bytes;
+import haxe.crypto.Base64;
+
+import snikket.ID;
+import snikket.Stanza;
+import snikket.queries.GenericQuery;
+
+class Push2Disable extends GenericQuery {
+	public var xmlns(default, null) = "urn:xmpp:push2:0";
+	public var queryId:String = null;
+	public var ver:String = null;
+	private var responseStanza:Stanza;
+
+	public function new(to: String) {
+		queryId = ID.short();
+		queryStanza = new Stanza(
+			"iq",
+			{ to: to, type: "set", id: queryId }
+		);
+		queryStanza.tag("disable", { xmlns: xmlns });
+	}
+
+	public function handleResponse(stanza:Stanza) {
+		responseStanza = stanza;
+		finish();
+	}
+
+	public function getResult() {
+		if (responseStanza == null) {
+			return null;
+		}
+		return { type: responseStanza.attr.get("type") };
+	}
+}