git » sdk » commit 18a79b3

Store attachment mime type

author Stephen Paul Weber
2023-11-20 14:40:20 UTC
committer Stephen Paul Weber
2023-11-20 14:40:20 UTC
parent fabd981e844243658b1d7f6f48c1552bb8ab9f88

Store attachment mime type

So UI can know what kind of preview to use

xmpp/ChatMessage.hx +7 -2

diff --git a/xmpp/ChatMessage.hx b/xmpp/ChatMessage.hx
index 211a6fe..3405aaa 100644
--- a/xmpp/ChatMessage.hx
+++ b/xmpp/ChatMessage.hx
@@ -21,9 +21,11 @@ enum MessageStatus {
 }
 
 class ChatAttachment {
+	public final mime: String;
 	public final uris: Array<String>;
 
-	public function new(uris: Array<String>) {
+	public function new(mime: String, uris: Array<String>) {
+		this.mime = mime;
 		this.uris = uris;
 	}
 }
@@ -186,9 +188,12 @@ class ChatMessage {
 	}
 
 	public function attachSims(sims: Stanza) {
+		var mime = sims.findText("{urn:xmpp:jingle:apps:file-transfer:5}/media-type#");
+		if (mime == null) sims.findText("{urn:xmpp:jingle:apps:file-transfer:3}/media-type#");
+		if (mime == null) mime = "application/octet-stream";
 		final sources = sims.getChild("sources");
 		final uris = (sources?.allTags("reference", "urn:xmpp:reference:0") ?? []).map((ref) -> ref.attr.get("uri") ?? "").filter((uri) -> uri != "");
-		if (uris.length > 0) attachments.push(new ChatAttachment(uris));
+		if (uris.length > 0) attachments.push(new ChatAttachment(mime, uris));
 	}
 
 	public function set_localId(localId:String):String {