Skip to content

Commit 164d7db

Browse files
committed
fixup! feat: Mute conversations
1 parent fd2dc3f commit 164d7db

21 files changed

Lines changed: 150 additions & 44 deletions

docs/capabilities.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,4 @@
226226
* `config => conversations => group-mode` (local) - User selected grouping mode for conversations (`none`, `group-first` or `private-first`)
227227
* `private-reply` - Whether clients can link the original message to a private reply in one-to-one conversations
228228
* `config => attachments => conversation-subfolders` (local) - Whether per-conversation subfolders are used for Talk attachments; when `true` files must be uploaded to `Talk/<ConversationName>-<token>/<DisplayName>-<uid>/` before calling the attachment endpoint
229-
* `mute-conversations` - Wether conversations can be muted for given time.
229+
* `mute-conversations` - Whether conversations can be muted for a given time

lib/Chat/Notifier.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ protected function shouldMentionedUserBeNotified(string $userId, IComment $comme
692692
return self::PRIORITY_NONE;
693693
}
694694

695-
if ($attendee->getMuteUntil() >= $this->timeFactory->getDateTime()) {
695+
if ($attendee->getMuteUntil() >= $this->timeFactory->getDateTime()->getTimestamp()) {
696696
return self::PRIORITY_NONE;
697697
}
698698

@@ -772,7 +772,7 @@ protected function shouldParticipantBeNotified(Participant $participant, ICommen
772772
return self::PRIORITY_NONE;
773773
}
774774

775-
if ($participant->getAttendee()->getMuteUntil() >= $this->timeFactory->getDateTime()) {
775+
if ($participant->getAttendee()->getMuteUntil() >= $this->timeFactory->getDateTime()->getTimestamp()) {
776776
return self::PRIORITY_NONE;
777777
}
778778

lib/Controller/RoomController.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3246,9 +3246,10 @@ public function scheduleMeeting(string $calendarUri, int $start, ?array $attende
32463246
* Required capability: `mute-conversations`
32473247
*
32483248
* @param int $muteUntil Unix timestamp until notifications are muted
3249-
* @return DataResponse<Http::STATUS_OK, TalkRoom, array{}>
3249+
* @return DataResponse<Http::STATUS_OK, TalkRoom, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, array{error: 'mute-until'}, array{}>
32503250
*
32513251
* 200: Conversation muted
3252+
* 400: Timestamp is in the past
32523253
*/
32533254
#[NoAdminRequired]
32543255
#[FederationSupported]
@@ -3258,10 +3259,11 @@ public function scheduleMeeting(string $calendarUri, int $start, ?array $attende
32583259
'token' => '[a-z0-9]{4,30}',
32593260
])]
32603261
public function muteConversation(int $muteUntil): DataResponse {
3261-
$muteUntilDateTime = $this->timeFactory->getDateTime('@' . $muteUntil);
3262-
$muteUntilDateTime->setTimezone(new \DateTimeZone('UTC'));
3262+
if ($muteUntil <= $this->timeFactory->getDateTime()->getTimestamp()) {
3263+
return new DataResponse(['error' => 'mute-until'], Http::STATUS_BAD_REQUEST);
3264+
}
32633265

3264-
$this->participantService->setMuteUntil($this->participant, $muteUntilDateTime);
3266+
$this->participantService->setMuteUntil($this->participant, $muteUntil);
32653267
return new DataResponse($this->formatRoom($this->room, $this->participant));
32663268
}
32673269

@@ -3283,10 +3285,7 @@ public function muteConversation(int $muteUntil): DataResponse {
32833285
'token' => '[a-z0-9]{4,30}',
32843286
])]
32853287
public function unmuteConversation(): DataResponse {
3286-
$muteUntilDateTime = new \DateTime();
3287-
$muteUntilDateTime->setTimestamp(0);
3288-
3289-
$this->participantService->setMuteUntil($this->participant, $muteUntilDateTime);
3288+
$this->participantService->setMuteUntil($this->participant, 0);
32903289
return new DataResponse($this->formatRoom($this->room, $this->participant));
32913290
}
32923291
}

lib/Migration/Version24000Date20260419190830.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
3131

