зеркало из https://github.com/nextcloud/spreed.git
Merge pull request #5691 from nextcloud/bugfix/noid/bug-fix-circles-integration
Deduplicate and bug-fix circles integration
This commit is contained in:
Коммит
e9854656f3
|
@ -29,7 +29,6 @@ namespace OCA\Talk\Controller;
|
|||
|
||||
use InvalidArgumentException;
|
||||
use OCA\Circles\Api\v1\Circles;
|
||||
use OCA\Circles\Model\Member;
|
||||
use OCA\Talk\Chat\ChatManager;
|
||||
use OCA\Talk\Chat\MessageParser;
|
||||
use OCA\Talk\Config;
|
||||
|
@ -710,38 +709,7 @@ class RoomController extends AEnvironmentAwareController {
|
|||
// Create the room
|
||||
$name = $this->roomService->prepareConversationName($circle->getName());
|
||||
$room = $this->roomService->createConversation(Room::GROUP_CALL, $name, $currentUser);
|
||||
|
||||
$participants = [];
|
||||
foreach ($circle->getMembers() as $member) {
|
||||
/** @var Member $member */
|
||||
if ($member->getType() !== Member::TYPE_USER || $member->getUserId() === '') {
|
||||
// Not a user?
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($currentUser->getUID() === $member->getUserId()) {
|
||||
// Current user is already added
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($member->getStatus() !== Member::STATUS_INVITED && $member->getStatus() !== Member::STATUS_MEMBER) {
|
||||
// Only allow invited and regular members
|
||||
continue;
|
||||
}
|
||||
|
||||
$user = $this->userManager->get($this->userId);
|
||||
if (!$user instanceof IUser) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$participants[] = [
|
||||
'actorType' => Attendee::ACTOR_USERS,
|
||||
'actorId' => $member->getUserId(),
|
||||
'displayName' => $user->getDisplayName(),
|
||||
];
|
||||
}
|
||||
|
||||
$this->participantService->addUsers($room, $participants);
|
||||
$this->participantService->addCircle($room, $circle);
|
||||
|
||||
return new DataResponse($this->formatRoom($room, $room->getParticipant($currentUser->getUID(), false)), Http::STATUS_CREATED);
|
||||
}
|
||||
|
@ -1057,29 +1025,7 @@ class RoomController extends AEnvironmentAwareController {
|
|||
return new DataResponse([], Http::STATUS_NOT_FOUND);
|
||||
}
|
||||
|
||||
foreach ($circle->getMembers() as $member) {
|
||||
/** @var Member $member */
|
||||
if ($member->getType() !== Member::TYPE_USER || $member->getUserId() === '') {
|
||||
// Not a user?
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($member->getStatus() !== Member::STATUS_INVITED && $member->getStatus() !== Member::STATUS_MEMBER) {
|
||||
// Only allow invited and regular members
|
||||
continue;
|
||||
}
|
||||
|
||||
$user = $this->userManager->get($this->userId);
|
||||
if (!$user instanceof IUser) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$participantsToAdd[] = [
|
||||
'actorType' => Attendee::ACTOR_USERS,
|
||||
'actorId' => $member->getUserId(),
|
||||
'displayName' => $user->getDisplayName(),
|
||||
];
|
||||
}
|
||||
$this->participantService->addCircle($this->room, $circle, $participants);
|
||||
} elseif ($source === 'emails') {
|
||||
$data = [];
|
||||
if ($this->room->setType(Room::PUBLIC_CALL)) {
|
||||
|
|
|
@ -23,6 +23,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace OCA\Talk\Service;
|
||||
|
||||
use OCA\Circles\Model\Circle;
|
||||
use OCA\Circles\Model\Member;
|
||||
use OCA\Talk\Config;
|
||||
use OCA\Talk\Events\AddParticipantsEvent;
|
||||
use OCA\Talk\Events\JoinRoomGuestEvent;
|
||||
|
@ -361,6 +363,77 @@ class ParticipantService {
|
|||
$this->addUsers($room, $newParticipants);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Room $room
|
||||
* @param Circle $circle
|
||||
* @param Participant[] $existingParticipants
|
||||
*/
|
||||
public function addCircle(Room $room, Circle $circle, array $existingParticipants = []): void {
|
||||
$membersInCircle = $circle->getMembers();
|
||||
|
||||
if (empty($existingParticipants)) {
|
||||
$existingParticipants = $this->getParticipantsForRoom($room);
|
||||
}
|
||||
|
||||
$participantsByUserId = [];
|
||||
foreach ($existingParticipants as $participant) {
|
||||
if ($participant->getAttendee()->getActorType() === Attendee::ACTOR_USERS) {
|
||||
$participantsByUserId[$participant->getAttendee()->getActorId()] = $participant;
|
||||
}
|
||||
}
|
||||
|
||||
$newParticipants = [];
|
||||
foreach ($membersInCircle as $member) {
|
||||
/** @var Member $member */
|
||||
if ($member->getUserType() !== Member::TYPE_USER || $member->getUserId() === '') {
|
||||
// Not a user?
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($member->getStatus() !== Member::STATUS_INVITED && $member->getStatus() !== Member::STATUS_MEMBER) {
|
||||
// Only allow invited and regular members
|
||||
continue;
|
||||
}
|
||||
|
||||
$user = $this->userManager->get($member->getUserId());
|
||||
if (!$user instanceof IUser) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$existingParticipant = $participantsByUserId[$user->getUID()] ?? null;
|
||||
if ($existingParticipant instanceof Participant) {
|
||||
if ($existingParticipant->getAttendee()->getParticipantType() === Participant::USER_SELF_JOINED) {
|
||||
$this->updateParticipantType($room, $existingParticipant, Participant::USER);
|
||||
}
|
||||
|
||||
// Participant is already in the conversation, so skip them.
|
||||
continue;
|
||||
}
|
||||
|
||||
$newParticipants[] = [
|
||||
'actorType' => Attendee::ACTOR_USERS,
|
||||
'actorId' => $user->getUID(),
|
||||
'displayName' => $user->getDisplayName(),
|
||||
];
|
||||
}
|
||||
|
||||
// No tracking of circles for now
|
||||
// try {
|
||||
// $this->attendeeMapper->findByActor($room->getId(), Attendee::ACTOR_CIRCLES, $circle->getSingleId());
|
||||
// } catch (DoesNotExistException $e) {
|
||||
// $attendee = new Attendee();
|
||||
// $attendee->setRoomId($room->getId());
|
||||
// $attendee->setActorType(Attendee::ACTOR_CIRCLES);
|
||||
// $attendee->setActorId($circle->getSingleId());
|
||||
// $attendee->setDisplayName($circle->getDisplayName());
|
||||
// $attendee->setParticipantType(Participant::USER);
|
||||
// $attendee->setReadPrivacy(Participant::PRIVACY_PRIVATE);
|
||||
// $this->attendeeMapper->insert($attendee);
|
||||
// }
|
||||
|
||||
$this->addUsers($room, $newParticipants);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Room $room
|
||||
* @param string $email
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
<referencedClass name="Doctrine\DBAL\Types\Types" />
|
||||
<referencedClass name="OC" />
|
||||
<referencedClass name="OCA\Files_Sharing\SharedStorage" />
|
||||
<referencedClass name="OCA\Circles\Model\Circle" />
|
||||
<referencedClass name="OCA\Circles\Model\Member" />
|
||||
</errorLevel>
|
||||
</UndefinedClass>
|
||||
<UndefinedDocblockClass>
|
||||
|
@ -37,6 +39,7 @@
|
|||
<referencedClass name="Doctrine\DBAL\Schema\SchemaException" />
|
||||
<referencedClass name="Doctrine\DBAL\Schema\Table" />
|
||||
<referencedClass name="OC\DB\ConnectionAdapter" />
|
||||
<referencedClass name="OCA\Circles\Model\Member" />
|
||||
</errorLevel>
|
||||
</UndefinedDocblockClass>
|
||||
<UndefinedInterfaceMethod>
|
||||
|
|
Загрузка…
Ссылка в новой задаче