mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
add remove subscriptions to class
This commit is contained in:
1 parent
ffb275d46d
commit
8ef300c020
5 files changed
+75
-31
No files matched your search
@@ -110,7 +110,7 @@ class Realtime
|
||||
* @param array $roles
|
||||
* @param array $channels
|
||||
*/
|
||||
static function addSubscription($projectId, $connection, &$subscriptions, &$connections, &$roles, &$channels)
|
||||
static function addSubscription($projectId, $connection, $roles, &$subscriptions, &$connections, &$channels)
|
||||
{
|
||||
/**
|
||||
* Build Subscriptions Tree
|
||||
@@ -145,4 +145,37 @@ class Realtime
|
||||
'roles' => $roles,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove Subscription.
|
||||
*
|
||||
* @param mixed $connection
|
||||
* @param array $subscriptions
|
||||
* @param array $connections
|
||||
*/
|
||||
static function removeSubscription($connection, &$subscriptions, &$connections)
|
||||
{
|
||||
$projectId = $connections[$connection]['projectId'] ?? '';
|
||||
$roles = $connections[$connection]['roles'] ?? [];
|
||||
|
||||
foreach ($roles as $key => $role) {
|
||||
foreach ($subscriptions[$projectId][$role] as $channel => $list) {
|
||||
unset($subscriptions[$projectId][$role][$channel][$connection]); // Remove connection
|
||||
|
||||
if (empty($subscriptions[$projectId][$role][$channel])) {
|
||||
unset($subscriptions[$projectId][$role][$channel]); // Remove channel when no connections
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($subscriptions[$projectId][$role])) {
|
||||
unset($subscriptions[$projectId][$role]); // Remove role when no channels
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($subscriptions[$projectId])) { // Remove project when no roles
|
||||
unset($subscriptions[$projectId]);
|
||||
}
|
||||
|
||||
unset($connections[$connection]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user