3232
$table = $schema->getTable('talk_attendees');
3333
if (!$table->hasColumn('mute_until')) {
34-
$table->addColumn('mute_until', Types::DATETIME, [
34+
$table->addColumn('mute_until', Types::INTEGER, [
3535
'notnull' => true,
36+
'length' => 11,
37+
'default' => 0,
3638
]);
3739
}
3840

lib/Model/Attendee.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@
7474
* @method int getHiddenPinnedId()
7575
* @method void setHasScheduledMessages(int $scheduledMessages)
7676
* @method int getHasScheduledMessages()
77-
* @method void setMuteUntil(\DateTime $muteUntil)
78-
* @method \DateTime getMuteUntil()
77+
* @method void setMuteUntil(int $muteUntil)
78+
* @method int getMuteUntil()
7979
*/
8080
class Attendee extends Entity {
8181
public const ACTOR_USERS = 'users';
@@ -152,13 +152,9 @@ class Attendee extends Entity {
152152
protected bool $hasUnreadThreadDirects = false;
153153
protected int $hiddenPinnedId = 0;
154154
protected int $hasScheduledMessages = 0;
155-
protected \DateTime $muteUntil;
155+
protected int $muteUntil = 0;
156156

157157
public function __construct() {
158-
$muteUntilDateTime = new \DateTime();
159-
$muteUntilDateTime->setTimestamp(0);
160-
$this->muteUntil = $muteUntilDateTime;
161-
162158
$this->addType('roomId', Types::BIGINT);
163159
$this->addType('actorType', Types::STRING);
164160
$this->addType('actorId', Types::STRING);
@@ -190,7 +186,7 @@ public function __construct() {
190186
$this->addType('hasUnreadThreadDirects', Types::BOOLEAN);
191187
$this->addType('hiddenPinnedId', Types::BIGINT);
192188
$this->addType('hasScheduledMessages', Types::INTEGER);
193-
$this->addType('muteUntil', Types::DATETIME);
189+
$this->addType('muteUntil', Types::INTEGER);
194190
}
195191

196192
public function getDisplayName(): string {

lib/Model/AttendeeMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ public function createAttendeeFromRow(array $row): Attendee {
316316
'has_unread_thread_directs' => (bool)$row['has_unread_thread_directs'],
317317
'hidden_pinned_id' => (int)$row['hidden_pinned_id'],
318318
'has_scheduled_messages' => (int)$row['has_scheduled_messages'],
319-
'mute_until' => new \DateTime($row['mute_until']),
319+
'mute_until' => (int)$row['mute_until'],
320320
]);
321321
}
322322
}

lib/ResponseDefinitions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@
570570
* hasScheduledMessages: int,
571571
* // Bit-flag of enabled attributes of this conversation (only available with capability: `conversation-attributes`). See [attributes list](https://nextcloud-talk.readthedocs.io/en/latest/constants/#conversation-attributes) for details
572572
* attributes: int,
573-
* // Required capability: `mute-conversations`
573+
* // Required capability: `mute-conversations`. Timestamp until the conversation is muted, i.e. not receiving notifications
574574
* muteUntil: int,
575575
* }
576576
*

lib/Service/ParticipantService.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ public function hidePinnedMessage(Participant $participant, int $messagesId): vo
382382
$this->attendeeMapper->update($attendee);
383383
}
384384

385-
public function setMuteUntil(Participant $participant, \DateTime $muteUntil): void {
385+
public function setMuteUntil(Participant $participant, int $muteUntil): void {
386386
$attendee = $participant->getAttendee();
387387
$attendee->setMuteUntil($muteUntil);
388388
$attendee->setLastAttendeeActivity($this->timeFactory->getTime());
@@ -519,7 +519,6 @@ public function joinRoomAsNewGuest(RoomService $roomService, Room $room, string
519519
$attendee->setParticipantType(Participant::GUEST);
520520
$attendee->setPermissions(Attendee::PERMISSIONS_DEFAULT);
521521
$attendee->setLastReadMessage($lastMessage);
522-
$attendee->setMuteUntil((new \DateTime())->setTimestamp(0));
523522

524523
if ($displayName !== null && $displayName !== '') {
525524
$attendee->setDisplayName($displayName);
@@ -675,7 +674,6 @@ public function addUsers(Room $room, array $participants, ?IUser $addedBy = null
675674
$attendee->setPermissions(Attendee::PERMISSIONS_DEFAULT);
676675
$attendee->setLastReadMessage($participant['lastReadMessage'] ?? $lastMessage);
677676
$attendee->setReadPrivacy($readPrivacy);
678-
$attendee->setMuteUntil((new \DateTime())->setTimestamp(0));
679677
$attendees[] = $attendee;
680678
}
681679

@@ -834,7 +832,6 @@ public function addGroup(Room $room, IGroup $group, array &$existingParticipants
834832
$attendee->setParticipantType(Participant::USER);
835833
$attendee->setPermissions(Attendee::PERMISSIONS_DEFAULT);
836834
$attendee->setReadPrivacy(Participant::PRIVACY_PRIVATE);
837-
$attendee->setMuteUntil((new \DateTime())->setTimestamp(0));
838835
$this->attendeeMapper->insert($attendee);
839836

840837
$attendeeEvent = new AttendeesAddedEvent($room, [$attendee]);
@@ -973,7 +970,6 @@ public function addCircle(Room $room, Circle $circle, array &$existingParticipan
973970
$attendee->setParticipantType(Participant::USER);
974971
$attendee->setPermissions(Attendee::PERMISSIONS_DEFAULT);
975972
$attendee->setReadPrivacy(Participant::PRIVACY_PRIVATE);
976-
$attendee->setMuteUntil((new \DateTime())->setTimestamp(0));
977973
$this->attendeeMapper->insert($attendee);
978974

979975
$attendeeEvent = new AttendeesAddedEvent($room, [$attendee]);
@@ -1013,7 +1009,6 @@ public function inviteEmailAddress(Room $room, string $actorId, string $email, ?
10131009

10141010
$attendee->setParticipantType(Participant::GUEST);
10151011
$attendee->setLastReadMessage($lastMessage);
1016-
$attendee->setMuteUntil((new \DateTime())->setTimestamp(0));
10171012
$this->attendeeMapper->insert($attendee);
10181013
// FIXME handle duplicate invites gracefully
10191014

@@ -2070,7 +2065,7 @@ public function getParticipantUsersForCallNotifications(Room $room): array {
20702065
->where($query->expr()->eq('a.room_id', $query->createNamedParameter($room->getId(), IQueryBuilder::PARAM_INT)))
20712066
->andWhere($query->expr()->eq('a.actor_type', $query->createNamedParameter(Attendee::ACTOR_USERS)))
20722067
->andWhere($query->expr()->eq('a.notification_calls', $query->createNamedParameter(Participant::NOTIFY_CALLS_ON)))
2073-
->andWhere($query->expr()->lte('a.mute_until', $query->createNamedParameter($this->timeFactory->getDateTime(), IQueryBuilder::PARAM_DATETIME_MUTABLE)))
2068+
->andWhere($query->expr()->lte('a.mute_until', $query->createNamedParameter($this->timeFactory->getDateTime()->getTimestamp(), IQueryBuilder::PARAM_INT)))
20742069
->andWhere($query->expr()->isNull('s.in_call'));
20752070

20762071
if ($room->getLobbyState() !== Webinary::LOBBY_NONE) {

lib/Service/RoomFormatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public function formatRoomV4(
252252
'lastPinnedId' => $room->getLastPinnedId(),
253253
'hiddenPinnedId' => $attendee->getHiddenPinnedId(),
254254
'attributes' => $room->getAttributes(),
255-
'muteUntil' => max($attendee->getMuteUntil()->getTimestamp(), 0),
255+
'muteUntil' => $attendee->getMuteUntil(),
256256
]);
257257

258258
if ($room->isFederatedConversation()) {

openapi-backend-sipbridge.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@
12601260
"muteUntil": {
12611261
"type": "integer",
12621262
"format": "int64",
1263-
"description": "Required capability: `mute-conversations`"
1263+
"description": "Required capability: `mute-conversations`. Timestamp until the conversation is muted, i.e. not receiving notifications"
12641264
}
12651265
}
12661266
},

0 commit comments

Comments
 (0)