diff --git a/lib/Chat/Parser/SystemMessage.php b/lib/Chat/Parser/SystemMessage.php index d463877a54a..499950e1978 100644 --- a/lib/Chat/Parser/SystemMessage.php +++ b/lib/Chat/Parser/SystemMessage.php @@ -756,17 +756,18 @@ protected function getFileFromShare(Room $room, ?Participant $participant, strin if ($participant && $participant->getAttendee()->getActorType() === Attendee::ACTOR_USERS) { if ($share->getShareOwner() !== $participant->getAttendee()->getActorId()) { $userFolder = $this->rootFolder->getUserFolder($participant->getAttendee()->getActorId()); - if ($userFolder instanceof Node) { - $userNodes = $userFolder->getById($share->getNodeId()); + if (!$userFolder instanceof Node) { + throw new ShareNotFound(); + } - if (empty($userNodes)) { - // FIXME This should be much more sensible, e.g. - // 1. Only be executed on "Waiting for new messages" - // 2. Once per request - \OC_Util::tearDownFS(); - \OC_Util::setupFS($participant->getAttendee()->getActorId()); - $userNodes = $userFolder->getById($share->getNodeId()); - } + $node = $userFolder->getFirstNodeById($share->getNodeId()); + if (!$node instanceof Node) { + // FIXME This should be much more sensible, e.g. + // 1. Only be executed on "Waiting for new messages" + // 2. Once per request + \OC_Util::tearDownFS(); + \OC_Util::setupFS($participant->getAttendee()->getActorId()); + $userNodes = $userFolder->getById($share->getNodeId()); if (empty($userNodes)) { throw new NotFoundException('File was not found'); @@ -774,12 +775,13 @@ protected function getFileFromShare(Room $room, ?Participant $participant, strin /** @var Node $node */ $node = reset($userNodes); - $fullPath = $node->getPath(); - $pathSegments = explode('/', $fullPath, 4); - $name = $node->getName(); - $size = $node->getSize(); - $path = $pathSegments[3] ?? $name; } + + $fullPath = $node->getPath(); + $pathSegments = explode('/', $fullPath, 4); + $name = $node->getName(); + $size = $node->getSize(); + $path = $pathSegments[3] ?? $name; } else { $node = $share->getNode(); $name = $node->getName(); diff --git a/tests/php/Chat/Parser/SystemMessageTest.php b/tests/php/Chat/Parser/SystemMessageTest.php index 66dee38484e..36c2f0e5daf 100644 --- a/tests/php/Chat/Parser/SystemMessageTest.php +++ b/tests/php/Chat/Parser/SystemMessageTest.php @@ -873,7 +873,11 @@ public function testGetFileFromShareForRecipientThrows() { ->willReturn($share); $userFolder = $this->createMock(Folder::class); - $userFolder->expects($this->exactly(2)) + $userFolder->expects($this->once()) + ->method('getFirstNodeById') + ->with('54') + ->willReturn(null); + $userFolder->expects($this->once()) ->method('getById') ->with('54') ->willReturn([]);