Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/Chat/ChatManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -645,12 +645,21 @@ public function deleteMessage(Room $chat, IComment $comment, Participant $partic

$this->commentsManager->save($comment);

$this->attachmentService->deleteAttachmentByMessageId((int)$comment->getId());
$messageId = (int)$comment->getId();
$this->attachmentService->deleteAttachmentByMessageId($messageId);

$this->referenceManager->invalidateCache($chat->getToken());

$this->unreadCountCache->clear($chat->getId() . '-');

if ($chat->getLastPinnedId() === $messageId) {
$pinnedMessages = $this->attachmentService->getAttachmentsByType($chat, Attachment::TYPE_PINNED, 0, 1);
if (!empty($pinnedMessages)) {
$pinnedMessage = array_shift($pinnedMessages);
$this->roomService->setLastPinnedId($chat, $pinnedMessage->getMessageId());
}
}

return $this->addSystemMessage(
$chat,
$participant,
Expand Down
17 changes: 17 additions & 0 deletions tests/integration/features/chat-1/pinned-messages.feature
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,20 @@ Feature: chat-1/pinned-messages
Then user "participant2" is participant of the following rooms (v4)
| id | type | lastPinnedId | hiddenPinnedId |
| room | 3 | EMPTY | EMPTY |

Scenario: Deleting last pinned message
Given user "participant1" creates room "room" (v4)
| roomType | 3 |
| roomName | room |
And user "participant1" adds user "participant2" to room "room" with 200 (v4)
When user "participant1" sends message "Message 1" to room "room" with 201
When user "participant1" pins message "Message 1" in room "room" with 200
When user "participant1" sends message "Message 2" to room "room" with 201
When user "participant1" pins message "Message 2" in room "room" with 200
Then user "participant2" is participant of the following rooms (v4)
| id | type | lastPinnedId | hiddenPinnedId |
| room | 3 | Message 2 | EMPTY |
When user "participant1" deletes message "Message 2" from room "room" with 200
Then user "participant2" is participant of the following rooms (v4)
| id | type | lastPinnedId | hiddenPinnedId |
| room | 3 | Message 1 | EMPTY |
Loading