From cf72ae74df6ef1ae5e424a404546dea783e49e53 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 25 Jan 2023 13:14:52 +0100 Subject: Introduce a "former one-to-one" conversation type Signed-off-by: Joas Schilling --- lib/Activity/Listener.php | 2 +- lib/Activity/Provider/Base.php | 1 + lib/Chat/Parser/UserMention.php | 1 + lib/Collaboration/Reference/TalkReferenceProvider.php | 3 ++- lib/Collaboration/Resources/ConversationProvider.php | 1 + lib/Controller/ChatController.php | 6 ++++-- lib/Controller/PollController.php | 3 ++- lib/Controller/RoomController.php | 17 ++++++++++------- lib/Dashboard/TalkWidget.php | 6 +++++- lib/Manager.php | 5 +++-- lib/Notification/Notifier.php | 15 ++++++++------- lib/Room.php | 1 + lib/Search/ConversationSearch.php | 2 +- lib/Search/MessageSearch.php | 2 +- lib/Service/AvatarService.php | 6 +++--- lib/Service/ParticipantService.php | 2 +- lib/Service/RoomService.php | 19 +++++++++++++++---- 17 files changed, 60 insertions(+), 32 deletions(-) (limited to 'lib') diff --git a/lib/Activity/Listener.php b/lib/Activity/Listener.php index d56a416cd..d4706637c 100644 --- a/lib/Activity/Listener.php +++ b/lib/Activity/Listener.php @@ -137,7 +137,7 @@ class Listener { $message = 'call_ended'; if ($endForEveryone) { $message = 'call_ended_everyone'; - } elseif ($room->getType() === Room::TYPE_ONE_TO_ONE && \count($userIds) === 1) { + } elseif (($room->getType() === Room::TYPE_ONE_TO_ONE || $room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) && \count($userIds) === 1) { $message = 'call_missed'; } diff --git a/lib/Activity/Provider/Base.php b/lib/Activity/Provider/Base.php index 6944ae852..be7def0b0 100644 --- a/lib/Activity/Provider/Base.php +++ b/lib/Activity/Provider/Base.php @@ -113,6 +113,7 @@ abstract class Base implements IProvider { 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: diff --git a/lib/Chat/Parser/UserMention.php b/lib/Chat/Parser/UserMention.php index 7962a0de5..f767343ab 100644 --- a/lib/Chat/Parser/UserMention.php +++ b/lib/Chat/Parser/UserMention.php @@ -172,6 +172,7 @@ class UserMention { 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'; diff --git a/lib/Collaboration/Reference/TalkReferenceProvider.php b/lib/Collaboration/Reference/TalkReferenceProvider.php index 10a77cf8f..d4e428da8 100644 --- a/lib/Collaboration/Reference/TalkReferenceProvider.php +++ b/lib/Collaboration/Reference/TalkReferenceProvider.php @@ -202,7 +202,7 @@ class TalkReferenceProvider implements IReferenceProvider { $description = str_replace($placeholders, $replacements, $message->getMessage()); $titleLine = $this->l->t('Message of {user} in {conversation}'); - if ($room->getType() === Room::TYPE_ONE_TO_ONE) { + if ($room->getType() === Room::TYPE_ONE_TO_ONE || $room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) { $titleLine = $this->l->t('Message of {user}'); } @@ -264,6 +264,7 @@ class TalkReferenceProvider implements IReferenceProvider { 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'; diff --git a/lib/Collaboration/Resources/ConversationProvider.php b/lib/Collaboration/Resources/ConversationProvider.php index f989141fe..5543c8e94 100644 --- a/lib/Collaboration/Resources/ConversationProvider.php +++ b/lib/Collaboration/Resources/ConversationProvider.php @@ -118,6 +118,7 @@ class ConversationProvider implements IProvider { 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'; diff --git a/lib/Controller/ChatController.php b/lib/Controller/ChatController.php index 99cd22b4a..6de8268b7 100644 --- a/lib/Controller/ChatController.php +++ b/lib/Controller/ChatController.php @@ -645,7 +645,8 @@ class ChatController extends AEnvironmentAwareController { $isOwnMessage = $isOwnMessage || ($message->getActorType() === Attendee::ACTOR_BRIDGED && $attendee->getActorId() === MatterbridgeManager::BRIDGE_BOT_USERID); if (!$isOwnMessage && (!$this->participant->hasModeratorPermissions(false) - || $this->room->getType() === Room::TYPE_ONE_TO_ONE)) { + || $this->room->getType() === Room::TYPE_ONE_TO_ONE + || $this->room->getType() === Room::TYPE_ONE_TO_ONE_FORMER)) { // Actor is not a moderator or not the owner of the message return new DataResponse([], Http::STATUS_FORBIDDEN); } @@ -702,7 +703,8 @@ class ChatController extends AEnvironmentAwareController { public function clearHistory(): DataResponse { $attendee = $this->participant->getAttendee(); if (!$this->participant->hasModeratorPermissions(false) - || $this->room->getType() === Room::TYPE_ONE_TO_ONE) { + || $this->room->getType() === Room::TYPE_ONE_TO_ONE + || $this->room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) { // Actor is not a moderator or not the owner of the message return new DataResponse([], Http::STATUS_FORBIDDEN); } diff --git a/lib/Controller/PollController.php b/lib/Controller/PollController.php index cfebd9a14..b4950692a 100644 --- a/lib/Controller/PollController.php +++ b/lib/Controller/PollController.php @@ -77,7 +77,8 @@ class PollController extends AEnvironmentAwareController { * @return DataResponse */ public function createPoll(string $question, array $options, int $resultMode, int $maxVotes): DataResponse { - if ($this->room->getType() === Room::TYPE_ONE_TO_ONE) { + if ($this->room->getType() === Room::TYPE_ONE_TO_ONE + || $this->room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) { return new DataResponse([], Http::STATUS_BAD_REQUEST); } diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php index b4415d0a1..4b561ec76 100644 --- a/lib/Controller/RoomController.php +++ b/lib/Controller/RoomController.php @@ -524,7 +524,7 @@ class RoomController extends AEnvironmentAwareController { if ($roomData['notificationLevel'] === Participant::NOTIFY_DEFAULT) { if ($currentParticipant->isGuest()) { $roomData['notificationLevel'] = Participant::NOTIFY_NEVER; - } elseif ($room->getType() === Room::TYPE_ONE_TO_ONE) { + } elseif ($room->getType() === Room::TYPE_ONE_TO_ONE || $room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) { $roomData['notificationLevel'] = Participant::NOTIFY_ALWAYS; } else { $adminSetting = (int) $this->config->getAppValue('spreed', 'default_group_notification', (string) Participant::NOTIFY_DEFAULT); @@ -574,6 +574,7 @@ class RoomController extends AEnvironmentAwareController { $roomData['lastReadMessage'] = $lastReadMessage; $roomData['canDeleteConversation'] = $room->getType() !== Room::TYPE_ONE_TO_ONE + && $room->getType() !== Room::TYPE_ONE_TO_ONE_FORMER && $currentParticipant->hasModeratorPermissions(false); $roomData['canLeaveConversation'] = true; $roomData['canEnableSIP'] = @@ -920,7 +921,7 @@ class RoomController extends AEnvironmentAwareController { * @return DataResponse */ public function renameRoom(string $roomName): DataResponse { - if ($this->room->getType() === Room::TYPE_ONE_TO_ONE) { + if ($this->room->getType() === Room::TYPE_ONE_TO_ONE || $this->room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) { return new DataResponse([], Http::STATUS_BAD_REQUEST); } @@ -942,7 +943,7 @@ class RoomController extends AEnvironmentAwareController { * @return DataResponse */ public function setDescription(string $description): DataResponse { - if ($this->room->getType() === Room::TYPE_ONE_TO_ONE) { + if ($this->room->getType() === Room::TYPE_ONE_TO_ONE || $this->room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) { return new DataResponse([], Http::STATUS_BAD_REQUEST); } @@ -962,7 +963,7 @@ class RoomController extends AEnvironmentAwareController { * @return DataResponse */ public function deleteRoom(): DataResponse { - if ($this->room->getType() === Room::TYPE_ONE_TO_ONE) { + if ($this->room->getType() === Room::TYPE_ONE_TO_ONE || $this->room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) { return new DataResponse([], Http::STATUS_BAD_REQUEST); } @@ -1118,7 +1119,9 @@ class RoomController extends AEnvironmentAwareController { * @return DataResponse */ public function addParticipantToRoom(string $newParticipant, string $source = 'users'): DataResponse { - if ($this->room->getType() === Room::TYPE_ONE_TO_ONE || $this->room->getObjectType() === 'share:password') { + if ($this->room->getType() === Room::TYPE_ONE_TO_ONE + || $this->room->getType() === Room::TYPE_ONE_TO_ONE_FORMER + || $this->room->getObjectType() === 'share:password') { return new DataResponse([], Http::STATUS_BAD_REQUEST); } @@ -1269,7 +1272,7 @@ class RoomController extends AEnvironmentAwareController { } protected function removeSelfFromRoomLogic(Room $room, Participant $participant): DataResponse { - if ($room->getType() !== Room::TYPE_ONE_TO_ONE) { + if ($room->getType() !== Room::TYPE_ONE_TO_ONE && $room->getType() !== Room::TYPE_ONE_TO_ONE_FORMER) { if ($participant->hasModeratorPermissions(false) && $this->participantService->getNumberOfUsers($room) > 1 && $this->participantService->getNumberOfModerators($room) === 1) { @@ -1318,7 +1321,7 @@ class RoomController extends AEnvironmentAwareController { return new DataResponse([], Http::STATUS_NOT_FOUND); } - if ($this->room->getType() === Room::TYPE_ONE_TO_ONE) { + if ($this->room->getType() === Room::TYPE_ONE_TO_ONE || $this->room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) { return new DataResponse([], Http::STATUS_BAD_REQUEST); } diff --git a/lib/Dashboard/TalkWidget.php b/lib/Dashboard/TalkWidget.php index 6137585a3..d5f21c4e1 100644 --- a/lib/Dashboard/TalkWidget.php +++ b/lib/Dashboard/TalkWidget.php @@ -164,7 +164,11 @@ class TalkWidget implements IAPIWidget, IIconWidget, IButtonWidget, IOptionWidge $attendee = $participant->getAttendee(); return $room->getCallFlag() !== Participant::FLAG_DISCONNECTED || $attendee->getLastMentionMessage() > $attendee->getLastReadMessage() - || ($room->getType() === Room::TYPE_ONE_TO_ONE && $room->getLastMessage() && $room->getLastMessage()->getId() > $attendee->getLastReadMessage()); + || ( + ($room->getType() === Room::TYPE_ONE_TO_ONE || $room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) + && $room->getLastMessage() + && $room->getLastMessage()->getId() > $attendee->getLastReadMessage() + ); }); uasort($rooms, [$this, 'sortRooms']); diff --git a/lib/Manager.php b/lib/Manager.php index 4beb0b47c..83d406557 100644 --- a/lib/Manager.php +++ b/lib/Manager.php @@ -432,12 +432,13 @@ class Manager { $leftRooms = $this->getLeftOneToOneRoomsForUser($user->getUID()); foreach ($leftRooms as $room) { - // We are changing the room type and name so a potential follow up + // We are changing the room type and name so a potential follow-up // user with the same user-id can not reopen the one-to-one conversation. /** @var RoomService $roomService */ $roomService = Server::get(RoomService::class); - $roomService->setType($room, Room::TYPE_GROUP, true); + $roomService->setType($room, Room::TYPE_ONE_TO_ONE_FORMER, true); $roomService->setName($room, $user->getDisplayName(), ''); + $roomService->setReadOnly($room, Room::READ_ONLY); } } diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index b9e65147e..07fae5d02 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -503,7 +503,7 @@ class Notifier implements INotifier { 'id' => $message->getComment()->getId(), 'name' => $shortenMessage, ]; - if ($room->getType() === Room::TYPE_ONE_TO_ONE) { + if ($room->getType() === Room::TYPE_ONE_TO_ONE || $room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) { $subject = "{user}\n{message}"; } elseif ($richSubjectUser) { $subject = $l->t('{user} in {call}') . "\n{message}"; @@ -518,7 +518,7 @@ class Notifier implements INotifier { } } } elseif ($notification->getSubject() === 'chat') { - if ($room->getType() === Room::TYPE_ONE_TO_ONE) { + if ($room->getType() === Room::TYPE_ONE_TO_ONE || $room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) { $subject = $l->t('{user} sent you a private message'); } elseif ($richSubjectUser) { $subject = $l->t('{user} sent a message in conversation {call}'); @@ -533,7 +533,7 @@ class Notifier implements INotifier { } } } elseif ($notification->getSubject() === 'reply') { - if ($room->getType() === Room::TYPE_ONE_TO_ONE) { + if ($room->getType() === Room::TYPE_ONE_TO_ONE || $room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) { $subject = $l->t('{user} replied to your private message'); } elseif ($richSubjectUser) { $subject = $l->t('{user} replied to your message in conversation {call}'); @@ -554,7 +554,7 @@ class Notifier implements INotifier { 'name' => $subjectParameters['reaction'], ]; - if ($room->getType() === Room::TYPE_ONE_TO_ONE) { + if ($room->getType() === Room::TYPE_ONE_TO_ONE || $room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) { $subject = $l->t('{user} reacted with {reaction} to your private message'); } elseif ($richSubjectUser) { $subject = $l->t('{user} reacted with {reaction} to your message in conversation {call}'); @@ -568,7 +568,7 @@ class Notifier implements INotifier { $subject = $l->t('A guest reacted with {reaction} to your message in conversation {call}'); } } - } elseif ($room->getType() === Room::TYPE_ONE_TO_ONE) { + } elseif ($room->getType() === Room::TYPE_ONE_TO_ONE || $room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) { $subject = $l->t('{user} mentioned you in a private conversation'); } elseif ($richSubjectUser) { $subject = $l->t('{user} mentioned you in conversation {call}'); @@ -628,6 +628,7 @@ class Notifier implements INotifier { 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'; @@ -660,7 +661,7 @@ class Notifier implements INotifier { } $roomName = $room->getDisplayName($notification->getUser()); - if ($room->getType() === Room::TYPE_ONE_TO_ONE) { + if ($room->getType() === Room::TYPE_ONE_TO_ONE || $room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) { $subject = $l->t('{user} invited you to a private conversation'); if ($this->participantService->hasActiveSessionsInCall($room)) { $notification = $this->addActionButton($notification, $l->t('Join call')); @@ -731,7 +732,7 @@ class Notifier implements INotifier { } $roomName = $room->getDisplayName($notification->getUser()); - if ($room->getType() === Room::TYPE_ONE_TO_ONE) { + if ($room->getType() === Room::TYPE_ONE_TO_ONE || $room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) { $parameters = $notification->getSubjectParameters(); $calleeId = $parameters['callee']; $userDisplayName = $this->userManager->getDisplayName($calleeId); diff --git a/lib/Room.php b/lib/Room.php index e5a7e6b3e..d1cacff27 100644 --- a/lib/Room.php +++ b/lib/Room.php @@ -54,6 +54,7 @@ class Room { public const TYPE_GROUP = 2; public const TYPE_PUBLIC = 3; public const TYPE_CHANGELOG = 4; + public const TYPE_ONE_TO_ONE_FORMER = 5; public const RECORDING_NONE = 0; public const RECORDING_VIDEO = 1; diff --git a/lib/Search/ConversationSearch.php b/lib/Search/ConversationSearch.php index 4dc97aed9..f4b99954c 100644 --- a/lib/Search/ConversationSearch.php +++ b/lib/Search/ConversationSearch.php @@ -100,7 +100,7 @@ class ConversationSearch implements IProvider { continue; } - if ($room->getType() === Room::TYPE_ONE_TO_ONE) { + if ($room->getType() === Room::TYPE_ONE_TO_ONE || $room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) { $otherUserId = str_replace( json_encode($user->getUID()), '', diff --git a/lib/Search/MessageSearch.php b/lib/Search/MessageSearch.php index 3e1fe3c87..1614d2720 100644 --- a/lib/Search/MessageSearch.php +++ b/lib/Search/MessageSearch.php @@ -217,7 +217,7 @@ class MessageSearch implements IProvider { } $subline = $this->getSublineTemplate(); - if ($room->getType() === Room::TYPE_ONE_TO_ONE) { + if ($room->getType() === Room::TYPE_ONE_TO_ONE || $room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) { $subline = '{user}'; } diff --git a/lib/Service/AvatarService.php b/lib/Service/AvatarService.php index 1e8e5247b..c05d27a0c 100644 --- a/lib/Service/AvatarService.php +++ b/lib/Service/AvatarService.php @@ -69,7 +69,7 @@ class AvatarService { } public function setAvatarFromRequest(Room $room, ?array $file): void { - if ($room->getType() === Room::TYPE_ONE_TO_ONE) { + if ($room->getType() === Room::TYPE_ONE_TO_ONE || $room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) { throw new InvalidArgumentException($this->l->t('One to one rooms always need to show the other users avatar')); } @@ -97,7 +97,7 @@ class AvatarService { } public function setAvatar(Room $room, \OC_Image $image): void { - if ($room->getType() === Room::TYPE_ONE_TO_ONE) { + if ($room->getType() === Room::TYPE_ONE_TO_ONE || $room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) { throw new InvalidArgumentException($this->l->t('One to one rooms always need to show the other users avatar')); } $image->fixOrientation(); @@ -166,7 +166,7 @@ class AvatarService { } // Fallback if (!isset($file)) { - if ($room->getType() === Room::TYPE_ONE_TO_ONE) { + if ($room->getType() === Room::TYPE_ONE_TO_ONE || $room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) { $users = json_decode($room->getName(), true); foreach ($users as $participantId) { if ($user instanceof IUser && $participantId !== $user->getUID()) { diff --git a/lib/Service/ParticipantService.php b/lib/Service/ParticipantService.php index 140e733bf..2941972c8 100644 --- a/lib/Service/ParticipantService.php +++ b/lib/Service/ParticipantService.php @@ -201,7 +201,7 @@ class ParticipantService { * @throws ForbiddenException */ public function updatePermissions(Room $room, Participant $participant, string $method, int $newPermissions): bool { - if ($room->getType() === Room::TYPE_ONE_TO_ONE) { + if ($room->getType() === Room::TYPE_ONE_TO_ONE || $room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) { return false; } diff --git a/lib/Service/RoomService.php b/lib/Service/RoomService.php index 572a12951..08d149660 100644 --- a/lib/Service/RoomService.php +++ b/lib/Service/RoomService.php @@ -182,7 +182,7 @@ class RoomService { } public function setPermissions(Room $room, string $level, string $method, int $permissions, bool $resetCustomPermissions): bool { - if ($room->getType() === Room::TYPE_ONE_TO_ONE) { + if ($room->getType() === Room::TYPE_ONE_TO_ONE || $room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) { return false; } @@ -347,7 +347,7 @@ class RoomService { } public function setAvatar(Room $room, string $avatar): bool { - if ($room->getType() === Room::TYPE_ONE_TO_ONE) { + if ($room->getType() === Room::TYPE_ONE_TO_ONE || $room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) { return false; } @@ -412,7 +412,15 @@ class RoomService { return false; } - if (!in_array($newType, [Room::TYPE_GROUP, Room::TYPE_PUBLIC], true)) { + if ($room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) { + return false; + } + + if (!in_array($newType, [Room::TYPE_GROUP, Room::TYPE_PUBLIC, Room::TYPE_ONE_TO_ONE_FORMER], true)) { + return false; + } + + if ($newType === Room::TYPE_ONE_TO_ONE_FORMER && $room->getType() !== Room::TYPE_ONE_TO_ONE) { return false; } @@ -466,7 +474,10 @@ class RoomService { } if (!in_array($room->getType(), [Room::TYPE_GROUP, Room::TYPE_PUBLIC, Room::TYPE_CHANGELOG], true)) { - return false; + if ($newState !== Room::READ_ONLY || $room->getType() !== Room::TYPE_ONE_TO_ONE_FORMER) { + // Allowed for the automated conversation of one-to-one chats to read only former + return false; + } } if (!in_array($newState, [Room::READ_ONLY, Room::READ_WRITE], true)) { -- cgit v1.2.3