<commit_before><?php

namespace OCA\OJSXC\StanzaHandlers;

use OCA\OJSXC\Db\MessageMapper;
use Sabre\Xml\Reader;
use Sabre\Xml\Writer;

class Message extends StanzaHandler {

	private $messageMapper;

	private $type;

	private $values;

	private $msgId;

	public function __construct($userId, $host, MessageMapper $messageMapper) {
		parent::__construct($userId, $host);
		$this->messageMapper = $messageMapper;
	}

	public function handle($stanza) {
		$this->to = $this->getAttribute($stanza, 'to');
		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 \OCA\OJSXC\Db\Message();
		$message->setTo($this->to);
		$message->setFrom($this->from);
		$message->setValues($this->values);
		$message->setType($this->type);
		$this->messageMapper->insert($message);

	}

}<commit_msg>Fix bug with multiple messages<commit_after><?php

namespace OCA\OJSXC\StanzaHandlers;

use OCA\OJSXC\Db\MessageMapper;
use Sabre\Xml\Reader;
use Sabre\Xml\Writer;

class Message extends StanzaHandler {

	private $messageMapper;

	private $type;

	private $values;

	private $msgId;

	public function __construct($userId, $host, MessageMapper $messageMapper) {
		parent::__construct($userId, $host);
		$this->messageMapper = $messageMapper;
	}

	public function handle($stanza) {
		$this->to = $this->getAttribute($stanza, 'to');
		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 \OCA\OJSXC\Db\Message();
		$message->setTo($this->to);
		$message->setFrom($this->from);
		$message->setValues($this->values);
		$message->setType($this->type);
		$this->messageMapper->insert($message);
		$this->values = [];
	}

}
{'fraction_non_alphanumeric': 0.18985849056603774, 'fraction_numerical': 0.0023584905660377358, 'mean_word_length': 4.46137339055794, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4015337', 'n_tokens_mistral': 973, 'n_tokens_neox': 891, 'n_words': 185}