Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/Chat/SystemMessage/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ public static function register(IEventDispatcher $dispatcher): void {
$dispatcher->addListener(Room::EVENT_AFTER_TYPE_SET, static function (ModifyRoomEvent $event) {
$room = $event->getRoom();

if ($event->getOldValue() === Room::ONE_TO_ONE_CALL) {
return;
}

if ($event->getNewValue() === Room::PUBLIC_CALL) {
/** @var self $listener */
$listener = \OC::$server->query(self::class);
Expand Down
9 changes: 8 additions & 1 deletion lib/Listener/UserDeletedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,20 @@ public function handle(Event $event): void {
$user = $event->getUser();

$rooms = $this->manager->getRoomsForUser($user->getUID());

foreach ($rooms as $room) {
if ($this->participantService->getNumberOfUsers($room) === 1) {
$room->deleteRoom();
} else {
$this->participantService->removeUser($room, $user, Room::PARTICIPANT_REMOVED);
}
}

$leftRooms = $this->manager->getLeftOneToOneRoomsForUser($user->getUID());
foreach ($leftRooms as $room) {
// 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.
$room->setType(Room::GROUP_CALL, true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this means other users could be invited to that conversation and then they could read past messages, feels like an unwanted side effect.
if we had a way to mark it as archived, like read-only mode but would need an external system user moderator then to prevent anyone to remove there read-only flag

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No one cares? Don't want to make it overly complicated so that is good enough. Before you could do screenshares and share them already ¯\_(ツ)_/¯

I'm fine with marking it archived by default as well. We could also "demote" the other user to be a normal user and they can then leave the conversation only. But simplicity is the key here I think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested it and seems fine then.

A good thing is that now that it's a group conversation, the remaining user is able to delete it also.

$room->setName($user->getDisplayName(), '');
}
}
}
28 changes: 28 additions & 0 deletions lib/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,34 @@ public function getRoomsForActor(string $actorType, string $actorId, array $sess
return $rooms;
}

/**
* @param string $userId
* @return Room[]
*/
public function getLeftOneToOneRoomsForUser(string $userId): array {
$query = $this->db->getQueryBuilder();
$helper = new SelectHelper();
$helper->selectRoomsTable($query);
$query->from('talk_rooms', 'r')
->where($query->expr()->eq('r.type', $query->createNamedParameter(Room::ONE_TO_ONE_CALL)))
->andWhere($query->expr()->like('r.name', $query->createNamedParameter('%' . $this->db->escapeLikeParameter(json_encode($userId)) . '%')));

$result = $query->execute();
$rooms = [];
while ($row = $result->fetch()) {
if ($row['token'] === null) {
// FIXME Temporary solution for the Talk6 release
continue;
}

$room = $this->createRoomObject($row);
$rooms[] = $room;
}
$result->closeCursor();

return $rooms;
}

/**
* @param string $userId
* @return string[]
Expand Down
4 changes: 2 additions & 2 deletions lib/Room.php
Original file line number Diff line number Diff line change
Expand Up @@ -813,12 +813,12 @@ public function setAssignedSignalingServer(?int $signalingServer): bool {
* @param int $newType Currently it is only allowed to change between `self::GROUP_CALL` and `self::PUBLIC_CALL`
* @return bool True when the change was valid, false otherwise
*/
public function setType(int $newType): bool {
public function setType(int $newType, bool $allowSwitchingOneToOne = false): bool {
if ($newType === $this->getType()) {
return true;
}

if ($this->getType() === self::ONE_TO_ONE_CALL) {
if (!$allowSwitchingOneToOne && $this->getType() === self::ONE_TO_ONE_CALL) {
return false;
}

Expand Down
17 changes: 17 additions & 0 deletions tests/integration/features/conversation/delete-user.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@ Feature: conversation/delete-user
Then user "participant1" sees the following messages in room "one-to-one room" with 200
| room | actorType | actorId | actorDisplayName | message | messageParameters |
| one-to-one room | deleted_users | deleted_users | | Message 1 | [] |
Then user "participant1" is participant of the following rooms (v4)
| name | type |
| participant2-displayname | 2 |

Scenario: delete user who left a one-to-one room
Given user "participant1" creates room "one-to-one room" (v4)
| roomType | 1 |
| invite | participant2 |
And user "participant2" sends message "Message 1" to room "one-to-one room" with 201
When user "participant2" leaves room "one-to-one room" with 200 (v4)
When user "participant2" is deleted
Then user "participant1" sees the following messages in room "one-to-one room" with 200
| room | actorType | actorId | actorDisplayName | message | messageParameters |
| one-to-one room | deleted_users | deleted_users | | Message 1 | [] |
Then user "participant1" is participant of the following rooms (v4)
| name | type |
| participant2-displayname | 2 |

Scenario: delete user who is in a group room
Given user "participant1" creates room "group room" (v4)
Expand Down