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

feat: send event when deleting all sessions #3014

Closed
wants to merge 11 commits into from
Prev Previous commit
Next Next commit
feat: propogate users events to accounts channel
  • Loading branch information
christyjacob4 committed Mar 28, 2022
commit 41fcae7925b887b87220b9c41e33fe47c9be1ca7
2 changes: 0 additions & 2 deletions app/realtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,6 @@ function () use ($register, $db, $redis) {
$redis->subscribe(['realtime'], function (Redis $redis, string $channel, string $payload) use ($server, $workerId, $stats, $register, $realtime) {
$event = json_decode($payload, true);

Console::success('Event received: ' . json_encode($event));

if ($event['permissionsChanged'] && isset($event['userId'])) {
$projectId = $event['project'];
$userId = $event['userId'];
Expand Down
7 changes: 2 additions & 5 deletions src/Appwrite/Messaging/Adapter/Realtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,6 @@ public static function send(string $projectId, array $payload, string $event, ar
{
if (empty($channels) || empty($roles) || empty($projectId)) return;

// Console::success('REALTIME SEND');
// var_dump($projectId, $payload, $event, $channels, $roles, $options);

$permissionsChanged = array_key_exists('permissionsChanged', $options) && $options['permissionsChanged'];
$userId = array_key_exists('userId', $options) ? $options['userId'] : null;

Expand Down Expand Up @@ -262,6 +259,7 @@ public static function fromPayload(string $event, Document $payload, Document $p

break;
case strpos($event, 'account.sessions.') === 0:
case strpos($event, 'users.sessions.') === 0:
$channels[] = 'account';
$userId = $payload->getAttribute('userId');
if (empty($userId)) {
Expand All @@ -273,6 +271,7 @@ public static function fromPayload(string $event, Document $payload, Document $p

break;
case strpos($event, 'account.') === 0:
case strpos($event, 'users.') === 0:
$channels[] = 'account';
$channels[] = 'account.' . $payload->getId();
$roles = ['user:' . $payload->getId()];
Expand All @@ -283,7 +282,6 @@ public static function fromPayload(string $event, Document $payload, Document $p
$channels[] = 'memberships';
$channels[] = 'memberships.' . $payload->getId();
$roles = ['team:' . $payload->getAttribute('teamId')];
var_dump($roles, $channels);

break;
case strpos($event, 'teams.') === 0:
Expand Down Expand Up @@ -337,7 +335,6 @@ public static function fromPayload(string $event, Document $payload, Document $p
break;
}

// var_dump($channels, $roles, $permissionsChanged, $projectId);
return [
'channels' => $channels,
'roles' => $roles,
Expand Down