Merge pull request #5135 from nextcloud/bugfix/noid/populate-the-display-name-when-adding-participants

Populate the display name when adding logged in users
This commit is contained in:
Joas Schilling 2021-02-12 09:44:44 +01:00 коммит произвёл GitHub
Родитель 69c9a7ef8e 383ca5fd4c
Коммит eb3de685e5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
9 изменённых файлов: 48 добавлений и 2 удалений

Просмотреть файл

@ -341,9 +341,11 @@ class Notifier {
// so they can see the room in their room list and
// the notification can be parsed and links to an existing room,
// where they are a participant of.
$user = $this->userManager->get($userId);
$this->participantService->addUsers($room, [[
'actorType' => Attendee::ACTOR_USERS,
'actorId' => $userId,
'displayName' => $user ? $user->getDisplayName() : $userId,
]]);
return true;
}

Просмотреть файл

@ -282,6 +282,7 @@ trait TRoomCommand {
$participants[] = [
'actorType' => Attendee::ACTOR_USERS,
'actorId' => $user->getUID(),
'displayName' => $user->getDisplayName(),
];
}

Просмотреть файл

@ -899,6 +899,7 @@ class RoomController extends AEnvironmentAwareController {
$participants[] = [
'actorType' => Attendee::ACTOR_USERS,
'actorId' => $user->getUID(),
'displayName' => $user->getDisplayName(),
];
}
@ -954,9 +955,15 @@ class RoomController extends AEnvironmentAwareController {
continue;
}
$user = $this->userManager->get($this->userId);
if (!$user instanceof IUser) {
continue;
}
$participants[] = [
'actorType' => Attendee::ACTOR_USERS,
'actorId' => $member->getUserId(),
'displayName' => $user->getDisplayName(),
];
}
@ -1248,6 +1255,7 @@ class RoomController extends AEnvironmentAwareController {
$participantsToAdd[] = [
'actorType' => Attendee::ACTOR_USERS,
'actorId' => $newUser->getUID(),
'displayName' => $newUser->getDisplayName(),
];
} elseif ($source === 'groups') {
$group = $this->groupManager->get($newParticipant);
@ -1260,6 +1268,7 @@ class RoomController extends AEnvironmentAwareController {
$participantsToAdd[] = [
'actorType' => Attendee::ACTOR_USERS,
'actorId' => $user->getUID(),
'displayName' => $user->getDisplayName(),
];
}
} elseif ($source === 'circles') {
@ -1286,9 +1295,15 @@ class RoomController extends AEnvironmentAwareController {
continue;
}
$user = $this->userManager->get($this->userId);
if (!$user instanceof IUser) {
continue;
}
$participantsToAdd[] = [
'actorType' => Attendee::ACTOR_USERS,
'actorId' => $member->getUserId(),
'displayName' => $user->getDisplayName(),
];
}
} elseif ($source === 'emails') {

Просмотреть файл

@ -33,6 +33,7 @@ use OCA\Talk\Room;
use OCA\Talk\Service\ParticipantService;
use OCA\Talk\TalkSession;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IUserManager;
/**
* Custom behaviour for rooms for files.
@ -56,14 +57,18 @@ class Listener {
protected $util;
/** @var ParticipantService */
protected $participantService;
/** @var IUserManager */
protected $userManager;
/** @var TalkSession */
protected $talkSession;
public function __construct(Util $util,
ParticipantService $participantService,
IUserManager $userManager,
TalkSession $talkSession) {
$this->util = $util;
$this->participantService = $participantService;
$this->userManager = $userManager;
$this->talkSession = $talkSession;
}
@ -154,9 +159,12 @@ class Listener {
try {
$room->getParticipant($userId);
} catch (ParticipantNotFoundException $e) {
$user = $this->userManager->get($userId);
$this->participantService->addUsers($room, [[
'actorType' => Attendee::ACTOR_USERS,
'actorId' => $userId,
'displayName' => $user ? $user->getDisplayName() : $userId,
]]);
}
}

Просмотреть файл

@ -802,9 +802,11 @@ class Manager {
$room->setReadOnly(Room::READ_ONLY);
$room->setListable(Room::LISTABLE_NONE);
$user = $this->userManager->get($userId);
$this->participantService->addUsers($room,[[
'actorType' => Attendee::ACTOR_USERS,
'actorId' => $userId,
'displayName' => $user ? $user->getDisplayName() : $userId,
]]);
return $room;
}
@ -814,9 +816,11 @@ class Manager {
try {
$room->getParticipant($userId);
} catch (ParticipantNotFoundException $e) {
$user = $this->userManager->get($userId);
$this->participantService->addUsers($room,[[
'actorType' => Attendee::ACTOR_USERS,
'actorId' => $userId,
'displayName' => $user ? $user->getDisplayName() : $userId,
]]);
}

Просмотреть файл

@ -309,6 +309,7 @@ class MatterbridgeManager {
$this->participantService->addUsers($room, [[
'actorType' => Attendee::ACTOR_USERS,
'actorId' => $botUserId,
'displayName' => $botUser->getDisplayName(),
'participantType' => Participant::USER,
]]);
}

Просмотреть файл

@ -182,6 +182,7 @@ class ParticipantService {
$this->addUsers($room, [[
'actorType' => Attendee::ACTOR_USERS,
'actorId' => $user->getUID(),
'displayName' => $user->getDisplayName(),
// need to use "USER" here, because "USER_SELF_JOINED" only works for public calls
'participantType' => Participant::USER,
]]);
@ -190,6 +191,7 @@ class ParticipantService {
$this->addUsers($room, [[
'actorType' => Attendee::ACTOR_USERS,
'actorId' => $user->getUID(),
'displayName' => $user->getDisplayName(),
'participantType' => Participant::USER_SELF_JOINED,
]]);
} else {
@ -279,6 +281,9 @@ class ParticipantService {
$attendee->setRoomId($room->getId());
$attendee->setActorType($participant['actorType']);
$attendee->setActorId($participant['actorId']);
if (isset($participant['displayName'])) {
$attendee->setDisplayName($participant['displayName']);
}
$attendee->setParticipantType($participant['participantType'] ?? Participant::USER);
$attendee->setLastReadMessage($lastMessage);
$attendee->setReadPrivacy($readPrivacy);
@ -338,10 +343,12 @@ class ParticipantService {
$missingUsers = array_diff($users, $participants);
foreach ($missingUsers as $userId) {
if ($this->userManager->userExists($userId)) {
$user = $this->userManager->get($userId);
if ($user instanceof IUser) {
$this->addUsers($room, [[
'actorType' => Attendee::ACTOR_USERS,
'actorId' => $userId,
'actorId' => $user->getUID(),
'displayName' => $user->getDisplayName(),
'participantType' => Participant::OWNER,
]]);
}

Просмотреть файл

@ -68,11 +68,13 @@ class RoomService {
[
'actorType' => Attendee::ACTOR_USERS,
'actorId' => $actor->getUID(),
'displayName' => $actor->getDisplayName(),
'participantType' => Participant::OWNER,
],
[
'actorType' => Attendee::ACTOR_USERS,
'actorId' => $targetUser->getUID(),
'displayName' => $targetUser->getDisplayName(),
'participantType' => Participant::OWNER,
],
]);

Просмотреть файл

@ -90,9 +90,13 @@ class RoomServiceTest extends TestCase {
$user1 = $this->createMock(IUser::class);
$user1->method('getUID')
->willReturn('uid1');
$user1->method('getDisplayName')
->willReturn('display-1');
$user2 = $this->createMock(IUser::class);
$user2->method('getUID')
->willReturn('uid2');
$user2->method('getDisplayName')
->willReturn('display-2');
$room = $this->createMock(Room::class);
$this->participantService->expects($this->once())
@ -100,10 +104,12 @@ class RoomServiceTest extends TestCase {
->with($room, [[
'actorType' => 'users',
'actorId' => 'uid1',
'displayName' => 'display-1',
'participantType' => Participant::OWNER,
], [
'actorType' => 'users',
'actorId' => 'uid2',
'displayName' => 'display-2',
'participantType' => Participant::OWNER,
]]);