Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/jsxc.nextcloud.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlaus <klaus@jsxc.org>2016-01-29 13:46:22 +0300
committerKlaus <klaus@jsxc.org>2016-01-29 13:46:22 +0300
commit142e5f712b2a4653cc9a407ef40814384e711804 (patch)
treebd66167304a7e69ee533e0d8f10890f546de4729 /build/lib/stanzahandlers/message.php
parent6c50da5f21c5028d4fff078db1d69140acceb0dd (diff)
build v3.0.0-beta1b
Diffstat (limited to 'build/lib/stanzahandlers/message.php')
-rw-r--r--build/lib/stanzahandlers/message.php80
1 files changed, 80 insertions, 0 deletions
diff --git a/build/lib/stanzahandlers/message.php b/build/lib/stanzahandlers/message.php
new file mode 100644
index 0000000..32585be
--- /dev/null
+++ b/build/lib/stanzahandlers/message.php
@@ -0,0 +1,80 @@
+<?php
+
+namespace OCA\OJSXC\StanzaHandlers;
+
+use OCA\OJSXC\Db\MessageMapper;
+use Sabre\Xml\Reader;
+use Sabre\Xml\Writer;
+use OCA\OJSXC\Db\Message as MessageEntity;
+
+/**
+ * Class Message
+ *
+ * @package OCA\OJSXC\StanzaHandlers
+ */
+class Message extends StanzaHandler {
+
+ /**
+ * @var MessageMapper $messageMapper
+ */
+ private $messageMapper;
+
+ /**
+ * @var string $type
+ */
+ private $type;
+
+ /**
+ * @var array $values
+ */
+ private $values;
+
+ /**
+ * @var string $msgId
+ */
+ private $msgId;
+
+ /**
+ * Message constructor.
+ *
+ * @param string $userId
+ * @param string $host
+ * @param MessageMapper $messageMapper
+ */
+ public function __construct($userId, $host, MessageMapper $messageMapper) {
+ parent::__construct($userId, $host);
+ $this->messageMapper = $messageMapper;
+ }
+
+ /**
+ * @param array $stanza
+ */
+ public function handle(array $stanza) {
+ $to = $this->getAttribute($stanza, 'to');
+ $pos = strpos($to, '@');
+ $this->to = substr($to, 0, $pos);
+ foreach($stanza['value'] as $keyRaw=>$value) {
+ // remove namespace from key as it is unneeded and cause problems
+ $key = substr($keyRaw, strpos($keyRaw, '}') + 1, strlen($keyRaw));
+ // fetch namespace from key to readd it
+ $ns = substr($keyRaw, 1, strpos($keyRaw, '}')-1);
+
+ $this->values[] = [
+ "name" => $key,
+ "value" => (string)$value,
+ "attributes" => ["xmlns" => $ns]
+ ];
+ }
+ $this->type = $this->getAttribute($stanza, 'type');
+ $this->msgId = $this->getAttribute($stanza, 'id');
+
+ $message = new MessageEntity();
+ $message->setTo($this->to);
+ $message->setFrom($this->from);
+ $message->setValue($this->values);
+ $message->setType($this->type);
+ $this->messageMapper->insert($message);
+ $this->values = [];
+ }
+
+} \ No newline at end of file