summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2024-11-15 09:03:22 +0100
committerJoas Schilling <coding@schilljs.com>2024-11-15 22:41:07 +0100
commit693a4595aabe02e3b17d87e38adb52ed97b146f5 (patch)
tree5e685ef6a3ebda90d3c13c8cc79805c4b7c310ed
parent7c8a1dbbc9ba1399d4bf96f8a5aa2946da6ab039 (diff)
fix: Manually copy new method from Nextcloud 31backport/13661/stable30
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r--lib/Controller/ChatController.php22
-rw-r--r--tests/php/Controller/ChatControllerTest.php4
2 files changed, 19 insertions, 7 deletions
diff --git a/lib/Controller/ChatController.php b/lib/Controller/ChatController.php
index 3c0c10b3cd..e9f74a1032 100644
--- a/lib/Controller/ChatController.php
+++ b/lib/Controller/ChatController.php
@@ -65,7 +65,6 @@ use OCP\IL10N;
use OCP\IRequest;
use OCP\IUserManager;
use OCP\RichObjectStrings\InvalidObjectExeption;
-use OCP\RichObjectStrings\IRichTextFormatter;
use OCP\RichObjectStrings\IValidator;
use OCP\Security\ITrustedDomainHelper;
use OCP\Security\RateLimiting\IRateLimitExceededException;
@@ -123,7 +122,6 @@ class ChatController extends AEnvironmentAwareController {
protected Authenticator $federationAuthenticator,
protected ProxyCacheMessageService $pcmService,
protected Notifier $notifier,
- protected IRichTextFormatter $richTextFormatter,
protected ITaskProcessingManager $taskProcessingManager,
protected IAppConfig $appConfig,
protected LoggerInterface $logger,
@@ -570,7 +568,7 @@ class ChatController extends AEnvironmentAwareController {
continue;
}
- $parsedMessage = $this->richTextFormatter->richToParsed(
+ $parsedMessage = $this->richToParsed(
$message->getMessage(),
$message->getMessageParameters(),
);
@@ -635,6 +633,24 @@ class ChatController extends AEnvironmentAwareController {
}
/**
+ * Function is copied from Nextcloud 31 \OCP\RichObjectStrings\IRichTextFormatter::richToParsed
+ * @deprecated
+ */
+ protected function richToParsed(string $message, array $parameters): string {
+ $placeholders = [];
+ $replacements = [];
+ foreach ($parameters as $placeholder => $parameter) {
+ $placeholders[] = '{' . $placeholder . '}';
+ $replacements[] = match($parameter['type']) {
+ 'user' => '@' . $parameter['name'],
+ 'file' => $parameter['path'] ?? $parameter['name'],
+ default => $parameter['name'],
+ };
+ }
+ return str_replace($placeholders, $replacements, $message);
+ }
+
+ /**
* @return DataResponse<Http::STATUS_OK|Http::STATUS_NOT_MODIFIED, TalkChatMessageWithParent[], array{X-Chat-Last-Common-Read?: numeric-string, X-Chat-Last-Given?: numeric-string}>
*/
protected function prepareCommentsAsDataResponse(array $comments, int $lastCommonReadId = 0): DataResponse {
diff --git a/tests/php/Controller/ChatControllerTest.php b/tests/php/Controller/ChatControllerTest.php
index 37d6cc4136..baf9bcad02 100644
--- a/tests/php/Controller/ChatControllerTest.php
+++ b/tests/php/Controller/ChatControllerTest.php
@@ -44,7 +44,6 @@ use OCP\IL10N;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserManager;
-use OCP\RichObjectStrings\IRichTextFormatter;
use OCP\RichObjectStrings\IValidator;
use OCP\Security\ITrustedDomainHelper;
use OCP\TaskProcessing\IManager as ITaskProcessingManager;
@@ -85,7 +84,6 @@ class ChatControllerTest extends TestCase {
private Authenticator&MockObject $federationAuthenticator;
private ProxyCacheMessageService&MockObject $pcmService;
private Notifier&MockObject $notifier;
- private IRichTextFormatter&MockObject $richTextFormatter;
private ITaskProcessingManager&MockObject $taskProcessingManager;
private IAppConfig&MockObject $appConfig;
private LoggerInterface&MockObject $logger;
@@ -129,7 +127,6 @@ class ChatControllerTest extends TestCase {
$this->federationAuthenticator = $this->createMock(Authenticator::class);
$this->pcmService = $this->createMock(ProxyCacheMessageService::class);
$this->notifier = $this->createMock(Notifier::class);
- $this->richTextFormatter = $this->createMock(IRichTextFormatter::class);
$this->taskProcessingManager = $this->createMock(ITaskProcessingManager::class);
$this->appConfig = $this->createMock(IAppConfig::class);
$this->logger = $this->createMock(LoggerInterface::class);
@@ -179,7 +176,6 @@ class ChatControllerTest extends TestCase {
$this->federationAuthenticator,
$this->pcmService,
$this->notifier,
- $this->richTextFormatter,
$this->taskProcessingManager,
$this->appConfig,
$this->logger,