Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update roster according to adding/removing of users to groups
  • Loading branch information
LEDfan committed Feb 8, 2018
commit 1b7c93a5adcfec566013ea136c85871e58d76598
3 changes: 2 additions & 1 deletion appinfo/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ public function __construct(array $urlParams=array()){
$c->query('ServerContainer')->getUserSession(),
$c->query('RosterPush'),
$c->query('PresenceMapper'),
$c->query('StanzaMapper')
$c->query('StanzaMapper'),
$c->query('ServerContainer')->query('OCP\IGroupManager')
);
});

Expand Down
29 changes: 28 additions & 1 deletion lib/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use OCA\OJSXC\Db\PresenceMapper;
use OCA\OJSXC\Db\StanzaMapper;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IUserManager;

use OCP\IUser;
Expand Down Expand Up @@ -32,25 +34,39 @@ class Hooks
*/
private $stanzaMapper;

/**
* @var RosterPush
*/
private $rosterPush;

/**
* @var IGroupManager
*/
private $groupManager;

public function __construct(
IUserManager $userManager,
IUserSession $userSession,
RosterPush $rosterPush,
PresenceMapper $presenceMapper,
StanzaMapper $stanzaMapper
StanzaMapper $stanzaMapper,
IGroupManager $groupManager
) {
$this->userManager = $userManager;
$this->userSession = $userSession;
$this->rosterPush = $rosterPush;
$this->presenceMapper = $presenceMapper;
$this->stanzaMapper = $stanzaMapper;
$this->groupManager = $groupManager;
}

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']);
$this->groupManager->listen('\OC\Group', 'postAddUser', [$this, 'onAddUserToGroup']);
$this->groupManager->listen('\OC\Group', 'postRemoveUser', [$this, 'onRemoveUserFromGroup']);
}

/**
Expand Down Expand Up @@ -112,4 +128,15 @@ public function onChangeUser(IUser $user, $feature, $value)
$this->onCreateUser($user, '');
}
}

public function onAddUserToGroup(IGroup $group, IUser $user)
{
$this->rosterPush->createOrUpdateRosterItem($user);
}

public function onRemoveUserFromGroup(IGroup $group, IUser $user)
{
$this->rosterPush->removeRosterItemForUsersInGroup($group, $user->getUID());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO this must only be done when one of the privacy options is enabled and when running on version > 12.0.3

}

}
18 changes: 18 additions & 0 deletions lib/rosterpush.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use OCA\OJSXC\Db\IQRosterPush;
use OCA\OJSXC\Db\IQRosterPushMapper;
use OCP\IDBConnection;
use OCP\IGroup;
use OCP\IUserManager;

use OCP\IUser;
Expand Down Expand Up @@ -158,4 +159,21 @@ public function refreshRoster()

return $stats;
}

public function removeRosterItemForUsersInGroup(IGroup $group, $userId) {
$iq = new IQRosterPush();
$iq->setJid($userId);
$iq->setSubscription('remove');
$iq->setFrom('');


foreach ($group->getUsers() as $recipient) {
if ($recipient->getUID() !== $userId) {
$iq->setTo($recipient->getUID());
$this->iqRosterPushMapper->insert($iq);
}
}

}

}