Skip to content

Commit

Permalink
fix(archive): Improve archive preference handling
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Sep 26, 2024
1 parent f67e2ff commit eac8129
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 6 deletions.
3 changes: 3 additions & 0 deletions lib/Controller/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,9 @@ public function setPassword(string $password): DataResponse {
/**
* Archive a conversation
*
* - Turns off call notifications
* - Reduces chat notifications in group and public rooms when it was "default" resulting in "always"
*
* @return DataResponse<Http::STATUS_OK, TalkRoom, array{}>
*
* 200: Conversation was archived
Expand Down
26 changes: 22 additions & 4 deletions lib/Service/ParticipantService.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,18 +299,36 @@ public function updateNotificationCalls(Participant $participant, int $level): v
}

/**
* @param Participant $participant
* @return Participant::NOTIFY_*
*/
protected function getDefaultGroupNotification(): int {
$config = (int)$this->serverConfig->getAppValue('spreed', 'default_group_notification', (string)Participant::NOTIFY_MENTION);
return max(Participant::NOTIFY_DEFAULT, min($config, Participant::NOTIFY_NEVER));
}

public function archiveConversation(Participant $participant): void {
$attendee = $participant->getAttendee();
$attendee->setArchived(true);
$attendee->setLastAttendeeActivity($this->timeFactory->getTime());

$room = $participant->getRoom();
if ($room->getType() === Room::TYPE_PUBLIC || $room->getType() === Room::TYPE_GROUP) {
// Turn of call notifications by default
if ($attendee->getNotificationCalls() === Participant::NOTIFY_CALLS_ON) {
$attendee->setNotificationCalls(Participant::NOTIFY_CALLS_OFF);
}

// Reduce notifications when it was "Always" via the default
// Otherwise we respect the attendees selection
if ($attendee->getNotificationLevel() === Participant::NOTIFY_DEFAULT
&& $this->getDefaultGroupNotification() !== Participant::NOTIFY_NEVER) {
$attendee->setNotificationCalls(Participant::NOTIFY_MENTION);
}
}

$this->attendeeMapper->update($attendee);
}

/**
* @param Participant $participant
*/
public function unarchiveConversation(Participant $participant): void {
$attendee = $participant->getAttendee();
$attendee->setArchived(false);
Expand Down
1 change: 1 addition & 0 deletions openapi-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -15814,6 +15814,7 @@
"post": {
"operationId": "room-archive-conversation",
"summary": "Archive a conversation",
"description": "- Turns off call notifications - Reduces chat notifications in group and public rooms when it was \"default\" resulting in \"always\"",
"tags": [
"room"
],
Expand Down
1 change: 1 addition & 0 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -15948,6 +15948,7 @@
"post": {
"operationId": "room-archive-conversation",
"summary": "Archive a conversation",
"description": "- Turns off call notifications - Reduces chat notifications in group and public rooms when it was \"default\" resulting in \"always\"",
"tags": [
"room"
],
Expand Down
5 changes: 4 additions & 1 deletion src/types/openapi/openapi-full.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,10 @@ export type paths = {
};
get?: never;
put?: never;
/** Archive a conversation */
/**
* Archive a conversation
* @description - Turns off call notifications - Reduces chat notifications in group and public rooms when it was "default" resulting in "always"
*/
post: operations["room-archive-conversation"];
/** Unarchive a conversation */
delete: operations["room-unarchive-conversation"];
Expand Down
5 changes: 4 additions & 1 deletion src/types/openapi/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,10 @@ export type paths = {
};
get?: never;
put?: never;
/** Archive a conversation */
/**
* Archive a conversation
* @description - Turns off call notifications - Reduces chat notifications in group and public rooms when it was "default" resulting in "always"
*/
post: operations["room-archive-conversation"];
/** Unarchive a conversation */
delete: operations["room-unarchive-conversation"];
Expand Down

0 comments on commit eac8129

Please sign in to comment.