fix(federation): Store thread notification level also locally

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2025-09-27 17:04:31 +02:00
parent 670e99a4ab
commit ecf3a71490
No known key found for this signature in database
GPG key ID: F72FA5B49FFA96B0
5 changed files with 22 additions and 10 deletions

View file

@ -431,7 +431,7 @@ class Listener implements IEventListener {
try {
// Add to subscribed threads list
$participant = $this->participantService->getParticipant($room, $this->getUserId());
$this->threadService->setNotificationLevel($participant->getAttendee(), $thread, Participant::NOTIFY_DEFAULT);
$this->threadService->setNotificationLevel($participant->getAttendee(), $thread->getId(), Participant::NOTIFY_DEFAULT);
} catch (ParticipantNotFoundException) {
}

View file

@ -279,7 +279,7 @@ class ChatController extends AEnvironmentAwareOCSController {
if ($createThread) {
$thread = $this->threadService->createThread($this->room, (int)$comment->getId(), $threadTitle);
// Add to subscribed threads list
$this->threadService->setNotificationLevel($this->participant->getAttendee(), $thread, Participant::NOTIFY_DEFAULT);
$this->threadService->setNotificationLevel($this->participant->getAttendee(), $thread->getId(), Participant::NOTIFY_DEFAULT);
$this->chatManager->addSystemMessage(
$this->room,

View file

@ -360,7 +360,14 @@ class ThreadController extends AEnvironmentAwareOCSController {
if ($this->room->isFederatedConversation()) {
/** @var \OCA\Talk\Federation\Proxy\TalkV1\Controller\ThreadController $proxy */
$proxy = \OCP\Server::get(\OCA\Talk\Federation\Proxy\TalkV1\Controller\ThreadController::class);
return $proxy->setNotificationLevel($this->room, $this->participant, $messageId, $level);
$response = $proxy->setNotificationLevel($this->room, $this->participant, $messageId, $level);
if ($response->getStatus() === Http::STATUS_OK) {
// Also save locally, for later handling when receiving a federated message
$this->threadService->setNotificationLevel($this->participant->getAttendee(), $messageId, $level);
}
return $response;
}
if (!\in_array($level, [
@ -372,13 +379,14 @@ class ThreadController extends AEnvironmentAwareOCSController {
return new DataResponse(['error' => 'level'], Http::STATUS_BAD_REQUEST);
}
try {
$thread = $this->threadService->findByThreadId($this->room->getId(), $messageId);
} catch (DoesNotExistException) {
return new DataResponse(['error' => 'message'], Http::STATUS_NOT_FOUND);
}
$threadAttendee = $this->threadService->setNotificationLevel($this->participant->getAttendee(), $thread, $level);
$threadAttendee = $this->threadService->setNotificationLevel($this->participant->getAttendee(), $thread->getId(), $level);
$attendees = [$thread->getId() => $threadAttendee];
$list = $this->prepareListOfThreads([$thread], $attendees);

View file

@ -65,7 +65,7 @@ class ThreadAttendeeMapper extends QBMapper {
/**
* @throws DoesNotExistException if the item does not exist
*/
public function findAttendeeByThreadId(string $actorType, string $actorId, int $threadId): ThreadAttendee {
public function findAttendeeByThreadId(string $actorType, string $actorId, int $roomId, int $threadId): ThreadAttendee {
$query = $this->db->getQueryBuilder();
$query->select('*')
->from($this->getTableName())
@ -77,6 +77,10 @@ class ThreadAttendeeMapper extends QBMapper {
'actor_id',
$query->createNamedParameter($actorId),
))
->andWhere($query->expr()->eq(
'room_id',
$query->createNamedParameter($roomId),
))
->andWhere($query->expr()->eq(
'thread_id',
$query->createNamedParameter($threadId),

View file

@ -198,15 +198,15 @@ class ThreadService {
return $threadAttendees;
}
public function setNotificationLevel(Attendee $attendee, Thread $thread, int $level): ThreadAttendee {
public function setNotificationLevel(Attendee $attendee, int $threadId, int $level): ThreadAttendee {
try {
$threadAttendee = $this->threadAttendeeMapper->findAttendeeByThreadId($attendee->getActorType(), $attendee->getActorId(), $thread->getId());
$threadAttendee = $this->threadAttendeeMapper->findAttendeeByThreadId($attendee->getActorType(), $attendee->getActorId(), $attendee->getRoomId(), $threadId);
$threadAttendee->setNotificationLevel($level);
$this->threadAttendeeMapper->update($threadAttendee);
} catch (DoesNotExistException) {
$threadAttendee = new ThreadAttendee();
$threadAttendee->setThreadId($thread->getId());
$threadAttendee->setRoomId($thread->getRoomId());
$threadAttendee->setThreadId($threadId);
$threadAttendee->setRoomId($attendee->getRoomId());
$threadAttendee->setAttendeeId($attendee->getId());
$threadAttendee->setActorType($attendee->getActorType());
@ -220,7 +220,7 @@ class ThreadService {
public function ensureIsThreadAttendee(Attendee $attendee, int $threadId): void {
try {
$this->threadAttendeeMapper->findAttendeeByThreadId($attendee->getActorType(), $attendee->getActorId(), $threadId);
$this->threadAttendeeMapper->findAttendeeByThreadId($attendee->getActorType(), $attendee->getActorId(), $attendee->getRoomId(), $threadId);
} catch (DoesNotExistException) {
$threadAttendee = new ThreadAttendee();
$threadAttendee->setThreadId($threadId);