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
+191
View File
@@ -0,0 +1,191 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Talk\Activity;
use OCA\Talk\Chat\ChatManager;
use OCA\Talk\Events\ACallEndedEvent;
use OCA\Talk\Events\ARoomEvent;
use OCA\Talk\Events\AttendeesAddedEvent;
use OCA\Talk\Events\CallEndedEvent;
use OCA\Talk\Events\CallEndedForEveryoneEvent;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCA\Talk\Service\ParticipantService;
use OCA\Talk\Service\RecordingService;
use OCA\Talk\Service\RoomService;
use OCP\Activity\Exceptions\InvalidValueException;
use OCP\Activity\IManager;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\IUser;
use OCP\IUserSession;
use Psr\Log\LoggerInterface;
/**
* @template-implements IEventListener<Event>
*/
class Listener implements IEventListener {
public function __construct(
protected IManager $activityManager,
protected IUserSession $userSession,
protected ChatManager $chatManager,
protected ParticipantService $participantService,
protected RoomService $roomService,
protected RecordingService $recordingService,
protected LoggerInterface $logger,
protected ITimeFactory $timeFactory,
protected Setting $setting,
) {
}
#[\Override]
public function handle(Event $event): void {
if ($event instanceof ARoomEvent && $event->getRoom()->isFederatedConversation()) {
return;
}
match (get_class($event)) {
CallEndedEvent::class,
CallEndedForEveryoneEvent::class => $this->generateCallActivity($event),
AttendeesAddedEvent::class => $this->generateInvitationActivity($event->getRoom(), $event->getAttendees()),
};
}
/**
* Call activity: "You attended a call with {user1} and {user2}"
*/
protected function generateCallActivity(ACallEndedEvent $event): void {
$room = $event->getRoom();
$actor = $event->getActor();
$activeSince = $event->getOldValue();
$duration = $this->timeFactory->getTime() - $activeSince->getTimestamp();
$userIds = $this->participantService->getParticipantUserIds($room, $activeSince);
$cloudIds = $this->participantService->getParticipantActorIdsByActorType($room, [Attendee::ACTOR_FEDERATED_USERS], $activeSince);
$numGuests = $this->participantService->getActorsCountByType($room, Attendee::ACTOR_GUESTS, $activeSince->getTimestamp());
$numGuests += $this->participantService->getActorsCountByType($room, Attendee::ACTOR_EMAILS, $activeSince->getTimestamp());
$message = 'call_ended';
if (($room->getType() === Room::TYPE_ONE_TO_ONE || $room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) && \count($userIds) === 1) {
$message = 'call_missed';
} elseif ($event instanceof CallEndedForEveryoneEvent) {
$message = 'call_ended_everyone';
}
if ($actor instanceof Participant) {
$actorId = $actor->getAttendee()->getActorId();
$actorType = $actor->getAttendee()->getActorType();
} else {
$actorType = Attendee::ACTOR_GUESTS;
$actorId = Attendee::ACTOR_ID_SYSTEM;
}
$this->chatManager->addSystemMessage($room, $actor, $actorType, $actorId, json_encode([
'message' => $message,
'parameters' => [
'users' => $userIds,
'cloudIds' => $cloudIds,
'guests' => $numGuests,
'duration' => $duration,
],
]), $this->timeFactory->getDateTime(), false);
if (empty($userIds)) {
return;
}
$activity = $this->activityManager->generateEvent();
try {
$activity->setApp('spreed')
->setType('spreed')
->setAuthor('')
->setObject('room', $room->getId())
->setTimestamp($this->timeFactory->getTime())
->setSubject('call', [
'room' => $room->getId(),
'users' => $userIds,
'cloudIds' => $cloudIds,
'guests' => $numGuests,
'duration' => $duration,
]);
} catch (InvalidValueException $e) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
return;
}
$this->activityManager->bulkPublish($activity, $userIds, $this->setting);
}
/**
* Invitation activity: "{actor} invited you to {call}"
*
* @param Room $room
* @param Attendee[] $attendees
*/
protected function generateInvitationActivity(Room $room, array $attendees): void {
$actor = $this->userSession->getUser();
if (!$actor instanceof IUser) {
return;
}
$actorId = $actor->getUID();
$event = $this->activityManager->generateEvent();
try {
$event->setApp('spreed')
->setType('spreed')
->setAuthor($actorId)
->setObject('room', $room->getId())
->setTimestamp($this->timeFactory->getTime())
->setSubject('invitation', [
'user' => $actor->getUID(),
'room' => $room->getId(),
]);
} catch (\Throwable $e) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
return;
}
// We know the new participant is in the room,
// so skip loading them just to make sure they can read it.
// Must be overwritten later on for one-to-one chats.
$roomName = $room->getDisplayName($actorId);
foreach ($attendees as $attendee) {
if ($attendee->getActorType() !== Attendee::ACTOR_USERS) {
// No user => no activity
continue;
}
if ($actorId === $attendee->getActorId()) {
// No activity for self-joining and the creator
continue;
}
try {
if ($room->getType() === Room::TYPE_ONE_TO_ONE) {
// Overwrite the room name with the other participant
$roomName = $room->getDisplayName($attendee->getActorId());
}
$event
->setObject('room', $room->getId(), $roomName)
->setSubject('invitation', [
'user' => $actor->getUID(),
'room' => $room->getId(),
'name' => $roomName,
])
->setAffectedUser($attendee->getActorId());
$this->activityManager->publish($event);
} catch (\Throwable $e) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
}
}
}
}
+142
View File
@@ -0,0 +1,142 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Talk\Activity\Provider;
use OCA\Talk\Config;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\Manager;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Room;
use OCA\Talk\Service\AvatarService;
use OCA\Talk\Service\ParticipantService;
use OCP\Activity\Exceptions\UnknownActivityException;
use OCP\Activity\IEvent;
use OCP\Activity\IManager;
use OCP\Activity\IProvider;
use OCP\Federation\ICloudIdManager;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
use OCP\L10N\IFactory;
abstract class Base implements IProvider {
public function __construct(
protected IFactory $languageFactory,
protected IURLGenerator $url,
protected Config $config,
protected IManager $activityManager,
protected IUserManager $userManager,
protected ICloudIdManager $cloudIdManager,
protected ParticipantService $participantService,
protected AvatarService $avatarService,
protected Manager $manager,
) {
}
/**
* @param IEvent $event
* @return IEvent
* @throws UnknownActivityException
*/
public function preParse(IEvent $event): IEvent {
if ($event->getApp() !== 'spreed') {
throw new UnknownActivityException('app');
}
$uid = $event->getAffectedUser();
$user = $this->userManager->get($uid);
if (!$user instanceof IUser || $this->config->isDisabledForUser($user)) {
throw new UnknownActivityException('User can not use Talk');
}
if ($this->activityManager->getRequirePNG()) {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('spreed', 'app-dark.png')));
} else {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('spreed', 'app-dark.svg')));
}
return $event;
}
/**
* @param IEvent $event
* @param string $subject
* @param array $parameters
*/
protected function setSubjects(IEvent $event, string $subject, array $parameters): void {
$placeholders = $replacements = [];
foreach ($parameters as $placeholder => $parameter) {
$placeholders[] = '{' . $placeholder . '}';
$replacements[] = $parameter['name'];
}
$event->setParsedSubject(str_replace($placeholders, $replacements, $subject))
->setRichSubject($subject, $parameters);
}
protected function getRoom(Room $room, string $userId): array {
switch ($room->getType()) {
case Room::TYPE_ONE_TO_ONE:
case Room::TYPE_ONE_TO_ONE_FORMER:
$stringType = 'one2one';
break;
case Room::TYPE_GROUP:
$stringType = 'group';
break;
case Room::TYPE_PUBLIC:
default:
$stringType = 'public';
break;
}
return [
'type' => 'call',
'id' => (string)$room->getId(),
'name' => $room->getDisplayName($userId),
'link' => $this->url->linkToRouteAbsolute('spreed.Page.showCall', ['token' => $room->getToken()]),
'call-type' => $stringType,
'icon-url' => $this->avatarService->getAvatarUrl($room),
];
}
protected function getFormerRoom(IL10N $l): array {
return [
'type' => 'highlight',
'id' => 'deleted',
'name' => $l->t('a conversation'),
];
}
protected function getUser(string $uid): array {
return [
'type' => 'user',
'id' => $uid,
'name' => $this->userManager->getDisplayName($uid) ?? $uid,
];
}
protected function getRemoteUser(Room $room, string $federationId): array {
$cloudId = $this->cloudIdManager->resolveCloudId($federationId);
$displayName = $cloudId->getDisplayId();
try {
$participant = $this->participantService->getParticipantByActor($room, Attendee::ACTOR_FEDERATED_USERS, $federationId);
$displayName = $participant->getAttendee()->getDisplayName();
} catch (ParticipantNotFoundException) {
}
return [
'type' => 'user',
'id' => $cloudId->getUser(),
'name' => $displayName,
'server' => $cloudId->getRemote(),
];
}
}
+156
View File
@@ -0,0 +1,156 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Talk\Activity\Provider;
use OCA\Talk\Exceptions\RoomNotFoundException;
use OCA\Talk\Room;
use OCP\Activity\Exceptions\UnknownActivityException;
use OCP\Activity\IEvent;
use OCP\IL10N;
class Call extends Base {
/**
* @param string $language
* @param IEvent $event
* @param IEvent|null $previousEvent
* @return IEvent
* @throws UnknownActivityException
* @since 11.0.0
*/
#[\Override]
public function parse($language, IEvent $event, ?IEvent $previousEvent = null): IEvent {
$event = $this->preParse($event);
if ($event->getSubject() === 'call') {
$l = $this->languageFactory->get('spreed', $language);
$parameters = $event->getSubjectParameters();
try {
$room = $this->manager->getRoomForUser((int)$parameters['room'], $this->activityManager->getCurrentUserId());
} catch (RoomNotFoundException) {
$room = null;
}
$result = $this->parseCall($room, $event, $l);
$result['subject'] .= ' ' . $this->getDuration($l, (int)$parameters['duration']);
// $result['params']['call'] = $roomParameter;
$this->setSubjects($event, $result['subject'], $result['params']);
} else {
throw new UnknownActivityException('subject');
}
return $event;
}
protected function getDuration(IL10N $l, int $seconds): string {
$hours = floor($seconds / 3600);
$seconds %= 3600;
$minutes = floor($seconds / 60);
$seconds %= 60;
if ($hours > 0) {
$duration = sprintf('%1$d:%2$02d:%3$02d', $hours, $minutes, $seconds);
} else {
$duration = sprintf('%1$d:%2$02d', $minutes, $seconds);
}
return $l->t('(Duration %s)', $duration);
}
protected function parseCall(?Room $room, IEvent $event, IL10N $l): array {
$parameters = $event->getSubjectParameters();
$currentUser = array_search($this->activityManager->getCurrentUserId(), $parameters['users'], true);
if ($currentUser === false) {
throw new UnknownActivityException('Unknown case');
}
unset($parameters['users'][$currentUser]);
sort($parameters['users']);
if (!isset($parameters['cloudIds'])) {
// Compatibility with old messages
$parameters['cloudIds'] = [];
}
sort($parameters['users']);
sort($parameters['cloudIds']);
$numUsers = $numRealUsers = count($parameters['users']);
// Without room, we can not resolve cloudIds, so we list them as guests instead
if (!$room instanceof Room) {
$numUsers += count($parameters['cloudIds']);
} else {
$parameters['guests'] += count($parameters['cloudIds']);
}
$displayedUsers = $numUsers;
switch ($numUsers) {
case 0:
$subject = $l->t('You attended a call with {user1}');
$subject = str_replace('{user1}', $l->n('%n guest', '%n guests', $parameters['guests']), $subject);
break;
case 1:
if ($parameters['guests'] === 0) {
$subject = $l->t('You attended a call with {user1}');
} else {
$subject = $l->t('You attended a call with {user1} and {user2}');
$subject = str_replace('{user2}', $l->n('%n guest', '%n guests', $parameters['guests']), $subject);
}
break;
case 2:
if ($parameters['guests'] === 0) {
$subject = $l->t('You attended a call with {user1} and {user2}');
} else {
$subject = $l->t('You attended a call with {user1}, {user2} and {user3}');
$subject = str_replace('{user3}', $l->n('%n guest', '%n guests', $parameters['guests']), $subject);
}
break;
case 3:
if ($parameters['guests'] === 0) {
$subject = $l->t('You attended a call with {user1}, {user2} and {user3}');
} else {
$subject = $l->t('You attended a call with {user1}, {user2}, {user3} and {user4}');
$subject = str_replace('{user4}', $l->n('%n guest', '%n guests', $parameters['guests']), $subject);
}
break;
case 4:
if ($parameters['guests'] === 0) {
$subject = $l->t('You attended a call with {user1}, {user2}, {user3} and {user4}');
} else {
$subject = $l->t('You attended a call with {user1}, {user2}, {user3}, {user4} and {user5}');
$subject = str_replace('{user5}', $l->n('%n guest', '%n guests', $parameters['guests']), $subject);
}
break;
case 5:
default:
$subject = $l->t('You attended a call with {user1}, {user2}, {user3}, {user4} and {user5}');
if ($numUsers === 5 && $parameters['guests'] === 0) {
$displayedUsers = 5;
} else {
$displayedUsers = 4;
$numOthers = $parameters['guests'] + $numUsers - $displayedUsers;
$subject = str_replace('{user5}', $l->n('%n other', '%n others', $numOthers), $subject);
}
}
$params = [];
for ($i = 1; $i <= $displayedUsers; $i++) {
if ($i <= $numRealUsers) {
$params['user' . $i] = $this->getUser($parameters['users'][$i - 1]);
} else {
$params['user' . $i] = $this->getRemoteUser($room, $parameters['cloudIds'][$i - $numRealUsers - 1]);
}
}
return [
'subject' => $subject,
'params' => $params,
];
}
}
+49
View File
@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Talk\Activity\Provider;
use OCA\Talk\Exceptions\RoomNotFoundException;
use OCP\Activity\Exceptions\UnknownActivityException;
use OCP\Activity\IEvent;
class Invitation extends Base {
/**
* @param string $language
* @param IEvent $event
* @param IEvent|null $previousEvent
* @return IEvent
* @throws UnknownActivityException
* @since 11.0.0
*/
#[\Override]
public function parse($language, IEvent $event, ?IEvent $previousEvent = null): IEvent {
$event = $this->preParse($event);
if ($event->getSubject() === 'invitation') {
$l = $this->languageFactory->get('spreed', $language);
$parameters = $event->getSubjectParameters();
try {
$room = $this->manager->getRoomById((int)$parameters['room']);
$roomParameter = $this->getRoom($room, $event->getAffectedUser());
} catch (RoomNotFoundException) {
$roomParameter = $this->getFormerRoom($l);
}
$this->setSubjects($event, $l->t('{actor} invited you to {call}'), [
'actor' => $this->getUser($parameters['user']),
'call' => $roomParameter,
]);
} else {
throw new UnknownActivityException('subject');
}
return $event;
}
}
+76
View File
@@ -0,0 +1,76 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Talk\Activity;
use OCP\Activity\ActivitySettings;
use OCP\IL10N;
class Setting extends ActivitySettings {
public function __construct(
protected IL10N $l,
) {
}
/**
* @return string Lowercase a-z and underscore only identifier
* @since 11.0.0
*/
#[\Override]
public function getIdentifier(): string {
return 'spreed';
}
/**
* @return string A translated string
* @since 11.0.0
*/
#[\Override]
public function getName(): string {
return $this->l->t('You were invited to a <strong>conversation</strong> or had a <strong>call</strong>');
}
/**
* {@inheritdoc}
*/
#[\Override]
public function getGroupIdentifier(): string {
return 'other';
}
/**
* {@inheritdoc}
*/
#[\Override]
public function getGroupName(): string {
return $this->l->t('Other activities');
}
/**
* {@inheritdoc}
*/
#[\Override]
public function getPriority(): int {
return 51;
}
/**
* {@inheritdoc}
*/
#[\Override]
public function canChangeNotification(): bool {
return false;
}
/**
* {@inheritdoc}
*/
#[\Override]
public function isDefaultEnabledNotification(): bool {
return false;
}
}