-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathhooks.php
115 lines (100 loc) · 3.08 KB
/
hooks.php
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
namespace OCA\OJSXC;
use OCA\OJSXC\Db\PresenceMapper;
use OCA\OJSXC\Db\StanzaMapper;
use OCP\IUserManager;
use OCP\IUser;
use OCP\IUserSession;
class Hooks
{
/**
* @var IUserManager
*/
private $userManager;
/**
* @var IUserSession
*/
private $userSession;
/**
* @var PresenceMapper
*/
private $presenceMapper;
/**
* @var StanzaMapper
*/
private $stanzaMapper;
public function __construct(
IUserManager $userManager,
IUserSession $userSession,
RosterPush $rosterPush,
PresenceMapper $presenceMapper,
StanzaMapper $stanzaMapper
) {
$this->userManager = $userManager;
$this->userSession = $userSession;
$this->rosterPush = $rosterPush;
$this->presenceMapper = $presenceMapper;
$this->stanzaMapper = $stanzaMapper;
}
public function register()
{
$this->userManager->listen('\OC\User', 'postCreateUser', [$this, 'onCreateUser']);
$this->userManager->listen('\OC\User', 'postDelete', [$this, 'onDeleteUser']);
$this->userSession->listen('\OC\User', 'changeUser', [$this, 'onChangeUser']);
}
/**
* @brief when a new user is created, the roster of the users must be updated,
* by sending a roster push.
* Note that this can still be useful when the roster and contacts menu are
* merged, for the internal state.
* @see https://tools.ietf.org/html/rfc6121#section-2.1.6
* @param IUser $user
* @param string $password
*/
public function onCreateUser(IUser $user, $password)
{
$this->rosterPush->createOrUpdateRosterItem($user);
}
/**
* @brief when a new user is created, the roster of the users must be updated,
* by sending a roster push.
* Note that this can still be useful when the roster and contacts menu are
* merged, for the internal state. E.g. JSXC removes a chat window, when it
* receives this stanza.
* @see https://tools.ietf.org/html/rfc6121#section-2.1.6
* @param IUser $user
*/
public function onDeleteUser(IUser $user)
{
$this->rosterPush->removeRosterItem($user->getUID());
// delete the presence record of this user
$this->presenceMapper->deletePresence($user->getUID());
// delete all stanzas addressed to this user
$this->stanzaMapper->deleteByTo($user->getUID());
}
/**
* @brief when a use is changed, adapt the roster of the users.
* Note that this can still be useful when the roster and contacts menu are
* merged, for the internal state. E.g. JSXC removes a chat window, when it
* receives this stanza.
* @see https://tools.ietf.org/html/rfc6121#section-2.1.6
* @param IUser $user
* @param string $feature feature which was changed. Enabled and displayName are supported.
* @param string $value
*/
public function onChangeUser(IUser $user, $feature, $value)
{
if ($feature === "enabled") {
if ($value === "true") {
// if user is enabled, add to roster
$this->onCreateUser($user, '');
} elseif ($value === "false") {
// if user is enabled, remove from roster
$this->onDeleteUser($user);
}
} elseif ($feature === "displayName") {
// if the user was changed, resend the whole roster item
$this->onCreateUser($user, '');
}
}
}