blob: 9d36cc666f9e227afb085e7045eef92c6bed239a (
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
|
<?php
namespace OCA\OJSXC\StanzaHandlers;
use OCA\OJSXC\Db\IQRoster;
use OCP\IConfig;
use OCP\IUserManager;
use Sabre\Xml\Reader;
use Sabre\Xml\Writer;
use OCA\OJSXC\AppInfo\Application;
/**
* Class IQ
*
* @package OCA\OJSXC\StanzaHandlers
*/
class IQ extends StanzaHandler
{
/**
* @var IUserManager
*/
private $userManager;
/**
* @var IConfig
*/
private $config;
/**
* IQ constructor.
*
* @param string $userId
* @param string $host
* @param IUserManager $userManager
* @param IConfig $config
*/
public function __construct($userId, $host, IUserManager $userManager, IConfig $config)
{
parent::__construct($userId, $host);
$this->userManager = $userManager;
$this->config = $config;
}
/**
* @param array $stanza
* @return IQRoster
*/
public function handle(array $stanza)
{
$this->to = $this->getAttribute($stanza, 'to');
// if in debug mode we show the own username in the roster for testing
$debugMode = $this->config->getSystemValue("debug");
if ($stanza['value'][0]['name'] === '{jabber:iq:roster}query') {
$id = $stanza['attributes']['id'];
$iqRoster = new IQRoster();
$iqRoster->setType('result');
$iqRoster->setTo($this->userId);
$iqRoster->setQid($id);
foreach ($this->userManager->search('') as $user) {
$userId = Application::santizeUserId($user->getUID());
if ($debugMode || ($userId !== $this->userId && $user->isEnabled())) {
$iqRoster->addItem($userId . '@' . $this->host, $user->getDisplayName());
}
}
return $iqRoster;
}
}
}
|