git » sdk » commit 6de180c

Handle call notifications from push

author Stephen Paul Weber
2025-03-04 16:20:23 UTC
committer Stephen Paul Weber
2025-03-04 16:20:23 UTC
parent c2f217fc6c6a55708ab71d5c0996a169d21f4754

Handle call notifications from push

snikket/ChatMessage.hx +7 -0
snikket/Notification.hx +15 -2

diff --git a/snikket/ChatMessage.hx b/snikket/ChatMessage.hx
index 0406350..25d3cfa 100644
--- a/snikket/ChatMessage.hx
+++ b/snikket/ChatMessage.hx
@@ -383,6 +383,13 @@ class ChatMessage {
 		return payloads.find((el) -> el.attr.get("xmlns") == "urn:xmpp:jingle-message:0")?.name;
 	}
 
+	/**
+		The session id of the call if this message is related to a call
+	**/
+	public function callSid() {
+		return payloads.find((el) -> el.attr.get("xmlns") == "urn:xmpp:jingle-message:0")?.attr?.get("id");
+	}
+
 	/**
 		The duration of the call if this message is related to a call
 	**/
diff --git a/snikket/Notification.hx b/snikket/Notification.hx
index a7f9d01..774ab5f 100644
--- a/snikket/Notification.hx
+++ b/snikket/Notification.hx
@@ -2,6 +2,7 @@ package snikket;
 
 import snikket.ChatMessage;
 import snikket.JID;
+import snikket.Message;
 
 @:expose
 class Notification {
@@ -10,16 +11,22 @@ class Notification {
 	public var accountId (default, null) : String;
 	public var chatId (default, null) : String;
 	public var messageId (default, null) : String;
+	public var type (default, null) : MessageType;
+	public var callStatus (default, null) : Null<String>;
+	public var callSid (default, null) : Null<String>;
 	public var imageUri (default, null) : Null<String>;
 	public var lang (default, null) : Null<String>;
 	public var timestamp (default, null) : Null<String>;
 
-	public function new(title: String, body: String, accountId: String, chatId: String, messageId: String, imageUri: Null<String>, lang: Null<String>, timestamp: Null<String>) {
+	public function new(title: String, body: String, accountId: String, chatId: String, messageId: String, type: MessageType, callStatus: Null<String>, callSid: Null<String>, imageUri: Null<String>, lang: Null<String>, timestamp: Null<String>) {
 		this.title = title;
 		this.body = body;
 		this.accountId = accountId;
 		this.chatId = chatId;
 		this.messageId = messageId;
+		this.type = type;
+		this.callStatus = callStatus;
+		this.callSid = callSid;
 		this.imageUri = imageUri;
 		this.lang = lang;
 		this.timestamp = timestamp;
@@ -32,11 +39,14 @@ class Notification {
 			imageUri = attachment.uris[0];
 		}
 		return new Notification(
-			"New Message",
+			m.type == MessageCall ? "Incoming Call" : "New Message",
 			m.text,
 			m.account(),
 			m.chatId(),
 			m.serverId,
+			m.type,
+			m.callStatus(),
+			m.callSid(),
 			imageUri,
 			m.lang,
 			m.timestamp
@@ -52,6 +62,9 @@ class Notification {
 			JID.parse(stanza.attr.get("to")).asBare().asString(),
 			JID.parse(stanza.attr.get("from")).asBare().asString(),
 			stanza.getChildText("stanza-id", "urn:xmpp:sid:0"),
+			MessageChat,
+			null,
+			null,
 			null,
 			null,
 			null