-
Notifications
You must be signed in to change notification settings - Fork 508
Sync group members with conversation participants #4810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nickvergessen
merged 19 commits into
master
from
feature/1329/sync-group-members-with-conversation-participants
Apr 8, 2021
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
d7bd1a8
Add a method to add group members directly to a conversation
nickvergessen db91242
Keep track of added groups
nickvergessen 2db230b
Add and remove users from conversations when their group membership c…
nickvergessen b37dade
Fix constant value to plural
nickvergessen b532b28
Fix command integration tests
nickvergessen 9edff03
Add expected group to output
nickvergessen 55981db
Make sure existing self-joined users are converted to added users
nickvergessen 4ccc537
Save and show the display name of groups
nickvergessen 1e66602
Show groups at the end and don't allow promoting
nickvergessen bc4f7e5
Prevent promoting/demoting groups on API level
nickvergessen 8608bdc
Filter out groups which are already participants
nickvergessen 0253a69
Don't error when a user is already a member
nickvergessen 5730ef0
Add integration tests
nickvergessen 44a7308
Only remove users and not moderators when a group (membership) is rem…
nickvergessen 672f06f
Ignore the read status of groups and store the displayname on adding …
nickvergessen 807c8a0
Change misleading computed name
nickvergessen b48ce35
Adjust label when removing a group
nickvergessen 269ac90
Add integration tests for multi group scenarios
nickvergessen 4b268d0
Rename test file
nickvergessen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
| /** | ||
| * @copyright Copyright (c) 2020 Joas Schilling <[email protected]> | ||
| * | ||
| * @license GNU AGPL version 3 or any later version | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
|
|
||
| namespace OCA\Talk\Listener; | ||
|
|
||
| use OCA\Talk\Exceptions\ParticipantNotFoundException; | ||
| use OCA\Talk\Manager; | ||
| use OCA\Talk\Model\Attendee; | ||
| use OCA\Talk\Participant; | ||
| use OCA\Talk\Room; | ||
| use OCA\Talk\Service\ParticipantService; | ||
| use OCP\EventDispatcher\Event; | ||
| use OCP\EventDispatcher\IEventListener; | ||
| use OCP\Group\Events\UserAddedEvent; | ||
| use OCP\Group\Events\UserRemovedEvent; | ||
| use OCP\IGroup; | ||
| use OCP\IGroupManager; | ||
| use OCP\IUser; | ||
|
|
||
| class GroupMembershipListener implements IEventListener { | ||
|
|
||
| /** @var IGroupManager */ | ||
| private $groupManager; | ||
| /** @var Manager */ | ||
| private $manager; | ||
| /** @var ParticipantService */ | ||
| private $participantService; | ||
|
|
||
| public function __construct(IGroupManager $groupManager, | ||
| Manager $manager, | ||
| ParticipantService $participantService) { | ||
| $this->groupManager = $groupManager; | ||
| $this->manager = $manager; | ||
| $this->participantService = $participantService; | ||
| } | ||
|
|
||
| public function handle(Event $event): void { | ||
| if ($event instanceof UserAddedEvent) { | ||
| $this->addNewMemberToRooms($event->getGroup(), $event->getUser()); | ||
| } | ||
| if ($event instanceof UserRemovedEvent) { | ||
| $this->removeFormerMemberFromRooms($event->getGroup(), $event->getUser()); | ||
| } | ||
| } | ||
|
|
||
| protected function addNewMemberToRooms(IGroup $group, IUser $user): void { | ||
| $rooms = $this->manager->getRoomsForActor(Attendee::ACTOR_GROUPS, $group->getGID()); | ||
|
|
||
| foreach ($rooms as $room) { | ||
| try { | ||
| $participant = $room->getParticipant($user->getUID()); | ||
| if ($participant->getAttendee()->getParticipantType() === Participant::USER_SELF_JOINED) { | ||
| $this->participantService->updateParticipantType($room, $participant, Participant::USER); | ||
| } | ||
| } catch (ParticipantNotFoundException $e) { | ||
| $this->participantService->addUsers($room, [[ | ||
| 'actorType' => Attendee::ACTOR_USERS, | ||
| 'actorId' => $user->getUID(), | ||
| 'displayName' => $user->getDisplayName(), | ||
| ]]); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| protected function removeFormerMemberFromRooms(IGroup $group, IUser $user): void { | ||
| $rooms = $this->manager->getRoomsForActor(Attendee::ACTOR_GROUPS, $group->getGID()); | ||
| if (empty($rooms)) { | ||
| return; | ||
| } | ||
|
|
||
| $userGroupIds = $this->groupManager->getUserGroupIds($user); | ||
|
|
||
| $furtherMemberships = []; | ||
| foreach ($userGroupIds as $groupId) { | ||
| $groupRooms = $this->manager->getRoomsForActor(Attendee::ACTOR_GROUPS, $groupId); | ||
| foreach ($groupRooms as $room) { | ||
| $furtherMemberships[$room->getId()] = true; | ||
| } | ||
| } | ||
|
|
||
| $rooms = array_filter($rooms, static function (Room $room) use ($furtherMemberships) { | ||
| // Only delete from rooms where the user is not member via another group | ||
| return !isset($furtherMemberships[$room->getId()]); | ||
| }); | ||
|
|
||
| foreach ($rooms as $room) { | ||
| try { | ||
| $participant = $room->getParticipant($user->getUID()); | ||
| $participantType = $participant->getAttendee()->getParticipantType(); | ||
| if ($participantType === Participant::USER) { | ||
| $this->participantService->removeUser($room, $user, Room::PARTICIPANT_REMOVED); | ||
| } | ||
| } catch (ParticipantNotFoundException $e) { | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.