From 96baf853acf98ffd076afde9484c6d917c5a2968 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 28 Feb 2024 19:36:45 +0100 Subject: [PATCH] feat(federation): Expose the info to show the subline for proxy convos Signed-off-by: Joas Schilling --- lib/Model/ProxyCacheMessages.php | 30 +++++++++++++++-- lib/ResponseDefinitions.php | 15 ++++++++- lib/Service/RoomFormatter.php | 20 ++++++++--- openapi-backend-sipbridge.json | 58 +++++++++++++++++++++++++++++++- openapi-federation.json | 58 +++++++++++++++++++++++++++++++- openapi-full.json | 58 +++++++++++++++++++++++++++++++- openapi.json | 58 +++++++++++++++++++++++++++++++- 7 files changed, 285 insertions(+), 12 deletions(-) diff --git a/lib/Model/ProxyCacheMessages.php b/lib/Model/ProxyCacheMessages.php index 0d7cf7db78d9..9803f3e2b700 100644 --- a/lib/Model/ProxyCacheMessages.php +++ b/lib/Model/ProxyCacheMessages.php @@ -26,6 +26,7 @@ namespace OCA\Talk\Model; +use OCA\Talk\ResponseDefinitions; use OCP\AppFramework\Db\Entity; /** @@ -47,14 +48,16 @@ * @method string getMessageType() * @method void setSystemMessage(?string $systemMessage) * @method string|null getSystemMessage() - * @method void setExpirationDateTime(?\DateTimeImmutable $expirationDateTime) - * @method \DateTimeImmutable|null getExpirationDateTime() + * @method void setExpirationDatetime(?\DateTimeImmutable $expirationDatetime) + * @method \DateTimeImmutable|null getExpirationDatetime() * @method void setMessage(?string $message) * @method string|null getMessage() * @method void setMessageParameters(?string $messageParameters) * @method string|null getMessageParameters() + * + * @psalm-import-type TalkRoomProxyMessage from ResponseDefinitions */ -class ProxyCacheMessages extends Entity { +class ProxyCacheMessages extends Entity implements \JsonSerializable { protected string $localToken = ''; protected string $remoteServerUrl = ''; @@ -83,4 +86,25 @@ public function __construct() { $this->addType('message', 'string'); $this->addType('messageParameters', 'string'); } + + /** + * @return TalkRoomProxyMessage + */ + public function jsonSerialize(): array { + $expirationTimestamp = 0; + if ($this->getExpirationDatetime()) { + $expirationTimestamp = $this->getExpirationDatetime()->getTimestamp(); + } + + return [ + 'actorType' => $this->getActorType(), + 'actorId' => $this->getActorId(), + 'actorDisplayName' => $this->getActorDisplayName(), + 'expirationTimestamp' => $expirationTimestamp, + 'messageType' => $this->getMessageType(), + 'systemMessage' => $this->getSystemMessage() ?? '', + 'message' => $this->getMessage() ?? '', + 'messageParameters' => json_decode($this->getMessageParameters() ?? '[]', true), + ]; + } } diff --git a/lib/ResponseDefinitions.php b/lib/ResponseDefinitions.php index 82136baef489..1f257d8224bc 100644 --- a/lib/ResponseDefinitions.php +++ b/lib/ResponseDefinitions.php @@ -91,6 +91,19 @@ * silent?: bool, * } * + * @psalm-type TalkRoomProxyMessage = array{ + * actorDisplayName: string, + * actorId: string, + * actorType: string, + * expirationTimestamp: int, + * message: string, + * messageParameters: array>, + * messageType: string, + * systemMessage: string, + * } + * + * @psalm-type TalkRoomLastMessage = TalkChatMessage|TalkRoomProxyMessage + * * @psalm-type TalkChatMessageWithParent = TalkChatMessage&array{parent?: TalkChatMessage} * * @psalm-type TalkChatReminder = array{ @@ -208,7 +221,7 @@ * isFavorite: bool, * lastActivity: int, * lastCommonReadMessage: int, - * lastMessage: TalkChatMessage|array, + * lastMessage: TalkRoomLastMessage|array, * lastPing: int, * lastReadMessage: int, * listable: int, diff --git a/lib/Service/RoomFormatter.php b/lib/Service/RoomFormatter.php index 41c3e6aaf697..d20aa45318c6 100644 --- a/lib/Service/RoomFormatter.php +++ b/lib/Service/RoomFormatter.php @@ -30,12 +30,14 @@ use OCA\Talk\Config; use OCA\Talk\Model\Attendee; use OCA\Talk\Model\BreakoutRoom; +use OCA\Talk\Model\ProxyCacheMessagesMapper; use OCA\Talk\Model\Session; use OCA\Talk\Participant; use OCA\Talk\ResponseDefinitions; use OCA\Talk\Room; use OCA\Talk\Webinary; use OCP\App\IAppManager; +use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Utility\ITimeFactory; use OCP\Comments\IComment; use OCP\IConfig; @@ -46,7 +48,7 @@ use OCP\UserStatus\IUserStatus; /** - * @psalm-import-type TalkChatMessage from ResponseDefinitions + * @psalm-import-type TalkRoomLastMessage from ResponseDefinitions * @psalm-import-type TalkRoom from ResponseDefinitions */ class RoomFormatter { @@ -61,6 +63,7 @@ public function __construct( protected IAppManager $appManager, protected IManager $userStatusManager, protected IUserManager $userManager, + protected ProxyCacheMessagesMapper $proxyCacheMessagesMapper, protected IL10N $l10n, protected ?string $userId, ) { @@ -374,6 +377,7 @@ public function formatRoomV4( } } + $roomData['lastMessage'] = []; $lastMessage = $room->getLastMessage(); if ($room->getRemoteServer() === '' && $lastMessage instanceof IComment) { $roomData['lastMessage'] = $this->formatLastMessage( @@ -382,15 +386,23 @@ public function formatRoomV4( $currentParticipant, $lastMessage, ); - } else { - $roomData['lastMessage'] = []; + } elseif ($room->getRemoteServer() !== '') { + try { + $cachedMessage = $this->proxyCacheMessagesMapper->findByRemote( + $room->getRemoteServer(), + $room->getRemoteToken(), + $room->getLastMessageId(), + ); + $roomData['lastMessage'] = $cachedMessage->jsonSerialize(); + } catch (DoesNotExistException $e) { + } } return $roomData; } /** - * @return TalkChatMessage|array + * @return TalkRoomLastMessage|array */ public function formatLastMessage( string $responseFormat, diff --git a/openapi-backend-sipbridge.json b/openapi-backend-sipbridge.json index 4c8c76ae3e18..04f1ce51023f 100644 --- a/openapi-backend-sipbridge.json +++ b/openapi-backend-sipbridge.json @@ -478,7 +478,7 @@ "lastMessage": { "oneOf": [ { - "$ref": "#/components/schemas/ChatMessage" + "$ref": "#/components/schemas/RoomLastMessage" }, { "type": "array", @@ -588,6 +588,62 @@ "format": "int64" } } + }, + "RoomLastMessage": { + "oneOf": [ + { + "$ref": "#/components/schemas/ChatMessage" + }, + { + "$ref": "#/components/schemas/RoomProxyMessage" + } + ] + }, + "RoomProxyMessage": { + "type": "object", + "required": [ + "actorDisplayName", + "actorId", + "actorType", + "expirationTimestamp", + "message", + "messageParameters", + "messageType", + "systemMessage" + ], + "properties": { + "actorDisplayName": { + "type": "string" + }, + "actorId": { + "type": "string" + }, + "actorType": { + "type": "string" + }, + "expirationTimestamp": { + "type": "integer", + "format": "int64" + }, + "message": { + "type": "string" + }, + "messageParameters": { + "type": "object", + "additionalProperties": { + "type": "object", + "additionalProperties": { + "type": "object" + } + } + }, + "messageType": { + "type": "string" + }, + "systemMessage": { + "type": "string" + } + } } } }, diff --git a/openapi-federation.json b/openapi-federation.json index b4e024dedd89..94f1cc13e13d 100644 --- a/openapi-federation.json +++ b/openapi-federation.json @@ -537,7 +537,7 @@ "lastMessage": { "oneOf": [ { - "$ref": "#/components/schemas/ChatMessage" + "$ref": "#/components/schemas/RoomLastMessage" }, { "type": "array", @@ -647,6 +647,62 @@ "format": "int64" } } + }, + "RoomLastMessage": { + "oneOf": [ + { + "$ref": "#/components/schemas/ChatMessage" + }, + { + "$ref": "#/components/schemas/RoomProxyMessage" + } + ] + }, + "RoomProxyMessage": { + "type": "object", + "required": [ + "actorDisplayName", + "actorId", + "actorType", + "expirationTimestamp", + "message", + "messageParameters", + "messageType", + "systemMessage" + ], + "properties": { + "actorDisplayName": { + "type": "string" + }, + "actorId": { + "type": "string" + }, + "actorType": { + "type": "string" + }, + "expirationTimestamp": { + "type": "integer", + "format": "int64" + }, + "message": { + "type": "string" + }, + "messageParameters": { + "type": "object", + "additionalProperties": { + "type": "object", + "additionalProperties": { + "type": "object" + } + } + }, + "messageType": { + "type": "string" + }, + "systemMessage": { + "type": "string" + } + } } } }, diff --git a/openapi-full.json b/openapi-full.json index b4872e55df48..79512b6a4e85 100644 --- a/openapi-full.json +++ b/openapi-full.json @@ -1002,7 +1002,7 @@ "lastMessage": { "oneOf": [ { - "$ref": "#/components/schemas/ChatMessage" + "$ref": "#/components/schemas/RoomLastMessage" }, { "type": "array", @@ -1113,6 +1113,62 @@ } } }, + "RoomLastMessage": { + "oneOf": [ + { + "$ref": "#/components/schemas/ChatMessage" + }, + { + "$ref": "#/components/schemas/RoomProxyMessage" + } + ] + }, + "RoomProxyMessage": { + "type": "object", + "required": [ + "actorDisplayName", + "actorId", + "actorType", + "expirationTimestamp", + "message", + "messageParameters", + "messageType", + "systemMessage" + ], + "properties": { + "actorDisplayName": { + "type": "string" + }, + "actorId": { + "type": "string" + }, + "actorType": { + "type": "string" + }, + "expirationTimestamp": { + "type": "integer", + "format": "int64" + }, + "message": { + "type": "string" + }, + "messageParameters": { + "type": "object", + "additionalProperties": { + "type": "object", + "additionalProperties": { + "type": "object" + } + } + }, + "messageType": { + "type": "string" + }, + "systemMessage": { + "type": "string" + } + } + }, "SignalingSession": { "type": "object", "required": [ diff --git a/openapi.json b/openapi.json index 162d93a8f9aa..93b882007eb2 100644 --- a/openapi.json +++ b/openapi.json @@ -884,7 +884,7 @@ "lastMessage": { "oneOf": [ { - "$ref": "#/components/schemas/ChatMessage" + "$ref": "#/components/schemas/RoomLastMessage" }, { "type": "array", @@ -995,6 +995,62 @@ } } }, + "RoomLastMessage": { + "oneOf": [ + { + "$ref": "#/components/schemas/ChatMessage" + }, + { + "$ref": "#/components/schemas/RoomProxyMessage" + } + ] + }, + "RoomProxyMessage": { + "type": "object", + "required": [ + "actorDisplayName", + "actorId", + "actorType", + "expirationTimestamp", + "message", + "messageParameters", + "messageType", + "systemMessage" + ], + "properties": { + "actorDisplayName": { + "type": "string" + }, + "actorId": { + "type": "string" + }, + "actorType": { + "type": "string" + }, + "expirationTimestamp": { + "type": "integer", + "format": "int64" + }, + "message": { + "type": "string" + }, + "messageParameters": { + "type": "object", + "additionalProperties": { + "type": "object", + "additionalProperties": { + "type": "object" + } + } + }, + "messageType": { + "type": "string" + }, + "systemMessage": { + "type": "string" + } + } + }, "SignalingSession": { "type": "object", "required": [