Skip to content

Commit

Permalink
Merge pull request #9830 from nextcloud/feat/9679/api-for-threads
Browse files Browse the repository at this point in the history
feat(chat): Expose the "top most parent" ID as thread ID
  • Loading branch information
nickvergessen authored Jun 26, 2023
2 parents cb5e214 + 5af43cd commit ca29fbb
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 94 deletions.
3 changes: 3 additions & 0 deletions docs/capabilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,6 @@
* `config => call => supported-reactions` - A list of emojis supported as call reactions. If the list is absent or empty, clients should not show the emoji reaction option in calls.
* `config => chat => typing-privacy` - User defined numeric value to enable 1 or disable 0 the typing indicator to other users
* `typing-privacy` - Support toggle typing privacy

## 18
* `threads` - Chat messages have a thread ID exposed which allows clients to only list chat messages of a dedicated messages stream
37 changes: 19 additions & 18 deletions docs/chat.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,25 @@ Base endpoint is: `/ocs/v2.php/apps/spreed/api/v1`: since Nextcloud 13
- Data:
Array of messages, each message has at least:

| field | type | Description |
|------------------------|----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `id` | int | ID of the comment |
| `token` | string | Conversation token |
| `actorType` | string | See [Constants - Actor types of chat messages](constants.md#actor-types-of-chat-messages) |
| `actorId` | string | Actor id of the message author |
| `actorDisplayName` | string | Display name of the message author |
| `timestamp` | int | Timestamp in seconds and UTC time zone |
| `systemMessage` | string | empty for normal chat message or the type of the system message (untranslated) |
| `messageType` | string | Currently known types are `comment`, `comment_deleted`, `system` and `command` |
| `isReplyable` | bool | True if the user can post a reply to this message (only available with `chat-replies` capability) |
| `referenceId` | string | A reference string that was given while posting the message to be able to identify a sent message again (only available with `chat-reference-id` capability) |
| `message` | string | Message string with placeholders (see [Rich Object String](https://github.com/nextcloud/server/issues/1706)) |
| `messageParameters` | array | Message parameters for `message` (see [Rich Object String](https://github.com/nextcloud/server/issues/1706)) |
| `expirationTimestamp` | int | Unix time stamp when the message expires and show be removed from the clients UI without further note or warning (only available with `message-expiration` capability) |
| `parent` | array | **Optional:** See `Parent data` below |
| `reactions` | int[] | **Optional:** An array map with relation between reaction emoji and total count of reactions with this emoji |
| `reactionsSelf` | string[] | **Optional:** When the user reacted this is the list of emojis the user reacted with |
| field | type | Description |
|-----------------------|----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `id` | int | ID of the comment |
| `threadId` | int | ID of the top most parent comment, indicating the thread of this message (`0` for the messages without a parent) (only available with `threads` capability) |
| `token` | string | Conversation token |
| `actorType` | string | See [Constants - Actor types of chat messages](constants.md#actor-types-of-chat-messages) |
| `actorId` | string | Actor id of the message author |
| `actorDisplayName` | string | Display name of the message author |
| `timestamp` | int | Timestamp in seconds and UTC time zone |
| `systemMessage` | string | empty for normal chat message or the type of the system message (untranslated) |
| `messageType` | string | Currently known types are `comment`, `comment_deleted`, `system` and `command` |
| `isReplyable` | bool | True if the user can post a reply to this message (only available with `chat-replies` capability) |
| `referenceId` | string | A reference string that was given while posting the message to be able to identify a sent message again (only available with `chat-reference-id` capability) |
| `message` | string | Message string with placeholders (see [Rich Object String](https://github.com/nextcloud/server/issues/1706)) |
| `messageParameters` | array | Message parameters for `message` (see [Rich Object String](https://github.com/nextcloud/server/issues/1706)) |
| `expirationTimestamp` | int | Unix time stamp when the message expires and show be removed from the clients UI without further note or warning (only available with `message-expiration` capability) |
| `parent` | array | **Optional:** See `Parent data` below |
| `reactions` | int[] | **Optional:** An array map with relation between reaction emoji and total count of reactions with this emoji |
| `reactionsSelf` | string[] | **Optional:** When the user reacted this is the list of emojis the user reacted with |

#### Parent data

Expand Down
1 change: 1 addition & 0 deletions lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public function getCapabilities(): array {
'single-conversation-status',
'chat-keep-notifications',
'typing-privacy',
// FIXME Publish once the API is approved by the clients 'threads',
],
'config' => [
'attachments' => [
Expand Down
1 change: 1 addition & 0 deletions lib/Model/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public function toArray(string $format): array {

$data = [
'id' => (int) $this->getComment()->getId(),
'threadId' => (int) $this->getComment()->getTopmostParentId(),
'token' => $this->getRoom()->getToken(),
'actorType' => $this->getActorType(),
'actorId' => $this->getActorId(),
Expand Down
10 changes: 9 additions & 1 deletion tests/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -2233,6 +2233,7 @@ protected function compareDataResponse(TableNode $formData = null) {
$includeReferenceId = in_array('referenceId', $formData->getRow(0), true);
$includeReactions = in_array('reactions', $formData->getRow(0), true);
$includeReactionsSelf = in_array('reactionsSelf', $formData->getRow(0), true);
$includeThreadId = in_array('threadId', $formData->getRow(0), true);

$expected = $formData->getHash();
$count = count($expected);
Expand All @@ -2242,6 +2243,10 @@ protected function compareDataResponse(TableNode $formData = null) {
$messages[$i]['messageParameters'] = 'IGNORE';
}

if ($includeThreadId && !is_numeric($expected[$i]['threadId'])) {
$expected[$i]['threadId'] = self::$textToMessageId[$expected[$i]['threadId']];
}

$result = preg_match('/POLL_ID\(([^)]+)\)/', $expected[$i]['messageParameters'], $matches);
if ($result) {
$expected[$i]['messageParameters'] = str_replace($matches[0], '"' . self::$questionToPollId[$matches[1]] . '"', $expected[$i]['messageParameters']);
Expand All @@ -2255,7 +2260,7 @@ protected function compareDataResponse(TableNode $formData = null) {
}
}

Assert::assertEquals($expected, array_map(function ($message) use ($includeParents, $includeReferenceId, $includeReactions, $includeReactionsSelf) {
Assert::assertEquals($expected, array_map(function ($message) use ($includeParents, $includeReferenceId, $includeReactions, $includeReactionsSelf, $includeThreadId) {
$data = [
'room' => self::$tokenToIdentifier[$message['token']],
'actorType' => $message['actorType'],
Expand All @@ -2282,6 +2287,9 @@ protected function compareDataResponse(TableNode $formData = null) {
$data['reactionsSelf'] = null;
}
}
if ($includeThreadId) {
$data['threadId'] = $message['threadId'];
}
return $data;
}, $messages));
}
Expand Down
Loading

0 comments on commit ca29fbb

Please sign in to comment.