summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2024-05-03 11:25:07 +0200
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>2024-05-16 16:12:32 +0000
commit742045b62eb2d4a11d8c969093f6a79024ce09e7 (patch)
tree3e48ea5c6ed592801bee089a135a576e5edd9247
parentba023601fbc3c605cd153d51f593f1c6c4ef23ee (diff)
fix(chat): Better handling of captioned messages in federated conversationsbackport/12256/stable29
Signed-off-by: Joas Schilling <coding@schilljs.com> [skip ci]
-rw-r--r--lib/Chat/Parser/SystemMessage.php19
-rw-r--r--tests/integration/features/sharing-1/delete.feature7
-rw-r--r--tests/php/Chat/Parser/SystemMessageTest.php37
3 files changed, 34 insertions, 29 deletions
diff --git a/lib/Chat/Parser/SystemMessage.php b/lib/Chat/Parser/SystemMessage.php
index e9469527d..3a4e12701 100644
--- a/lib/Chat/Parser/SystemMessage.php
+++ b/lib/Chat/Parser/SystemMessage.php
@@ -500,7 +500,7 @@ class SystemMessage implements IEventListener {
}
} elseif ($message === 'file_shared') {
try {
- $parsedParameters['file'] = $this->getFileFromShare($participant, $parameters['share']);
+ $parsedParameters['file'] = $this->getFileFromShare($room, $participant, $parameters['share']);
$parsedMessage = '{file}';
$metaData = $parameters['metaData'] ?? [];
if (isset($metaData['messageType'])) {
@@ -520,10 +520,19 @@ class SystemMessage implements IEventListener {
if (isset($metaData['caption']) && $metaData['caption'] !== '') {
$parsedMessage = $metaData['caption'];
}
- } catch (\Exception $e) {
+ } catch (\Exception) {
+ $chatMessage->setMessageType(ChatManager::VERB_MESSAGE);
$parsedMessage = $this->l->t('{actor} shared a file which is no longer available');
if ($currentUserIsActor) {
$parsedMessage = $this->l->t('You shared a file which is no longer available');
+ } elseif ($currentActorType === Attendee::ACTOR_FEDERATED_USERS) {
+ $parsedMessage = $this->l->t('File shares are currently not supported in federated conversations');
+ }
+ $parsedMessage = '*' . $parsedMessage . '*';
+
+ $metaData = $parameters['metaData'] ?? [];
+ if (isset($metaData['caption']) && $metaData['caption'] !== '') {
+ $parsedMessage .= "\n\n" . $metaData['caption'];
}
}
} elseif ($message === 'object_shared') {
@@ -741,10 +750,10 @@ class SystemMessage implements IEventListener {
* @throws NotFoundException
* @throws ShareNotFound
*/
- protected function getFileFromShare(?Participant $participant, string $shareId): array {
+ protected function getFileFromShare(Room $room, ?Participant $participant, string $shareId): array {
$share = $this->shareProvider->getShareById((int) $shareId);
- if ($participant && !$participant->isGuest()) {
+ 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) {
@@ -784,6 +793,8 @@ class SystemMessage implements IEventListener {
$url = $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', [
'fileid' => $node->getId(),
]);
+ } elseif ($participant && $room->getType() !== Room::TYPE_PUBLIC && $participant->getAttendee()->getActorType() === Attendee::ACTOR_FEDERATED_USERS) {
+ throw new ShareNotFound();
} else {
$node = $share->getNode();
$name = $node->getName();
diff --git a/tests/integration/features/sharing-1/delete.feature b/tests/integration/features/sharing-1/delete.feature
index d5d472001..21ae2a589 100644
--- a/tests/integration/features/sharing-1/delete.feature
+++ b/tests/integration/features/sharing-1/delete.feature
@@ -384,7 +384,6 @@ Feature: delete
| poll | 0 |
| voice | 0 |
| recording | 0 |
- And user "participant1" sees the following system messages in room "public room" with 200
- | room | actorType | actorId | actorDisplayName | systemMessage |
- | public room | users | participant1 | participant1-displayname | file_shared |
- | public room | users | participant1 | participant1-displayname | conversation_created |
+ And user "participant1" sees the following messages in room "public room" with 200
+ | room | actorType | actorId | actorDisplayName | message | messageParameters |
+ | public room | users | participant1 | participant1-displayname | *You shared a file which is no longer available* | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} |
diff --git a/tests/php/Chat/Parser/SystemMessageTest.php b/tests/php/Chat/Parser/SystemMessageTest.php
index 269643705..2490c4b47 100644
--- a/tests/php/Chat/Parser/SystemMessageTest.php
+++ b/tests/php/Chat/Parser/SystemMessageTest.php
@@ -381,11 +381,11 @@ class SystemMessageTest extends TestCase {
['actor' => ['id' => 'actor', 'type' => 'user'], 'file' => ['id' => 'file-from-share']],
],
['file_shared', ['share' => InvalidPathException::class], 'recipient',
- '{actor} shared a file which is no longer available',
+ '*{actor} shared a file which is no longer available*',
['actor' => ['id' => 'actor', 'type' => 'user']],
],
['file_shared', ['share' => NotFoundException::class], 'actor',
- 'You shared a file which is no longer available',
+ '*You shared a file which is no longer available*',
['actor' => ['id' => 'actor', 'type' => 'user']],
],
['read_only', [], 'recipient',
@@ -555,12 +555,12 @@ class SystemMessageTest extends TestCase {
if (is_subclass_of($parameters['share'], \Exception::class)) {
$parser->expects($this->once())
->method('getFileFromShare')
- ->with($participant, $parameters['share'])
+ ->with($room, $participant, $parameters['share'])
->willThrowException(new $parameters['share']());
} else {
$parser->expects($this->once())
->method('getFileFromShare')
- ->with($participant, $parameters['share'])
+ ->with($room, $participant, $parameters['share'])
->willReturn(['id' => 'file-from-share']);
}
} else {
@@ -670,9 +670,6 @@ class SystemMessageTest extends TestCase {
->willReturn(['width' => 1234, 'height' => 4567]);
$participant = $this->createMock(Participant::class);
- $participant->expects($this->once())
- ->method('isGuest')
- ->willReturn(true);
$parser = $this->getParser();
$this->assertSame([
@@ -688,7 +685,7 @@ class SystemMessageTest extends TestCase {
'preview-available' => 'yes',
'width' => '1234',
'height' => '4567',
- ], self::invokePrivate($parser, 'getFileFromShare', [$participant, '23']));
+ ], self::invokePrivate($parser, 'getFileFromShare', [$room, $participant, '23']));
}
public function testGetFileFromShareForOwner() {
@@ -744,9 +741,6 @@ class SystemMessageTest extends TestCase {
->method('getMetadataPhotosSizeForFileId');
$participant = $this->createMock(Participant::class);
- $participant->expects($this->once())
- ->method('isGuest')
- ->willReturn(false);
$attendee = Attendee::fromRow([
'actor_type' => 'users',
'actor_id' => 'owner',
@@ -767,7 +761,7 @@ class SystemMessageTest extends TestCase {
'permissions' => '27',
'mimetype' => 'httpd/unix-directory',
'preview-available' => 'no',
- ], self::invokePrivate($parser, 'getFileFromShare', [$participant, '23']));
+ ], self::invokePrivate($parser, 'getFileFromShare', [$room, $participant, '23']));
}
public function testGetFileFromShareForRecipient() {
@@ -777,9 +771,6 @@ class SystemMessageTest extends TestCase {
->willReturn(54);
$participant = $this->createMock(Participant::class);
- $participant->expects($this->once())
- ->method('isGuest')
- ->willReturn(false);
$attendee = Attendee::fromRow([
'actor_type' => 'users',
'actor_id' => 'user',
@@ -854,7 +845,7 @@ class SystemMessageTest extends TestCase {
'permissions' => '27',
'mimetype' => 'application/octet-stream',
'preview-available' => 'no',
- ], self::invokePrivate($parser, 'getFileFromShare', [$participant, '23']));
+ ], self::invokePrivate($parser, 'getFileFromShare', [$room, $participant, '23']));
}
public function testGetFileFromShareForRecipientThrows() {
@@ -864,9 +855,6 @@ class SystemMessageTest extends TestCase {
->willReturn(54);
$participant = $this->createMock(Participant::class);
- $participant->expects($this->once())
- ->method('isGuest')
- ->willReturn(false);
$attendee = Attendee::fromRow([
'actor_type' => 'users',
'actor_id' => 'user',
@@ -896,7 +884,7 @@ class SystemMessageTest extends TestCase {
$parser = $this->getParser();
$this->expectException(NotFoundException::class);
- self::invokePrivate($parser, 'getFileFromShare', [$participant, '23']);
+ self::invokePrivate($parser, 'getFileFromShare', [$room, $participant, '23']);
}
public function testGetFileFromShareThrows() {
@@ -906,9 +894,16 @@ class SystemMessageTest extends TestCase {
->willThrowException(new ShareNotFound());
$participant = $this->createMock(Participant::class);
+ $attendee = Attendee::fromRow([
+ 'actor_type' => 'users',
+ 'actor_id' => 'user',
+ ]);
+ $participant->expects($this->any())
+ ->method('getAttendee')
+ ->willReturn($attendee);
$parser = $this->getParser();
$this->expectException(ShareNotFound::class);
- self::invokePrivate($parser, 'getFileFromShare', [$participant, '23']);
+ self::invokePrivate($parser, 'getFileFromShare', [$room, $participant, '23']);
}
public static function dataGetActor(): array {