Skip to content

Commit

Permalink
also purge on accepting and declining
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Mar 27, 2024
1 parent a2e1bba commit 43f1cce
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/Controller/FederationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
namespace OCA\Talk\Controller;

use OCA\Talk\AppInfo\Application;
use OCA\Talk\CachePrefix;
use OCA\Talk\Exceptions\CannotReachRemoteException;
use OCA\Talk\Exceptions\RoomNotFoundException;
use OCA\Talk\Exceptions\UnauthorizedException;
Expand All @@ -42,6 +43,8 @@
use OCP\AppFramework\Http\Attribute\OpenAPI;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserSession;
Expand All @@ -51,15 +54,18 @@
* @psalm-import-type TalkRoom from ResponseDefinitions
*/
class FederationController extends OCSController {
protected ?ICache $fedInviteCountCache;

public function __construct(
IRequest $request,
private FederationManager $federationManager,
private Manager $talkManager,
private IUserSession $userSession,
private RoomFormatter $roomFormatter,
ICacheFactory $cacheFactory,
) {
parent::__construct(Application::APP_ID, $request);
$this->fedInviteCountCache = $cacheFactory->createDistributed(CachePrefix::FEDERATED_INVITES_COUNT);
}

/**
Expand Down Expand Up @@ -107,6 +113,9 @@ public function acceptShare(int $id): DataResponse {
}
try {
$participant = $this->federationManager->acceptRemoteRoomShare($user, $id);

$this->fedInviteCountCache?->remove($user->getUID());
\OC::$server->getLogger()->error('$this->fedInviteCountCache->remove(): ' . json_encode([$user->getUID()]));
} catch (CannotReachRemoteException) {
return new DataResponse(['error' => 'remote'], Http::STATUS_GONE);
} catch (UnauthorizedException $e) {
Expand Down Expand Up @@ -144,6 +153,9 @@ public function rejectShare(int $id): DataResponse {
}
try {
$this->federationManager->rejectRemoteRoomShare($user, $id);

$this->fedInviteCountCache?->remove($user->getUID());
\OC::$server->getLogger()->error('$this->fedInviteCountCache->remove(): ' . json_encode([$user->getUID()]));
} catch (UnauthorizedException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
} catch (\InvalidArgumentException $e) {
Expand Down
2 changes: 2 additions & 0 deletions lib/Controller/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ public function getRooms(int $noStatusUpdate = 0, bool $includeStatus = false, i
/** @var array{X-Nextcloud-Talk-Modified-Before: numeric-string, X-Nextcloud-Talk-Federation-Invites?: numeric-string} $headers */
$headers = ['X-Nextcloud-Talk-Modified-Before' => (string) $nextModifiedSince];
\OC::$server->getLogger()->error('$this->talkConfig->isFederationEnabledForUserId($user): ' . json_encode($this->talkConfig->isFederationEnabledForUserId($user)));
\OC::$server->getLogger()->error('$user->getUID()): ' . json_encode($user->getUID()));
\OC::$server->getLogger()->error('$this->fedInviteCountCache?->get($user->getUID()): ' . json_encode($this->fedInviteCountCache?->get($user->getUID())));
if ($this->talkConfig->isFederationEnabledForUserId($user)) {
$numInvites = $this->fedInviteCountCache?->get($user->getUID());
Expand All @@ -273,6 +274,7 @@ public function getRooms(int $noStatusUpdate = 0, bool $includeStatus = false, i
\OC::$server->getLogger()->error('$numInvites: ' . json_encode($numInvites));
if ($this->fedInviteCountCache instanceof ICache) {
$this->fedInviteCountCache->set($user->getUID(), $numInvites, 15 * 60);
\OC::$server->getLogger()->error('$this->fedInviteCountCache->set(): ' . json_encode([$user->getUID(), $numInvites]));
}
}
if ($numInvites !== 0) {
Expand Down
2 changes: 2 additions & 0 deletions lib/Federation/CloudFederationProviderTalk.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ public function shareReceived(ICloudFederationShare $share): string {

$this->notifyAboutNewShare($shareWith, (string) $invite->getId(), $sharedByFederatedId, $sharedByDisplayName, $roomName, $roomToken, $remote);
$this->fedInviteCountCache?->remove($invite->getUserId());
\OC::$server->getLogger()->error('$this->fedInviteCountCache->remove(): ' . json_encode([$invite->getUserId()]));
return (string) $invite->getId();
}

Expand Down Expand Up @@ -292,6 +293,7 @@ private function shareUnshared(int $remoteAttendeeId, array $notification): arra
$participant = $this->participantService->getParticipantByActor($room, Attendee::ACTOR_USERS, $invite->getUserId());
$this->participantService->removeAttendee($room, $participant, AAttendeeRemovedEvent::REASON_REMOVED);
$this->fedInviteCountCache?->remove($invite->getUserId());
\OC::$server->getLogger()->error('$this->fedInviteCountCache->remove(): ' . json_encode([$invite->getUserId()]));
} catch (ParticipantNotFoundException) {
// Never accepted the invite
}
Expand Down

0 comments on commit 43f1cce

Please sign in to comment.