зеркало из https://github.com/nextcloud/spreed.git
Make room names non-optional
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Родитель
1a4f96436a
Коммит
7e54634fb5
|
@ -174,7 +174,7 @@ Base endpoint is: `/ocs/v2.php/apps/spreed/api/v1`
|
|||
* Response:
|
||||
- Header:
|
||||
+ `200 OK`
|
||||
+ `400 Bad Request` When the name is too long
|
||||
+ `400 Bad Request` When the name is too long or empty
|
||||
+ `403 Forbidden` When the current user is not a moderator/owner
|
||||
+ `404 Not Found` When the room could not be found for the participant
|
||||
+ `405 Method Not Allowed` When the room is a one to one room
|
||||
|
|
|
@ -136,7 +136,7 @@
|
|||
});
|
||||
results.push({
|
||||
id: "create-public-room",
|
||||
displayName: t('spreed', '{name} (public)', { name: shortenedName }),
|
||||
displayName: shortenedName,
|
||||
type: "createPublicRoom"
|
||||
});
|
||||
}
|
||||
|
@ -152,7 +152,7 @@
|
|||
},
|
||||
formatResult: function (element) {
|
||||
if (element.type === "createPublicRoom") {
|
||||
return '<span><div class="avatar icon icon-public"></div>' + escapeHTML(element.displayName) + '</span>';
|
||||
return '<span><div class="avatar icon icon-public"></div>' + t('spreed', '{name} (public)', { name: element.displayName }) + '</span>';
|
||||
}
|
||||
|
||||
if (element.type === "createGroupRoom" || element.type === 'group') {
|
||||
|
|
|
@ -219,6 +219,9 @@
|
|||
this.modelSaveOptions.success.apply(this, arguments);
|
||||
}
|
||||
}, this);
|
||||
options.error = _.bind(function() {
|
||||
this.hideInput();
|
||||
}, this);
|
||||
|
||||
this.model.save(this.modelAttribute, newText, options);
|
||||
},
|
||||
|
|
|
@ -125,7 +125,7 @@ class Listener {
|
|||
$event->setApp('spreed')
|
||||
->setType('spreed')
|
||||
->setAuthor('')
|
||||
->setObject('room', $room->getId(), $room->getName())
|
||||
->setObject('room', $room->getId())
|
||||
->setTimestamp($this->timeFactory->getTime())
|
||||
->setSubject('call', [
|
||||
'room' => $room->getId(),
|
||||
|
@ -180,12 +180,11 @@ class Listener {
|
|||
$event->setApp('spreed')
|
||||
->setType('spreed')
|
||||
->setAuthor($actorId)
|
||||
->setObject('room', $room->getId(), $room->getName())
|
||||
->setObject('room', $room->getId())
|
||||
->setTimestamp($this->timeFactory->getTime())
|
||||
->setSubject('invitation', [
|
||||
'user' => $actor->getUID(),
|
||||
'room' => $room->getId(),
|
||||
'name' => $room->getName(),
|
||||
]);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$this->logger->logException($e, ['app' => 'spreed']);
|
||||
|
@ -199,7 +198,15 @@ class Listener {
|
|||
}
|
||||
|
||||
try {
|
||||
$event->setAffectedUser($participant['userId']);
|
||||
$roomName = $room->getDisplayName($participant['userId']);
|
||||
$event
|
||||
->setObject('room', $room->getId(), $roomName)
|
||||
->setSubject('invitation', [
|
||||
'user' => $actor->getUID(),
|
||||
'room' => $room->getId(),
|
||||
'name' => $roomName,
|
||||
])
|
||||
->setAffectedUser($participant['userId']);
|
||||
$this->activityManager->publish($event);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$this->logger->logException($e, ['app' => 'spreed']);
|
||||
|
|
|
@ -101,7 +101,7 @@ abstract class Base implements IProvider {
|
|||
->setRichSubject($subject, $parameters);
|
||||
}
|
||||
|
||||
protected function getRoom(IL10N $l, Room $room): array {
|
||||
protected function getRoom(Room $room, string $userId): array {
|
||||
switch ($room->getType()) {
|
||||
case Room::ONE_TO_ONE_CALL:
|
||||
$stringType = 'one2one';
|
||||
|
@ -118,7 +118,7 @@ abstract class Base implements IProvider {
|
|||
return [
|
||||
'type' => 'call',
|
||||
'id' => $room->getId(),
|
||||
'name' => $room->getName() ?: $l->t('a conversation'),
|
||||
'name' => $room->getDisplayName($userId),
|
||||
'call-type' => $stringType,
|
||||
];
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ class Invitation extends Base {
|
|||
$roomParameter = $this->getFormerRoom($l, (int) $parameters['room']);
|
||||
try {
|
||||
$room = $this->manager->getRoomById((int) $parameters['room']);
|
||||
$roomParameter = $this->getRoom($l, $room);
|
||||
$roomParameter = $this->getRoom($room, $event->getAffectedUser());
|
||||
} catch (RoomNotFoundException $e) {
|
||||
}
|
||||
|
||||
|
|
|
@ -103,7 +103,7 @@ class UserMention {
|
|||
$messageParameters[$mentionParameterId] = [
|
||||
'type' => $mention['type'],
|
||||
'id' => $chatMessage->getRoom()->getToken(),
|
||||
'name' => $chatMessage->getRoom()->getName() ?: $this->l->t('Conversation'),
|
||||
'name' => $chatMessage->getRoom()->getDisplayName($chatMessage->getParticipant()->getUser()),
|
||||
'call-type' => $this->getRoomType($chatMessage->getRoom()),
|
||||
];
|
||||
} else {
|
||||
|
|
|
@ -53,14 +53,16 @@ class RoomPlugin implements ISearchPlugin {
|
|||
return false;
|
||||
}
|
||||
|
||||
$userId = $this->userSession->getUser()->getUID();
|
||||
|
||||
$result = ['wide' => [], 'exact' => []];
|
||||
|
||||
$rooms = $this->manager->getRoomsForParticipant($this->userSession->getUser()->getUID());
|
||||
$rooms = $this->manager->getRoomsForParticipant($userId);
|
||||
foreach ($rooms as $room) {
|
||||
if (stripos($room->getName(), $search) !== false) {
|
||||
$item = $this->roomToSearchResultItem($room);
|
||||
$item = $this->roomToSearchResultItem($room, $userId);
|
||||
|
||||
if (strtolower($room->getName()) === strtolower($search)) {
|
||||
if (strtolower($item['label']) === strtolower($search)) {
|
||||
$result['exact'][] = $item;
|
||||
} else {
|
||||
$result['wide'][] = $item;
|
||||
|
@ -74,14 +76,10 @@ class RoomPlugin implements ISearchPlugin {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Room $room
|
||||
* @return array
|
||||
*/
|
||||
private function roomToSearchResultItem(Room $room): array {
|
||||
private function roomToSearchResultItem(Room $room, string $userId): array {
|
||||
return
|
||||
[
|
||||
'label' => $room->getName(),
|
||||
'label' => $room->getDisplayName($userId),
|
||||
'value' => [
|
||||
'shareType' => Share::SHARE_TYPE_ROOM,
|
||||
'shareWith' => $room->getToken()
|
||||
|
|
|
@ -336,7 +336,7 @@ class ChatController extends OCSController {
|
|||
try {
|
||||
/** @var Room $room */
|
||||
/** @var Participant $participant */
|
||||
[$room, ] = $this->getRoomAndParticipant($token);
|
||||
[$room, $participant] = $this->getRoomAndParticipant($token);
|
||||
} catch (RoomNotFoundException $e) {
|
||||
return new DataResponse([], Http::STATUS_NOT_FOUND);
|
||||
}
|
||||
|
@ -364,7 +364,7 @@ class ChatController extends OCSController {
|
|||
if ($search === '' || strpos('all', $search) !== false) {
|
||||
array_unshift($results, [
|
||||
'id' => 'all',
|
||||
'label' => $room->getName() ?: $this->l->t('Conversation'),
|
||||
'label' => $room->getDisplayName($participant->getUser()),
|
||||
'source' => 'calls',
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ use OCP\AppFramework\OCSController;
|
|||
use OCP\IRequest;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IUserSession;
|
||||
use OCP\Share;
|
||||
use OCP\Share\IManager as IShareManager;
|
||||
use OCP\Share\Exceptions\ShareNotFound;
|
||||
|
@ -41,6 +42,8 @@ class PublicShareAuthController extends OCSController {
|
|||
private $userManager;
|
||||
/** @var IShareManager */
|
||||
private $shareManager;
|
||||
/** @var IUserSession */
|
||||
private $userSession;
|
||||
/** @var Manager */
|
||||
private $manager;
|
||||
|
||||
|
@ -49,11 +52,13 @@ class PublicShareAuthController extends OCSController {
|
|||
IRequest $request,
|
||||
IUserManager $userManager,
|
||||
IShareManager $shareManager,
|
||||
IUserSession $userSession,
|
||||
Manager $manager
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
$this->userManager = $userManager;
|
||||
$this->shareManager = $shareManager;
|
||||
$this->userSession = $userSession;
|
||||
$this->manager = $manager;
|
||||
}
|
||||
|
||||
|
@ -106,10 +111,13 @@ class PublicShareAuthController extends OCSController {
|
|||
'participantType' => Participant::OWNER,
|
||||
]);
|
||||
|
||||
$user = $this->userSession->getUser();
|
||||
$userId = $user instanceof IUser ? $user->getUID() : '';
|
||||
|
||||
return new DataResponse([
|
||||
'token' => $room->getToken(),
|
||||
'name' => $room->getName(),
|
||||
'displayName' => $room->getName(),
|
||||
'displayName' => $room->getDisplayName($userId),
|
||||
], Http::STATUS_CREATED);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -197,7 +197,7 @@ class RoomController extends OCSController {
|
|||
|
||||
$roomData = array_merge($roomData, [
|
||||
'name' => $room->getName(),
|
||||
'displayName' => $room->getName(),
|
||||
'displayName' => $room->getDisplayName($currentParticipant->getUser()),
|
||||
'objectType' => $room->getObjectType(),
|
||||
'objectId' => $room->getObjectId(),
|
||||
'participantType' => $currentParticipant->getParticipantType(),
|
||||
|
@ -219,11 +219,6 @@ class RoomController extends OCSController {
|
|||
}
|
||||
}
|
||||
|
||||
if ($room->getObjectType() === 'share:password') {
|
||||
// FIXME use an event
|
||||
$roomData['displayName'] = $this->l10n->t('Password request: %s', [$room->getName()]);
|
||||
}
|
||||
|
||||
$currentUser = $this->userManager->get($currentParticipant->getUser());
|
||||
if ($currentUser instanceof IUser) {
|
||||
$unreadSince = $this->chatManager->getUnreadMarker($room, $currentUser);
|
||||
|
@ -285,76 +280,6 @@ class RoomController extends OCSController {
|
|||
'lastMessage' => $lastMessage,
|
||||
]);
|
||||
|
||||
if (!$currentParticipant->isGuest()) {
|
||||
unset($participantList[$currentParticipant->getUser()]);
|
||||
$numOtherParticipants = \count($participantList);
|
||||
$numGuestParticipants = $numActiveGuests;
|
||||
} else {
|
||||
$numOtherParticipants = \count($participantList);
|
||||
$numGuestParticipants = $numActiveGuests - 1;
|
||||
}
|
||||
|
||||
$guestString = '';
|
||||
switch ($room->getType()) {
|
||||
case Room::ONE_TO_ONE_CALL:
|
||||
// As name of the room use the name of the other person participating
|
||||
if ($numOtherParticipants === 1) {
|
||||
// Only one other participant
|
||||
reset($participantList);
|
||||
$roomData['name'] = key($participantList);
|
||||
$roomData['displayName'] = $participantList[$roomData['name']]['name'];
|
||||
} else {
|
||||
// Invalid user count, there must be exactly 2 users in each one2one room
|
||||
$this->logger->warning('one2one room found with invalid participant count. Leaving room for everyone', [
|
||||
'app' => 'spreed',
|
||||
]);
|
||||
$room->deleteRoom();
|
||||
}
|
||||
break;
|
||||
|
||||
/** @noinspection PhpMissingBreakStatementInspection */
|
||||
case Room::PUBLIC_CALL:
|
||||
if ($numGuestParticipants) {
|
||||
if ($currentParticipant->isGuest()) {
|
||||
$guestString = $this->l10n->n('%n other guest', '%n other guests', $numGuestParticipants);
|
||||
} else {
|
||||
$guestString = $this->l10n->n('%n guest', '%n guests', $numGuestParticipants);
|
||||
}
|
||||
}
|
||||
|
||||
// no break;
|
||||
|
||||
case Room::GROUP_CALL:
|
||||
if ($room->getName() === '') {
|
||||
// As name of the room use the names of the other participants
|
||||
$participantList = array_map(function($participant) {
|
||||
return $participant['name'];
|
||||
}, $participantList);
|
||||
if ($currentParticipant->isGuest()) {
|
||||
$participantList[] = $this->l10n->t('You');
|
||||
} else if ($numOtherParticipants === 0) {
|
||||
$participantList = [$this->l10n->t('You')];
|
||||
}
|
||||
|
||||
if ($guestString !== '') {
|
||||
$participantList[] = $guestString;
|
||||
}
|
||||
|
||||
$roomData['displayName'] = implode($this->l10n->t(', '), $participantList);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// Invalid room type
|
||||
$this->logger->warning('Invalid room type found. Leaving room for everyone', [
|
||||
'app' => 'spreed',
|
||||
]);
|
||||
$room->deleteRoom();
|
||||
throw new RoomNotFoundException('The room type is unknown');
|
||||
}
|
||||
|
||||
$roomData['guestList'] = $guestString;
|
||||
|
||||
return $roomData;
|
||||
}
|
||||
|
||||
|
@ -450,7 +375,7 @@ class RoomController extends OCSController {
|
|||
return new DataResponse([
|
||||
'token' => $room->getToken(),
|
||||
'name' => $room->getName(),
|
||||
'displayName' => $targetUser->getDisplayName(),
|
||||
'displayName' => $room->getDisplayName($currentUser->getUID()),
|
||||
], Http::STATUS_CREATED);
|
||||
}
|
||||
}
|
||||
|
@ -500,7 +425,7 @@ class RoomController extends OCSController {
|
|||
return new DataResponse([
|
||||
'token' => $room->getToken(),
|
||||
'name' => $room->getName(),
|
||||
'displayName' => $room->getName(),
|
||||
'displayName' => $room->getDisplayName($currentUser->getUID()),
|
||||
], Http::STATUS_CREATED);
|
||||
}
|
||||
|
||||
|
@ -512,6 +437,11 @@ class RoomController extends OCSController {
|
|||
* @return DataResponse
|
||||
*/
|
||||
protected function createEmptyRoom(string $roomName, bool $public = true): DataResponse {
|
||||
$roomName = trim($roomName);
|
||||
if ($roomName === '') {
|
||||
return new DataResponse([], Http::STATUS_BAD_REQUEST);
|
||||
}
|
||||
|
||||
$currentUser = $this->userManager->get($this->userId);
|
||||
|
||||
if (!$currentUser instanceof IUser) {
|
||||
|
@ -532,7 +462,7 @@ class RoomController extends OCSController {
|
|||
return new DataResponse([
|
||||
'token' => $room->getToken(),
|
||||
'name' => $room->getName(),
|
||||
'displayName' => $room->getName(),
|
||||
'displayName' => $room->getDisplayName($currentUser->getUID()),
|
||||
], Http::STATUS_CREATED);
|
||||
}
|
||||
|
||||
|
@ -628,7 +558,9 @@ class RoomController extends OCSController {
|
|||
return new DataResponse([], Http::STATUS_FORBIDDEN);
|
||||
}
|
||||
|
||||
if (strlen($roomName) > 200) {
|
||||
$roomName = trim($roomName);
|
||||
|
||||
if ($roomName === '' || strlen($roomName) > 200) {
|
||||
return new DataResponse([], Http::STATUS_BAD_REQUEST);
|
||||
}
|
||||
|
||||
|
|
|
@ -441,7 +441,7 @@ class SignalingController extends OCSController {
|
|||
'version' => '1.0',
|
||||
'roomid' => $room->getToken(),
|
||||
'properties' => [
|
||||
'name' => $room->getName(),
|
||||
'name' => $room->getDisplayName((string) $userId),
|
||||
'type' => $room->getType(),
|
||||
],
|
||||
],
|
||||
|
|
|
@ -171,7 +171,7 @@ class GuestManager {
|
|||
|
||||
$template = $this->mailer->createEMailTemplate('Talk.InviteByEmail', [
|
||||
'invitee' => $invitee,
|
||||
'roomName' => $room->getName(),
|
||||
'roomName' => $room->getDisplayName(''),
|
||||
'roomLink' => $link,
|
||||
]);
|
||||
|
||||
|
@ -191,17 +191,10 @@ class GuestManager {
|
|||
$subject
|
||||
);
|
||||
|
||||
if ($room->getName()) {
|
||||
$template->addBodyButton(
|
||||
$this->l->t('Join »%s«', [$room->getName()]),
|
||||
$link
|
||||
);
|
||||
} else {
|
||||
$template->addBodyButton(
|
||||
$this->l->t('Join now'),
|
||||
$link
|
||||
);
|
||||
}
|
||||
$template->addBodyButton(
|
||||
$this->l->t('Join »%s«', [$room->getDisplayName('')]),
|
||||
$link
|
||||
);
|
||||
|
||||
$template->addFooter();
|
||||
|
||||
|
|
|
@ -29,6 +29,9 @@ use OCP\AppFramework\Utility\ITimeFactory;
|
|||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
use OCP\IConfig;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IL10N;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Security\IHasher;
|
||||
use OCP\Security\ISecureRandom;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
|
@ -42,6 +45,8 @@ class Manager {
|
|||
private $config;
|
||||
/** @var ISecureRandom */
|
||||
private $secureRandom;
|
||||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
/** @var CommentsManager */
|
||||
private $commentsManager;
|
||||
/** @var EventDispatcherInterface */
|
||||
|
@ -50,21 +55,27 @@ class Manager {
|
|||
protected $timeFactory;
|
||||
/** @var IHasher */
|
||||
private $hasher;
|
||||
/** @var IL10N */
|
||||
private $l;
|
||||
|
||||
public function __construct(IDBConnection $db,
|
||||
IConfig $config,
|
||||
ISecureRandom $secureRandom,
|
||||
IUserManager $userManager,
|
||||
CommentsManager $commentsManager,
|
||||
EventDispatcherInterface $dispatcher,
|
||||
ITimeFactory $timeFactory,
|
||||
IHasher $hasher) {
|
||||
IHasher $hasher,
|
||||
IL10N $l) {
|
||||
$this->db = $db;
|
||||
$this->config = $config;
|
||||
$this->secureRandom = $secureRandom;
|
||||
$this->userManager = $userManager;
|
||||
$this->commentsManager = $commentsManager;
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->timeFactory = $timeFactory;
|
||||
$this->hasher = $hasher;
|
||||
$this->l = $l;
|
||||
}
|
||||
|
||||
public function forAllRooms(callable $callback): void {
|
||||
|
@ -516,6 +527,57 @@ class Manager {
|
|||
return $sessionIds;
|
||||
}
|
||||
|
||||
public function resolveRoomDisplayName(Room $room, string $userId): string {
|
||||
if ($room->getObjectType() === 'share:password') {
|
||||
return $this->l->t('Password request: %s', [$room->getName()]);
|
||||
}
|
||||
|
||||
if ($room->getName() === '') {
|
||||
$room->setName($this->getRoomNameByParticipants($room));
|
||||
}
|
||||
|
||||
// Set the room name to the other participant for one-to-one rooms
|
||||
if ($userId !== '' && $room->getType() === Room::ONE_TO_ONE_CALL) {
|
||||
$users = $room->getParticipantUserIds();
|
||||
$otherParticipant = '';
|
||||
$userIsParticipant = false;
|
||||
|
||||
foreach ($users as $participantId) {
|
||||
if ($participantId !== $userId) {
|
||||
$user = $this->userManager->get($participantId);
|
||||
$otherParticipant = $user instanceof IUser ? $user->getDisplayName() : $participantId;
|
||||
} else {
|
||||
$userIsParticipant = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$userIsParticipant) {
|
||||
// Do not leak the name of rooms the user is not a part of
|
||||
return $this->l->t('Private conversation');
|
||||
}
|
||||
|
||||
return $otherParticipant;
|
||||
}
|
||||
|
||||
return $room->getName();
|
||||
}
|
||||
|
||||
protected function getRoomNameByParticipants(Room $room): string {
|
||||
$users = $room->getParticipantUserIds();
|
||||
$displayNames = [];
|
||||
|
||||
foreach ($users as $participantId) {
|
||||
$user = $this->userManager->get($participantId);
|
||||
$displayNames[] = $user instanceof IUser ? $user->getDisplayName() : $participantId;
|
||||
}
|
||||
|
||||
$roomName = implode(', ', $displayNames);
|
||||
if (strlen($roomName) > 128) {
|
||||
$roomName = substr($roomName, 120) . '…';
|
||||
}
|
||||
return $roomName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
|
|
@ -176,7 +176,7 @@ class Notifier implements INotifier {
|
|||
$richSubjectCall = [
|
||||
'type' => 'call',
|
||||
'id' => $room->getId(),
|
||||
'name' => $room->getName() !== '' ? $room->getName() : $l->t('a conversation'),
|
||||
'name' => $room->getDisplayName($notification->getUser()),
|
||||
'call-type' => $this->getRoomType($room),
|
||||
];
|
||||
|
||||
|
@ -221,42 +221,22 @@ class Notifier implements INotifier {
|
|||
$subject = $l->t('{user} sent you a private message');
|
||||
} else {
|
||||
if ($richSubjectUser) {
|
||||
if ($room->getName() !== '') {
|
||||
$subject = $l->t('{user} sent a message in conversation {call}');
|
||||
} else {
|
||||
$subject = $l->t('{user} sent a message in a conversation');
|
||||
}
|
||||
$subject = $l->t('{user} sent a message in conversation {call}');
|
||||
} else if (!$isGuest) {
|
||||
if ($room->getName() !== '') {
|
||||
$subject = $l->t('A deleted user sent a message in conversation {call}');
|
||||
} else {
|
||||
$subject = $l->t('A deleted user sent a message in a conversation');
|
||||
}
|
||||
} else if ($room->getName() !== '') {
|
||||
$subject = $l->t('A guest sent a message in conversation {call}');
|
||||
$subject = $l->t('A deleted user sent a message in conversation {call}');
|
||||
} else {
|
||||
$subject = $l->t('A guest sent a message in a conversation');
|
||||
$subject = $l->t('A guest sent a message in conversation {call}');
|
||||
}
|
||||
}
|
||||
} else if ($room->getType() === Room::ONE_TO_ONE_CALL) {
|
||||
$subject = $l->t('{user} mentioned you in a private conversation');
|
||||
} else {
|
||||
if ($richSubjectUser) {
|
||||
if ($room->getName() !== '') {
|
||||
$subject = $l->t('{user} mentioned you in conversation {call}');
|
||||
} else {
|
||||
$subject = $l->t('{user} mentioned you in a conversation');
|
||||
}
|
||||
$subject = $l->t('{user} mentioned you in conversation {call}');
|
||||
} else if (!$isGuest) {
|
||||
if ($room->getName() !== '') {
|
||||
$subject = $l->t('A deleted user mentioned you in conversation {call}');
|
||||
} else {
|
||||
$subject = $l->t('A deleted user mentioned you in a conversation');
|
||||
}
|
||||
} else if ($room->getName() !== '') {
|
||||
$subject = $l->t('A guest mentioned you in conversation {call}');
|
||||
$subject = $l->t('A deleted user mentioned you in conversation {call}');
|
||||
} else {
|
||||
$subject = $l->t('A guest mentioned you in a conversation');
|
||||
$subject = $l->t('A guest mentioned you in conversation {call}');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -314,6 +294,7 @@ class Notifier implements INotifier {
|
|||
throw new \InvalidArgumentException('Calling user does not exist anymore');
|
||||
}
|
||||
|
||||
$roomName = $room->getDisplayName($notification->getUser());
|
||||
if ($room->getType() === Room::ONE_TO_ONE_CALL) {
|
||||
$notification
|
||||
->setParsedSubject(
|
||||
|
@ -329,54 +310,32 @@ class Notifier implements INotifier {
|
|||
'call' => [
|
||||
'type' => 'call',
|
||||
'id' => $room->getId(),
|
||||
'name' => $l->t('a conversation'),
|
||||
'name' => $roomName,
|
||||
'call-type' => $this->getRoomType($room),
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
} else if (\in_array($room->getType(), [Room::GROUP_CALL, Room::PUBLIC_CALL], true)) {
|
||||
if ($room->getName() !== '') {
|
||||
$notification
|
||||
->setParsedSubject(
|
||||
$l->t('%s invited you to a group conversation: %s', [$user->getDisplayName(), $room->getName()])
|
||||
)
|
||||
->setRichSubject(
|
||||
$l->t('{user} invited you to a group conversation: {call}'), [
|
||||
'user' => [
|
||||
'type' => 'user',
|
||||
'id' => $uid,
|
||||
'name' => $user->getDisplayName(),
|
||||
],
|
||||
'call' => [
|
||||
'type' => 'call',
|
||||
'id' => $room->getId(),
|
||||
'name' => $room->getName(),
|
||||
'call-type' => $this->getRoomType($room),
|
||||
],
|
||||
]
|
||||
);
|
||||
} else {
|
||||
$notification
|
||||
->setParsedSubject(
|
||||
$l->t('%s invited you to a group conversation', [$user->getDisplayName()])
|
||||
)
|
||||
->setRichSubject(
|
||||
$l->t('{user} invited you to a group conversation'), [
|
||||
'user' => [
|
||||
'type' => 'user',
|
||||
'id' => $uid,
|
||||
'name' => $user->getDisplayName(),
|
||||
],
|
||||
'call' => [
|
||||
'type' => 'call',
|
||||
'id' => $room->getId(),
|
||||
'name' => $l->t('a conversation'),
|
||||
'call-type' => $this->getRoomType($room),
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
$notification
|
||||
->setParsedSubject(
|
||||
$l->t('%s invited you to a group conversation: %s', [$user->getDisplayName(), $roomName])
|
||||
)
|
||||
->setRichSubject(
|
||||
$l->t('{user} invited you to a group conversation: {call}'), [
|
||||
'user' => [
|
||||
'type' => 'user',
|
||||
'id' => $uid,
|
||||
'name' => $user->getDisplayName(),
|
||||
],
|
||||
'call' => [
|
||||
'type' => 'call',
|
||||
'id' => $room->getId(),
|
||||
'name' => $roomName,
|
||||
'call-type' => $this->getRoomType($room),
|
||||
],
|
||||
]
|
||||
);
|
||||
} else {
|
||||
throw new \InvalidArgumentException('Unknown room type');
|
||||
}
|
||||
|
@ -396,6 +355,7 @@ class Notifier implements INotifier {
|
|||
throw new \InvalidArgumentException('Unknown object type');
|
||||
}
|
||||
|
||||
$roomName = $room->getDisplayName($notification->getUser());
|
||||
if ($room->getType() === Room::ONE_TO_ONE_CALL) {
|
||||
$parameters = $notification->getSubjectParameters();
|
||||
$calleeId = $parameters['callee'];
|
||||
|
@ -415,7 +375,7 @@ class Notifier implements INotifier {
|
|||
'call' => [
|
||||
'type' => 'call',
|
||||
'id' => $room->getId(),
|
||||
'name' => $l->t('a conversation'),
|
||||
'name' => $roomName,
|
||||
'call-type' => $this->getRoomType($room),
|
||||
],
|
||||
]
|
||||
|
@ -425,33 +385,20 @@ class Notifier implements INotifier {
|
|||
}
|
||||
|
||||
} else if (\in_array($room->getType(), [Room::GROUP_CALL, Room::PUBLIC_CALL], true)) {
|
||||
if ($room->getName() !== '') {
|
||||
$notification
|
||||
->setParsedSubject(
|
||||
str_replace('{call}', $room->getName(), $l->t('A group call has started in {call}'))
|
||||
)
|
||||
->setRichSubject(
|
||||
$l->t('A group call has started in {call}'), [
|
||||
'call' => [
|
||||
'type' => 'call',
|
||||
'id' => $room->getId(),
|
||||
'name' => $room->getName(),
|
||||
'call-type' => $this->getRoomType($room),
|
||||
],
|
||||
]
|
||||
);
|
||||
} else {
|
||||
$notification
|
||||
->setParsedSubject($l->t('A group call has started'))
|
||||
->setRichSubject($l->t('A group call has started'), [
|
||||
$notification
|
||||
->setParsedSubject(
|
||||
str_replace('{call}', $roomName, $l->t('A group call has started in {call}'))
|
||||
)
|
||||
->setRichSubject(
|
||||
$l->t('A group call has started in {call}'), [
|
||||
'call' => [
|
||||
'type' => 'call',
|
||||
'id' => $room->getId(),
|
||||
'name' => $l->t('a conversation'),
|
||||
'name' => $roomName,
|
||||
'call-type' => $this->getRoomType($room),
|
||||
],
|
||||
]);
|
||||
}
|
||||
]
|
||||
);
|
||||
|
||||
} else {
|
||||
throw new \InvalidArgumentException('Unknown room type');
|
||||
|
|
|
@ -138,6 +138,10 @@ class Room {
|
|||
return $this->name;
|
||||
}
|
||||
|
||||
public function getDisplayName(string $userId): string {
|
||||
return $this->manager->resolveRoomDisplayName($this, $userId);
|
||||
}
|
||||
|
||||
public function getActiveGuests(): int {
|
||||
return $this->activeGuests;
|
||||
}
|
||||
|
@ -272,8 +276,6 @@ class Room {
|
|||
return false;
|
||||
}
|
||||
|
||||
$oldName = $this->getName();
|
||||
|
||||
$this->dispatcher->dispatch(self::class . '::preSetName', new GenericEvent($this, [
|
||||
'newName' => $newName,
|
||||
'oldName' => $oldName,
|
||||
|
|
|
@ -41,20 +41,14 @@ class DeletedShareAPIController {
|
|||
|
||||
/** @var string */
|
||||
private $userId;
|
||||
|
||||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
|
||||
/** @var Manager */
|
||||
private $manager;
|
||||
|
||||
public function __construct(
|
||||
string $UserId,
|
||||
IUserManager $userManager,
|
||||
Manager $manager
|
||||
) {
|
||||
$this->userId = $UserId;
|
||||
$this->userManager = $userManager;
|
||||
$this->manager = $manager;
|
||||
}
|
||||
|
||||
|
@ -76,22 +70,7 @@ class DeletedShareAPIController {
|
|||
return $result;
|
||||
}
|
||||
|
||||
// The display name of one-to-one rooms is set to the display name of
|
||||
// the other participant.
|
||||
$roomName = $room->getName();
|
||||
if ($room->getType() === Room::ONE_TO_ONE_CALL) {
|
||||
$userIds = $room->getParticipantUserIds();
|
||||
foreach ($userIds as $userId) {
|
||||
if ($this->userId !== $userId) {
|
||||
$user = $this->userManager->get($userId);
|
||||
if ($user instanceof IUser) {
|
||||
$roomName = $user->getDisplayName();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result['share_with_displayname'] = $roomName;
|
||||
$result['share_with_displayname'] = $room->getDisplayName($this->userId);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
|
|
@ -84,32 +84,7 @@ class ShareAPIController {
|
|||
return $result;
|
||||
}
|
||||
|
||||
$roomName = $room->getName();
|
||||
try {
|
||||
$room->getParticipant($this->userId);
|
||||
|
||||
if ($room->getType() === Room::ONE_TO_ONE_CALL) {
|
||||
$userIds = $room->getParticipantUserIds();
|
||||
foreach ($userIds as $userId) {
|
||||
if ($this->userId === $userId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$user = $this->userManager->get($userId);
|
||||
if ($user instanceof IUser) {
|
||||
$roomName = $user->getDisplayName();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if ($roomName === '') {
|
||||
$roomName = $this->l->t('Unnamed conversation');
|
||||
}
|
||||
} catch (ParticipantNotFoundException $e) {
|
||||
// Do not leak the name of rooms the user is not a part of
|
||||
$roomName = $this->l->t('Private conversation');
|
||||
}
|
||||
|
||||
$result['share_with_displayname'] = $roomName;
|
||||
$result['share_with_displayname'] = $room->getDisplayName($this->userId);
|
||||
if ($room->getType() === Room::PUBLIC_CALL) {
|
||||
$result['token'] = $share->getToken();
|
||||
}
|
||||
|
|
|
@ -132,7 +132,7 @@ class BackendNotifier {
|
|||
// find a better way to notify existing users to update the room.
|
||||
'alluserids' => $room->getParticipantUserIds(),
|
||||
'properties' => [
|
||||
'name' => $room->getName(),
|
||||
'name' => $room->getDisplayName(''),
|
||||
'type' => $room->getType(),
|
||||
],
|
||||
],
|
||||
|
@ -156,7 +156,7 @@ class BackendNotifier {
|
|||
// find a better way to notify existing users to update the room.
|
||||
'alluserids' => $room->getParticipantUserIds(),
|
||||
'properties' => [
|
||||
'name' => $room->getName(),
|
||||
'name' => $room->getDisplayName(''),
|
||||
'type' => $room->getType(),
|
||||
],
|
||||
],
|
||||
|
@ -180,7 +180,7 @@ class BackendNotifier {
|
|||
// find a better way to notify existing users to update the room.
|
||||
'alluserids' => $room->getParticipantUserIds(),
|
||||
'properties' => [
|
||||
'name' => $room->getName(),
|
||||
'name' => $room->getDisplayName(''),
|
||||
'type' => $room->getType(),
|
||||
],
|
||||
],
|
||||
|
@ -200,7 +200,7 @@ class BackendNotifier {
|
|||
'update' => [
|
||||
'userids' => $room->getParticipantUserIds(),
|
||||
'properties' => [
|
||||
'name' => $room->getName(),
|
||||
'name' => $room->getDisplayName(''),
|
||||
'type' => $room->getType(),
|
||||
],
|
||||
],
|
||||
|
|
|
@ -185,7 +185,7 @@ class BackendNotifierTest extends \Test\TestCase {
|
|||
$this->userId,
|
||||
],
|
||||
'properties' => [
|
||||
'name' => $room->getName(),
|
||||
'name' => $room->getDisplayName(''),
|
||||
'type' => $room->getType(),
|
||||
],
|
||||
],
|
||||
|
@ -218,7 +218,7 @@ class BackendNotifierTest extends \Test\TestCase {
|
|||
'alluserids' => [
|
||||
],
|
||||
'properties' => [
|
||||
'name' => $room->getName(),
|
||||
'name' => $room->getDisplayName(''),
|
||||
'type' => $room->getType(),
|
||||
],
|
||||
],
|
||||
|
@ -239,7 +239,7 @@ class BackendNotifierTest extends \Test\TestCase {
|
|||
'userids' => [
|
||||
],
|
||||
'properties' => [
|
||||
'name' => $room->getName(),
|
||||
'name' => $room->getDisplayName(''),
|
||||
'type' => $room->getType(),
|
||||
],
|
||||
],
|
||||
|
|
Загрузка…
Ссылка в новой задаче