| author | Stephen Paul Weber
<singpolyma@singpolyma.net> 2023-11-09 03:59:34 UTC |
| committer | Stephen Paul Weber
<singpolyma@singpolyma.net> 2023-11-09 03:59:34 UTC |
| parent | a6d1e40c242f2514ebf11f739eddbadbe62c1c99 |
| xmpp/ChatMessage.hx | +23 | -3 |
| xmpp/Notification.hx | +1 | -1 |
diff --git a/xmpp/ChatMessage.hx b/xmpp/ChatMessage.hx index 3e1eeb9..88a012a 100644 --- a/xmpp/ChatMessage.hx +++ b/xmpp/ChatMessage.hx @@ -11,8 +11,11 @@ enum MessageDirection { } class ChatAttachment { - public var url(default, null):String = null; - public var description(default, null):String = null; + public final uris: Array<String>; + + public function new(uris: Array<String>) { + this.uris = uris; + } } @:expose @@ -143,11 +146,28 @@ class ChatMessage { return null; } - if (msg.text == null) return null; + for (ref in stanza.allTags("reference", "urn:xmpp:reference:0")) { + if (ref.attr.get("begin") == null && ref.attr.get("end") == null) { + final sims = ref.getChild("media-sharing", "urn:xmpp:sims:1"); + if (sims != null) msg.attachSims(sims); + } + } + + for (sims in stanza.allTags("media-sharing", "urn:xmpp:sims:1")) { + msg.attachSims(sims); + } + + if (msg.text == null && msg.attachments.length < 1) return null; return msg; } + public function attachSims(sims: Stanza) { + 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)); + } + public function set_localId(localId:String):String { if(this.localId != null) { throw new Exception("Message already has a localId set"); diff --git a/xmpp/Notification.hx b/xmpp/Notification.hx index 1db2121..13b0351 100644 --- a/xmpp/Notification.hx +++ b/xmpp/Notification.hx @@ -29,7 +29,7 @@ class Notification { var imageUri = null; final attachment = m.attachments[0]; if (attachment != null) { - imageUri = attachment.url; + imageUri = attachment.uris[0]; } return new Notification( "New Message",