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

iqrosterpush.php « db « lib « build - github.com/nextcloud/jsxc.nextcloud.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: aebf9dc70aab11cfef17d4cbe5709bc5ce19b850 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php

namespace OCA\OJSXC\Db;

use OCA\OJSXC\AppInfo\Application;
use Sabre\Xml\Reader;
use Sabre\Xml\Writer;
use Sabre\Xml\XmlDeserializable;
use Sabre\Xml\XmlSerializable;

/**
 * This entity represents a roster push.
 * @see https://tools.ietf.org/html/rfc6121#section-2.1.6
 * Class IQRosterPush
 *
 * @package OCA\OJSXC\Db
 * @method void setName($name)
 * @method void setSubscription($subscription)
 * @method string getJid()
 * @method string getName()
 * @method string getSubscription()
 */
class IQRosterPush extends Stanza implements XmlSerializable
{

	/**
	 * @var string jid of the user, when inserting this into the DB, only userid
	 * is needed.
	 */
	public $jid;

	/**
	 * @var string displayname of the user
	 */
	public $name;

	/**
	 * @var string subscription type. Both and remove are used.
	 */
	public $subscription;

	/**
	 * Sets the to user as a `user`.
	 *
	 * @see setFullJid
	 * @param $userId
	 * @param null $host_and_or_resource
	 */
	public function setJid($userId, $host_and_or_resource = null)
	{
		$this->jid = Application::santizeUserId($userId);
		if (!is_null($host_and_or_resource)) {
			$this->jid .= '@' . $host_and_or_resource;
		}
	}

	public function xmlSerialize(Writer $writer)
	{
		$writer->write([
			[
				'name' => 'iq',
				'attributes' => [
					'to' => $this->to,
					'type' => 'set',
					'id' => uniqid()
				],
				'value' => [[
					'name' => 'query',
					'attributes' => [
						'xmlns' => 'jabber:iq:roster',
					],
					'value' => [
						"name" => "item",
						"attributes" => [
							"jid" => $this->jid,
							"name" => $this->name,
							"subscription" => $this->subscription
						],
						"value" => ''
					]
				]]
			]
		]);
	}
}