Skip to content

Commit

Permalink
Merge pull request #10826 from nextcloud/feat/10825/silent-attachments
Browse files Browse the repository at this point in the history
feat(attachments): Allow sending captions as silent messages
  • Loading branch information
nickvergessen authored Nov 2, 2023
2 parents 58910ae + a3c6021 commit 2974fc6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
9 changes: 5 additions & 4 deletions docs/chat.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,11 @@ See [OCP\RichObjectStrings\Definitions](https://github.com/nextcloud/server/blob

- `talkMetaData` array:

| field | type | Description |
|---------------|--------|-----------------------------------------------------------------------------------------------------------------------|
| `messageType` | string | A message type to show the message in different styles. Currently known: `voice-message` and `comment` |
| `caption` | string | A caption message that should be shown together with the shared file (only available with `media-caption` capability) |
| field | type | Description |
|---------------|--------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `messageType` | string | A message type to show the message in different styles. Currently known: `voice-message` and `comment` |
| `caption` | string | A caption message that should be shown together with the shared file (only available with `media-caption` capability) |
| `silent` | bool | If sent silent the message will not create chat notifications even for mentions (only available with `media-caption` capability, yes `media-caption` not `silent-send`) |

* Response: [See official OCS Share API docs](https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/ocs-share-api.html?highlight=sharing#create-a-new-share)

Expand Down
11 changes: 6 additions & 5 deletions lib/Chat/ChatManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ public function addSystemMessage(
bool $sendNotifications,
?string $referenceId = null,
?int $parentId = null,
bool $shouldSkipLastMessageUpdate = false
bool $shouldSkipLastMessageUpdate = false,
bool $silent = false,
): IComment {
$comment = $this->commentsManager->create($actorType, $actorId, 'chat', (string) $chat->getId());
$comment->setMessage($message, self::MAX_CHAT_LENGTH);
Expand All @@ -167,9 +168,9 @@ public function addSystemMessage(

$this->setMessageExpiration($chat, $comment);

$event = new BeforeSystemMessageSentEvent($chat, $comment, skipLastActivityUpdate: $shouldSkipLastMessageUpdate);
$event = new BeforeSystemMessageSentEvent($chat, $comment, silent: $silent, skipLastActivityUpdate: $shouldSkipLastMessageUpdate);
$this->dispatcher->dispatchTyped($event);
$event = new ChatEvent($chat, $comment, $shouldSkipLastMessageUpdate);
$event = new ChatEvent($chat, $comment, $shouldSkipLastMessageUpdate, $silent);
$this->dispatcher->dispatch(self::EVENT_BEFORE_SYSTEM_MESSAGE_SEND, $event);
try {
$this->commentsManager->save($comment);
Expand All @@ -181,7 +182,7 @@ public function addSystemMessage(
}

if ($sendNotifications) {
$this->notifier->notifyOtherParticipant($chat, $comment, [], false);
$this->notifier->notifyOtherParticipant($chat, $comment, [], $silent);
}

if (!$shouldSkipLastMessageUpdate && $sendNotifications) {
Expand All @@ -196,7 +197,7 @@ public function addSystemMessage(
}

$this->dispatcher->dispatch(self::EVENT_AFTER_SYSTEM_MESSAGE_SEND, $event);
$event = new SystemMessageSentEvent($chat, $comment, skipLastActivityUpdate: $shouldSkipLastMessageUpdate);
$event = new SystemMessageSentEvent($chat, $comment, silent: $silent, skipLastActivityUpdate: $shouldSkipLastMessageUpdate);
$this->dispatcher->dispatchTyped($event);
} catch (NotFoundException $e) {
}
Expand Down
13 changes: 10 additions & 3 deletions lib/Chat/SystemMessage/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,13 @@ protected function fixMimeTypeOfVoiceMessage(ShareCreatedEvent|BeforeDuplicateSh
}
}

$this->sendSystemMessage($room, 'file_shared', ['share' => $share->getId(), 'metaData' => $metaData]);
if (isset($metaData['silent'])) {
$silent = (bool) $metaData['silent'];
} else {
$silent = false;
}

$this->sendSystemMessage($room, 'file_shared', ['share' => $share->getId(), 'metaData' => $metaData], silent: $silent);
}

protected function attendeesAddedEvent(AttendeesAddedEvent $event): void {
Expand Down Expand Up @@ -401,7 +407,7 @@ protected function attendeesRemovedEvent(AttendeesRemovedEvent $event): void {
}
}

protected function sendSystemMessage(Room $room, string $message, array $parameters = [], Participant $participant = null, bool $shouldSkipLastMessageUpdate = false): IComment {
protected function sendSystemMessage(Room $room, string $message, array $parameters = [], Participant $participant = null, bool $shouldSkipLastMessageUpdate = false, bool $silent = false): IComment {
if ($participant instanceof Participant) {
$actorType = $participant->getAttendee()->getActorType();
$actorId = $participant->getAttendee()->getActorId();
Expand Down Expand Up @@ -439,7 +445,8 @@ protected function sendSystemMessage(Room $room, string $message, array $paramet
$this->timeFactory->getDateTime(), $message === 'file_shared',
$referenceId,
null,
$shouldSkipLastMessageUpdate
$shouldSkipLastMessageUpdate,
$silent,
);
}

Expand Down
2 changes: 2 additions & 0 deletions tests/php/Chat/SystemMessage/ListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ public function testAfterUsersAdd(int $roomType, string $objectType, array $part
self::DUMMY_REFERENCE_ID,
null,
false,
false,
];
}
if (!empty($consecutive)) {
Expand Down Expand Up @@ -334,6 +335,7 @@ public function testAfterParticipantTypeSet(string $actorType, int $oldParticipa
self::DUMMY_REFERENCE_ID,
null,
false,
false,
];
}
if (isset($consecutive)) {
Expand Down

0 comments on commit 2974fc6

Please sign in to comment.