Skip to content

Commit

Permalink
feat(federation): Expose the info to show the subline for proxy convos
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Feb 28, 2024
1 parent 4303d47 commit 96baf85
Show file tree
Hide file tree
Showing 7 changed files with 285 additions and 12 deletions.
30 changes: 27 additions & 3 deletions lib/Model/ProxyCacheMessages.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

namespace OCA\Talk\Model;

use OCA\Talk\ResponseDefinitions;
use OCP\AppFramework\Db\Entity;

/**
Expand All @@ -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 = '';
Expand Down Expand Up @@ -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),
];
}
}
15 changes: 14 additions & 1 deletion lib/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@
* silent?: bool,
* }
*
* @psalm-type TalkRoomProxyMessage = array{
* actorDisplayName: string,
* actorId: string,
* actorType: string,
* expirationTimestamp: int,
* message: string,
* messageParameters: array<string, array<string, mixed>>,
* messageType: string,
* systemMessage: string,
* }
*
* @psalm-type TalkRoomLastMessage = TalkChatMessage|TalkRoomProxyMessage
*
* @psalm-type TalkChatMessageWithParent = TalkChatMessage&array{parent?: TalkChatMessage}
*
* @psalm-type TalkChatReminder = array{
Expand Down Expand Up @@ -208,7 +221,7 @@
* isFavorite: bool,
* lastActivity: int,
* lastCommonReadMessage: int,
* lastMessage: TalkChatMessage|array<empty>,
* lastMessage: TalkRoomLastMessage|array<empty>,
* lastPing: int,
* lastReadMessage: int,
* listable: int,
Expand Down
20 changes: 16 additions & 4 deletions lib/Service/RoomFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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,
) {
Expand Down Expand Up @@ -374,6 +377,7 @@ public function formatRoomV4(
}
}

$roomData['lastMessage'] = [];
$lastMessage = $room->getLastMessage();
if ($room->getRemoteServer() === '' && $lastMessage instanceof IComment) {
$roomData['lastMessage'] = $this->formatLastMessage(
Expand All @@ -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<empty>
* @return TalkRoomLastMessage|array<empty>
*/
public function formatLastMessage(
string $responseFormat,
Expand Down
58 changes: 57 additions & 1 deletion openapi-backend-sipbridge.json
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@
"lastMessage": {
"oneOf": [
{
"$ref": "#/components/schemas/ChatMessage"
"$ref": "#/components/schemas/RoomLastMessage"
},
{
"type": "array",
Expand Down Expand Up @@ -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"
}
}
}
}
},
Expand Down
58 changes: 57 additions & 1 deletion openapi-federation.json
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@
"lastMessage": {
"oneOf": [
{
"$ref": "#/components/schemas/ChatMessage"
"$ref": "#/components/schemas/RoomLastMessage"
},
{
"type": "array",
Expand Down Expand Up @@ -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"
}
}
}
}
},
Expand Down
58 changes: 57 additions & 1 deletion openapi-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@
"lastMessage": {
"oneOf": [
{
"$ref": "#/components/schemas/ChatMessage"
"$ref": "#/components/schemas/RoomLastMessage"
},
{
"type": "array",
Expand Down Expand Up @@ -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": [
Expand Down
Loading

0 comments on commit 96baf85

Please sign in to comment.