| author | Stephen Paul Weber
<singpolyma@singpolyma.net> 2023-07-26 19:48:06 UTC |
| committer | Stephen Paul Weber
<singpolyma@singpolyma.net> 2023-07-26 19:48:06 UTC |
| parent | f4c0245d5fe840a3e1e7e02ef3c3527a2e774f59 |
| xmpp/Chat.hx | +3 | -1 |
| xmpp/ChatMessage.hx | +10 | -1 |
| xmpp/Client.hx | +4 | -0 |
diff --git a/xmpp/Chat.hx b/xmpp/Chat.hx index 56531e1..de909da 100644 --- a/xmpp/Chat.hx +++ b/xmpp/Chat.hx @@ -57,5 +57,7 @@ class DirectChat extends Chat { return sync; } - public function sendMessage(message:ChatMessage):Void {} + public function sendMessage(message:ChatMessage):Void { + client.sendStanza(message.asStanza()); + } } diff --git a/xmpp/ChatMessage.hx b/xmpp/ChatMessage.hx index fbacb81..a7efe38 100644 --- a/xmpp/ChatMessage.hx +++ b/xmpp/ChatMessage.hx @@ -74,5 +74,14 @@ class ChatMessage { public function isIncoming():Bool { return direction == MessageReceived; } -} + public function asStanza():Stanza { + var attrs: haxe.DynamicAccess<String> = { type: "chat" }; + if (from != null) attrs.set("from", from); + if (to != null) attrs.set("to", to); + if (localId != null) attrs.set("id", localId); + var stanza = new Stanza("message", attrs); + stanza.textTag("body", text); + return stanza; + } +} diff --git a/xmpp/Client.hx b/xmpp/Client.hx index f857b3a..5ff5517 100644 --- a/xmpp/Client.hx +++ b/xmpp/Client.hx @@ -44,4 +44,8 @@ class Client extends xmpp.EventEmitter { public function sendQuery(query:GenericQuery) { this.stream.sendIq(query.getQueryStanza(), query.handleResponse); } + + public function sendStanza(stanza:Stanza) { + stream.sendStanza(stanza); + } }