UPSTREAM BASELINE: nextcloud/spreed v22.0.12 (без изменений)
Type checking / changes (push) Has been cancelled
Type checking / test (push) Has been cancelled
Type checking / typescript-summary (push) Has been cancelled
Node tests / changes (push) Has been cancelled
Node tests / test (push) Has been cancelled
Node tests / test-summary (push) Has been cancelled

Источник: https://github.com/nextcloud/spreed/archive/refs/tags/v22.0.12.tar.gz
С этого коммита ветка официального Nextcloud Talk отрезана (решение владельца 2026-07-06).
Все дальнейшие изменения — только наши; версии релизов: 22.0.12-f7.N.
This commit is contained in:
2026-07-06 14:07:50 +00:00
commit 01acfa3b40
1716 changed files with 613013 additions and 0 deletions
@@ -0,0 +1,188 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Talk\Collaboration\Collaborators;
use OCA\Talk\Config;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\Exceptions\RoomNotFoundException;
use OCA\Talk\Manager;
use OCA\Talk\MatterbridgeManager;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCA\Talk\Service\ParticipantService;
use OCA\Talk\TalkSession;
use OCP\Collaboration\AutoComplete\AutoCompleteFilterEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\IUser;
use OCP\IUserManager;
/**
* @template-implements IEventListener<Event>
*/
class Listener implements IEventListener {
/** @var string[] */
protected array $allowedGroupIds = [];
protected string $roomToken;
protected ?Room $room = null;
public function __construct(
protected Manager $manager,
protected IUserManager $userManager,
protected ParticipantService $participantService,
protected Config $config,
protected TalkSession $talkSession,
protected ?string $userId,
) {
}
#[\Override]
public function handle(Event $event): void {
if (!$event instanceof AutoCompleteFilterEvent) {
return;
}
if ($event->getItemType() !== 'call') {
return;
}
$event->setResults($this->filterUsersAndGroupsWithoutTalk($event->getResults()));
$event->setResults($this->filterBridgeBot($event->getResults()));
if ($event->getItemId() !== 'new') {
$event->setResults($this->filterExistingParticipants($event->getItemId(), $event->getResults()));
}
}
protected function filterUsersAndGroupsWithoutTalk(array $results): array {
$this->allowedGroupIds = $this->config->getAllowedTalkGroupIds();
if (empty($this->allowedGroupIds)) {
return $results;
}
if (!empty($results['groups'])) {
$results['groups'] = array_filter($results['groups'], [$this, 'filterBlockedGroupResult']);
}
if (!empty($results['exact']['groups'])) {
$results['exact']['groups'] = array_filter($results['exact']['groups'], [$this, 'filterBlockedGroupResult']);
}
if (!empty($results['users'])) {
$results['users'] = array_filter($results['users'], [$this, 'filterBlockedUserResult']);
}
if (!empty($results['exact']['users'])) {
$results['exact']['users'] = array_filter($results['exact']['users'], [$this, 'filterBlockedUserResult']);
}
return $results;
}
protected function filterBlockedUserResult(array $result): bool {
$user = $this->userManager->get($result['value']['shareWith']);
return $user instanceof IUser && !$this->config->isDisabledForUser($user);
}
protected function filterBlockedGroupResult(array $result): bool {
return \in_array($result['value']['shareWith'], $this->allowedGroupIds, true);
}
protected function filterBridgeBot(array $results): array {
if (!empty($results['users'])) {
$results['users'] = array_filter($results['users'], [$this, 'filterBridgeBotUserResult']);
}
if (!empty($results['exact']['users'])) {
$results['exact']['users'] = array_filter($results['exact']['users'], [$this, 'filterBridgeBotUserResult']);
}
return $results;
}
protected function filterExistingParticipants(string $token, array $results): array {
$sessionId = $this->talkSession->getSessionForRoom($token);
try {
$this->room = $this->manager->getRoomForUserByToken($token, $this->userId);
if ($this->userId !== null) {
$this->participantService->getParticipant($this->room, $this->userId, $sessionId);
} else {
$this->participantService->getParticipantBySession($this->room, $sessionId);
}
} catch (RoomNotFoundException|ParticipantNotFoundException) {
return $results;
}
if ($this->room->isFederatedConversation()) {
return $results;
}
if (!empty($results['groups'])) {
$results['groups'] = array_filter($results['groups'], [$this, 'filterParticipantGroupResult']);
}
if (!empty($results['exact']['groups'])) {
$results['exact']['groups'] = array_filter($results['exact']['groups'], [$this, 'filterParticipantGroupResult']);
}
if (!empty($results['users'])) {
$results['users'] = array_filter($results['users'], [$this, 'filterParticipantUserResult']);
}
if (!empty($results['exact']['users'])) {
$results['exact']['users'] = array_filter($results['exact']['users'], [$this, 'filterParticipantUserResult']);
}
if (!empty($results['circles'])) {
$results['circles'] = array_filter($results['circles'], [$this, 'filterParticipantTeamResult']);
}
if (!empty($results['exact']['circles'])) {
$results['exact']['circles'] = array_filter($results['exact']['circles'], [$this, 'filterParticipantTeamResult']);
}
return $results;
}
protected function filterBridgeBotUserResult(array $result): bool {
return $result['value']['shareWith'] !== MatterbridgeManager::BRIDGE_BOT_USERID;
}
protected function filterParticipantUserResult(array $result): bool {
$userId = $result['value']['shareWith'];
try {
$participant = $this->participantService->getParticipant($this->room, $userId, false);
if ($participant->getAttendee()->getParticipantType() === Participant::USER_SELF_JOINED) {
// do list self-joined users so they can be added as permanent participants by moderators
return true;
}
return false;
} catch (ParticipantNotFoundException $e) {
return true;
}
}
protected function filterParticipantGroupResult(array $result): bool {
$groupId = $result['value']['shareWith'];
try {
$this->participantService->getParticipantByActor($this->room, Attendee::ACTOR_GROUPS, $groupId);
return false;
} catch (ParticipantNotFoundException $e) {
return true;
}
}
protected function filterParticipantTeamResult(array $result): bool {
$circleId = $result['value']['shareWith'];
try {
$this->participantService->getParticipantByActor($this->room, Attendee::ACTOR_CIRCLES, $circleId);
return false;
} catch (ParticipantNotFoundException $e) {
return true;
}
}
}
@@ -0,0 +1,88 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Talk\Collaboration\Collaborators;
use OCA\Talk\Manager;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Room;
use OCA\Talk\Service\ParticipantService;
use OCP\Collaboration\Collaborators\ISearchPlugin;
use OCP\Collaboration\Collaborators\ISearchResult;
use OCP\Collaboration\Collaborators\SearchResultType;
use OCP\IUserSession;
use OCP\Share\IShare;
class RoomPlugin implements ISearchPlugin {
public function __construct(
protected Manager $manager,
protected ParticipantService $participantService,
protected IUserSession $userSession,
) {
}
/**
* {@inheritdoc}
*/
#[\Override]
public function search($search, $limit, $offset, ISearchResult $searchResult): bool {
if (!is_string($search) || $search === '') {
return false;
}
$search = mb_strtolower($search);
$userId = $this->userSession->getUser()->getUID();
$result = ['wide' => [], 'exact' => []];
$rooms = $this->manager->getRoomsForUser($userId);
foreach ($rooms as $room) {
if ($room->getReadOnly() === Room::READ_ONLY) {
// Can not add new shares to read-only rooms
continue;
}
if ($room->isFederatedConversation()) {
continue;
}
$participant = $this->participantService->getParticipant($room, $userId, false);
if (!($participant->getPermissions() & Attendee::PERMISSIONS_CHAT)) {
// No chat permissions is like read-only
continue;
}
if (mb_stripos($room->getDisplayName($userId), $search) !== false) {
$item = $this->roomToSearchResultItem($room, $userId);
if (mb_strtolower($item['label']) === mb_strtolower($search)) {
$result['exact'][] = $item;
} else {
$result['wide'][] = $item;
}
}
}
$type = new SearchResultType('rooms');
$searchResult->addResultSet($type, $result['wide'], $result['exact']);
return false;
}
private function roomToSearchResultItem(Room $room, string $userId): array {
return
[
'label' => $room->getDisplayName($userId),
'value' => [
'shareType' => IShare::TYPE_ROOM,
'shareWith' => $room->getToken()
]
];
}
}
@@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Talk\Collaboration\Reference;
use OCA\Talk\Events\AttendeesAddedEvent;
use OCA\Talk\Events\AttendeesRemovedEvent;
use OCA\Talk\Events\LobbyModifiedEvent;
use OCA\Talk\Events\RoomDeletedEvent;
use OCA\Talk\Events\RoomModifiedEvent;
use OCP\Collaboration\Reference\IReferenceManager;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
/**
* @template-implements IEventListener<Event>
*/
class ReferenceInvalidationListener implements IEventListener {
public function __construct(
protected IReferenceManager $referenceManager,
) {
}
#[\Override]
public function handle(Event $event): void {
if ($event instanceof AttendeesAddedEvent
|| $event instanceof AttendeesRemovedEvent
|| $event instanceof LobbyModifiedEvent
|| $event instanceof RoomDeletedEvent
|| $event instanceof RoomModifiedEvent) {
$this->referenceManager->invalidateCache($event->getRoom()->getToken());
}
}
}
@@ -0,0 +1,321 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Talk\Collaboration\Reference;
use OCA\Talk\AppInfo\Application;
use OCA\Talk\Chat\ChatManager;
use OCA\Talk\Chat\MessageParser;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\Exceptions\RoomNotFoundException;
use OCA\Talk\Manager;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Model\ProxyCacheMessageMapper;
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCA\Talk\Service\AvatarService;
use OCA\Talk\Service\ParticipantService;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\Collaboration\Reference\ADiscoverableReferenceProvider;
use OCP\Collaboration\Reference\IReference;
use OCP\Collaboration\Reference\ISearchableReferenceProvider;
use OCP\Collaboration\Reference\Reference;
use OCP\Comments\NotFoundException;
use OCP\IL10N;
use OCP\IURLGenerator;
/**
* @psalm-type ReferenceMatch = array{token: string, message: int|null}
*/
class TalkReferenceProvider extends ADiscoverableReferenceProvider implements ISearchableReferenceProvider {
public function __construct(
protected IURLGenerator $urlGenerator,
protected Manager $roomManager,
protected ParticipantService $participantService,
protected ChatManager $chatManager,
protected ProxyCacheMessageMapper $proxyCacheMessageMapper,
protected AvatarService $avatarService,
protected MessageParser $messageParser,
protected IL10N $l,
protected ?string $userId,
) {
}
#[\Override]
public function matchReference(string $referenceText): bool {
return $this->getTalkAppLinkToken($referenceText) !== null;
}
/**
* @param string $referenceText
* @return array|null
* @psalm-return ReferenceMatch|null
*/
protected function getTalkAppLinkToken(string $referenceText): ?array {
$indexPhpUrl = $this->urlGenerator->getAbsoluteURL('/index.php/call/');
$rewriteUrl = $this->urlGenerator->getAbsoluteURL('/call/');
if (str_starts_with($referenceText, $indexPhpUrl)) {
$urlOfInterest = substr($referenceText, strlen($indexPhpUrl));
} elseif (str_starts_with($referenceText, $rewriteUrl)) {
$urlOfInterest = substr($referenceText, strlen($rewriteUrl));
} else {
return null;
}
$hashPosition = strpos($urlOfInterest, '#');
$queryPosition = strpos($urlOfInterest, '?');
if ($hashPosition === false && $queryPosition === false) {
return [
'token' => $urlOfInterest,
'message' => null,
];
}
if ($hashPosition !== false && $queryPosition !== false) {
$cutPosition = min($hashPosition, $queryPosition);
} elseif ($hashPosition !== false) {
$cutPosition = $hashPosition;
} else {
$cutPosition = $queryPosition;
}
$token = substr($urlOfInterest, 0, $cutPosition);
$messageId = null;
if ($hashPosition !== false) {
$afterHash = substr($urlOfInterest, $hashPosition + 1);
if (preg_match('/^message_(\d+)$/', $afterHash, $matches)) {
$messageId = (int)$matches[1];
}
}
return [
'token' => $token,
'message' => $messageId,
];
}
/**
* @inheritDoc
*/
#[\Override]
public function resolveReference(string $referenceText): ?IReference {
if ($this->matchReference($referenceText)) {
$reference = new Reference($referenceText);
try {
$this->fetchReference($reference);
} catch (RoomNotFoundException|ParticipantNotFoundException $e) {
$reference->setRichObject('call', null);
$reference->setAccessible(false);
}
return $reference;
}
return null;
}
/**
* @throws RoomNotFoundException
*/
protected function fetchReference(Reference $reference): void {
if ($this->userId === null) {
throw new RoomNotFoundException();
}
$referenceMatch = $this->getTalkAppLinkToken($reference->getId());
if ($referenceMatch === null) {
throw new RoomNotFoundException();
}
$room = $this->roomManager->getRoomForUserByToken($referenceMatch['token'], $this->userId);
try {
$participant = $this->participantService->getParticipant($room, $this->userId);
} catch (ParticipantNotFoundException $e) {
$participant = null;
}
/**
* Default handling:
* Title is the conversation name
* Description the conversation description
*/
$roomName = $room->getDisplayName($this->userId);
$title = $roomName;
$description = '';
$messageId = null;
if ($participant instanceof Participant
|| $this->roomManager->isRoomListableByUser($room, $this->userId)) {
$description = $room->getDescription();
}
/**
* If linking to a comment and the user is already a participant
* Title is "Message of {user} in {conversation}"
* Description is the plain text chat message
*/
if ($participant && !empty($referenceMatch['message'])) {
$messageId = (string)$referenceMatch['message'];
if (!$room->isFederatedConversation()) {
try {
$comment = $this->chatManager->getComment($room, $messageId);
} catch (NotFoundException) {
throw new RoomNotFoundException();
}
$message = $this->messageParser->createMessage($room, $participant, $comment, $this->l);
$this->messageParser->parseMessage($message, true);
} else {
try {
$proxy = $this->proxyCacheMessageMapper->findById($room, (int)$messageId);
if ($proxy->getLocalToken() !== $room->getToken()) {
throw new RoomNotFoundException();
}
} catch (DoesNotExistException) {
throw new RoomNotFoundException();
}
$message = $this->messageParser->createMessageFromProxyCache($room, $participant, $proxy, $this->l);
}
$placeholders = $replacements = [];
foreach ($message->getMessageParameters() as $placeholder => $parameter) {
$placeholders[] = '{' . $placeholder . '}';
if ($parameter['type'] === 'user' || $parameter['type'] === 'guest') {
$replacements[] = '@' . $parameter['name'];
} else {
$replacements[] = $parameter['name'];
}
}
$description = str_replace($placeholders, $replacements, $message->getMessage());
$titleLine = $this->l->t('Message of {user} in {conversation}');
if ($room->getType() === Room::TYPE_ONE_TO_ONE || $room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) {
$titleLine = $this->l->t('Message of {user}');
}
$displayName = $message->getActorDisplayName();
if (in_array($message->getActorType(), [Attendee::ACTOR_GUESTS, Attendee::ACTOR_EMAILS], true)) {
if ($displayName === '') {
$displayName = $this->l->t('Guest');
} else {
$displayName = $this->l->t('%s (guest)', $displayName);
}
} elseif ($displayName === '') {
$titleLine = $this->l->t('Message of a deleted user in {conversation}');
}
$title = str_replace(
['{user}', '{conversation}'],
[$displayName, $title],
$titleLine
);
}
$reference->setTitle($title);
$reference->setDescription($description);
$reference->setUrl($this->urlGenerator->linkToRouteAbsolute('spreed.Page.showCall', ['token' => $room->getToken()]));
$reference->setImageUrl($this->avatarService->getAvatarUrl($room));
$referenceData = [
'id' => $room->getToken(),
'name' => $roomName,
'link' => $reference->getUrl(),
'call-type' => $this->getRoomType($room),
];
if ($messageId) {
$referenceData['message-id'] = $messageId;
}
$reference->setRichObject('call', $referenceData);
}
/**
* @inheritDoc
*/
#[\Override]
public function getCachePrefix(string $referenceId): string {
$referenceMatch = $this->getTalkAppLinkToken($referenceId);
if ($referenceMatch === null) {
return '';
}
return $referenceMatch['token'];
}
/**
* @inheritDoc
*/
#[\Override]
public function getCacheKey(string $referenceId): ?string {
$referenceMatch = $this->getTalkAppLinkToken($referenceId);
if ($referenceMatch === null) {
return '';
}
return ($this->userId ?? '') . '#' . ($referenceMatch['message'] ?? 0);
}
protected function getRoomType(Room $room): string {
switch ($room->getType()) {
case Room::TYPE_ONE_TO_ONE:
case Room::TYPE_ONE_TO_ONE_FORMER:
return 'one2one';
case Room::TYPE_GROUP:
return 'group';
case Room::TYPE_PUBLIC:
return 'public';
default:
return 'unknown';
}
}
/**
* @inheritDoc
*/
#[\Override]
public function getId(): string {
return Application::APP_ID;
}
/**
* @inheritDoc
*/
#[\Override]
public function getTitle(): string {
return $this->l->t('Talk conversations');
}
/**
* @inheritDoc
*/
#[\Override]
public function getOrder(): int {
return 0;
}
/**
* @inheritDoc
*/
#[\Override]
public function getIconUrl(): string {
return $this->urlGenerator->imagePath(Application::APP_ID, 'app-dark.svg');
}
#[\Override]
public function getSupportedSearchProviderIds(): array {
if ($this->userId === null) {
return [];
}
return ['talk-conversations'];
}
}
@@ -0,0 +1,111 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Talk\Collaboration\Resources;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\Exceptions\RoomNotFoundException;
use OCA\Talk\Manager;
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCA\Talk\Service\AvatarService;
use OCA\Talk\Service\ParticipantService;
use OCP\Collaboration\Resources\IProvider;
use OCP\Collaboration\Resources\IResource;
use OCP\Collaboration\Resources\ResourceException;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserSession;
class ConversationProvider implements IProvider {
public function __construct(
protected Manager $manager,
protected AvatarService $avatarService,
protected ParticipantService $participantService,
protected IUserSession $userSession,
protected IURLGenerator $urlGenerator,
) {
}
#[\Override]
public function getResourceRichObject(IResource $resource): array {
try {
$user = $this->userSession->getUser();
$userId = $user instanceof IUser ? $user->getUID() : '';
$room = $this->manager->getRoomByToken($resource->getId(), $userId);
$iconURL = $this->avatarService->getAvatarUrl($room);
/**
* Disabled for now, because it would show a square avatar
* if ($room->getType() === Room::TYPE_ONE_TO_ONE) {
* $iconURL = $this->urlGenerator->linkToRouteAbsolute('core.avatar.getAvatar', ['userId' => 'admin', 'size' => 32]);
* }
*/
return [
'type' => 'room',
'id' => $resource->getId(),
'name' => $room->getDisplayName($userId),
'call-type' => $this->getRoomType($room),
'iconUrl' => $iconURL,
'link' => $this->urlGenerator->linkToRouteAbsolute('spreed.Page.showCall', ['token' => $room->getToken()])
];
} catch (RoomNotFoundException $e) {
throw new ResourceException('Conversation not found');
}
}
#[\Override]
public function canAccessResource(IResource $resource, ?IUser $user = null): bool {
$userId = $user instanceof IUser ? $user->getUID() : null;
if ($userId === null) {
throw new ResourceException('Guests are not supported at the moment');
}
try {
$room = $this->manager->getRoomForUserByToken(
$resource->getId(),
$userId
);
// Logged in users need to have a regular participant,
// before they can do anything with the room.
$participant = $this->participantService->getParticipant($room, $userId, false);
return $participant->getAttendee()->getParticipantType() !== Participant::USER_SELF_JOINED;
} catch (RoomNotFoundException $e) {
throw new ResourceException('Conversation not found');
} catch (ParticipantNotFoundException $e) {
throw new ResourceException('Participant not found');
}
}
#[\Override]
public function getType(): string {
return 'room';
}
/**
* @param Room $room
* @return string
* @throws \InvalidArgumentException
*/
protected function getRoomType(Room $room): string {
switch ($room->getType()) {
case Room::TYPE_ONE_TO_ONE:
case Room::TYPE_ONE_TO_ONE_FORMER:
return 'one2one';
case Room::TYPE_GROUP:
return 'group';
case Room::TYPE_PUBLIC:
return 'public';
default:
throw new \InvalidArgumentException('Unknown room type');
}
}
}
+47
View File
@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Talk\Collaboration\Resources;
use OCA\Talk\Events\ARoomModifiedEvent;
use OCA\Talk\Events\AttendeesAddedEvent;
use OCA\Talk\Events\AttendeesRemovedEvent;
use OCA\Talk\Events\EmailInvitationSentEvent;
use OCA\Talk\Events\RoomDeletedEvent;
use OCA\Talk\Events\RoomModifiedEvent;
use OCP\Collaboration\Resources\IManager;
use OCP\Collaboration\Resources\ResourceException;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
/**
* @template-implements IEventListener<Event>
*/
class Listener implements IEventListener {
public function __construct(
protected IManager $resourceManager,
) {
}
#[\Override]
public function handle(Event $event): void {
if ($event instanceof AttendeesAddedEvent
|| $event instanceof AttendeesRemovedEvent
|| $event instanceof RoomDeletedEvent
|| $event instanceof EmailInvitationSentEvent
|| ($event instanceof RoomModifiedEvent
&& $event->getProperty() === ARoomModifiedEvent::PROPERTY_TYPE)) {
try {
$resource = $this->resourceManager->getResourceForUser('room', $event->getRoom()->getToken(), null);
} catch (ResourceException) {
return;
}
$this->resourceManager->invalidateAccessCacheForResource($resource);
}
}
}