Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable30] feat: NoteToSelf messages are editable forever #13083

Merged
merged 2 commits into from
Aug 22, 2024
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
1 change: 1 addition & 0 deletions docs/capabilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,4 @@
* `ban-v1` - Whether the API to ban attendees is available
* `mention-permissions` - Whether non-moderators are allowed to mention `@all`
* `federation-v2` - Whether federated session ids are used and calls are possible with federation
* `edit-messages-note-to-self` - Messages in note-to-self conversations can be edited indefinitely
1 change: 1 addition & 0 deletions lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class Capabilities implements IPublicCapability {
'ban-v1',
'chat-reference-id',
'mention-permissions',
'edit-messages-note-to-self',
];

public const LOCAL_FEATURES = [
Expand Down
13 changes: 7 additions & 6 deletions lib/Controller/ChatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -845,13 +845,14 @@ public function editMessage(int $messageId, string $message): DataResponse {
return new DataResponse([], Http::STATUS_METHOD_NOT_ALLOWED);
}

$maxAge = $this->timeFactory->getDateTime();
$maxAge->sub(new \DateInterval('P1D'));
if ($comment->getCreationDateTime() < $maxAge) {
// Message is too old
return new DataResponse(['error' => 'age'], Http::STATUS_BAD_REQUEST);
if ($this->room->getType() !== Room::TYPE_NOTE_TO_SELF) {
$maxAge = $this->timeFactory->getDateTime();
$maxAge->sub(new \DateInterval('P1D'));
if ($comment->getCreationDateTime() < $maxAge) {
// Message is too old
return new DataResponse(['error' => 'age'], Http::STATUS_BAD_REQUEST);
}
}

try {
$systemMessageComment = $this->chatManager->editMessage(
$this->room,
Expand Down
16 changes: 16 additions & 0 deletions tests/integration/features/chat-1/note-to-self.feature
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,19 @@ Feature: chat/note-to-self
Then user "participant1" sees the following system messages in room "Note to self" with 200
| room | actorType | actorId | actorDisplayName | message | messageParameters | systemMessage |
| Note to self | guests | system | | System created the conversation | {"actor":{"type":"guest","id":"guest\/system","name":"Guest"}} | conversation_created |

Scenario: Edit messages forever in note-to-self room
When user "participant1" creates note-to-self (v4)
And user "participant1" is participant of the following note-to-self rooms (v4)
| id | type | name |
| participant1-note-to-self | 6 | Note to self |
Then user "participant1" sends message "Initial message" to room "participant1-note-to-self" with 201
And user "participant1" sees the following messages in room "participant1-note-to-self" with 200
| room | actorType | actorId | actorDisplayName | message | messageParameters |
| participant1-note-to-self | users | participant1 | participant1-displayname | Initial message | [] |
When aging messages 24 hours in room "participant1-note-to-self"
And user "participant1" edits message "Initial message" in room "participant1-note-to-self" to "Edited after 24 hours" with 200
Then user "participant1" sees the following messages in room "participant1-note-to-self" with 200
| room | actorType | actorId | actorDisplayName | message | messageParameters | lastEditActorType | lastEditActorId | lastEditActorDisplayName |
| participant1-note-to-self | users | participant1 | participant1-displayname | Edited after 24 hours | [] | users | participant1 | participant1-displayname |

Loading