add comments
This commit is contained in:
parent
cf09129cc2
commit
b56d886717
1 changed files with 20 additions and 1 deletions
|
@ -4,6 +4,7 @@ namespace Appwrite\Messaging\Adapter;
|
||||||
|
|
||||||
use Appwrite\Database\Document;
|
use Appwrite\Database\Document;
|
||||||
use Appwrite\Messaging\Adapter;
|
use Appwrite\Messaging\Adapter;
|
||||||
|
use Redis;
|
||||||
use Utopia\App;
|
use Utopia\App;
|
||||||
|
|
||||||
class Realtime extends Adapter
|
class Realtime extends Adapter
|
||||||
|
@ -165,16 +166,34 @@ class Realtime extends Adapter
|
||||||
*/
|
*/
|
||||||
public function getSubscribers(array $event)
|
public function getSubscribers(array $event)
|
||||||
{
|
{
|
||||||
//TODO: do comments
|
|
||||||
$receivers = [];
|
$receivers = [];
|
||||||
|
/**
|
||||||
|
* Check if project has subscriber.
|
||||||
|
*/
|
||||||
if (isset($this->subscriptions[$event['project']])) {
|
if (isset($this->subscriptions[$event['project']])) {
|
||||||
|
/**
|
||||||
|
* Iterate through each role.
|
||||||
|
*/
|
||||||
foreach ($this->subscriptions[$event['project']] as $role => $subscription) {
|
foreach ($this->subscriptions[$event['project']] as $role => $subscription) {
|
||||||
|
/**
|
||||||
|
* Iterate through each channel.
|
||||||
|
*/
|
||||||
foreach ($event['data']['channels'] as $channel) {
|
foreach ($event['data']['channels'] as $channel) {
|
||||||
|
/**
|
||||||
|
* Check if channel has subscriber. Also taking care of the role in the event and the wildcard role.
|
||||||
|
*/
|
||||||
if (
|
if (
|
||||||
\array_key_exists($channel, $this->subscriptions[$event['project']][$role])
|
\array_key_exists($channel, $this->subscriptions[$event['project']][$role])
|
||||||
&& (\in_array($role, $event['roles']) || \in_array('*', $event['roles']))
|
&& (\in_array($role, $event['roles']) || \in_array('*', $event['roles']))
|
||||||
) {
|
) {
|
||||||
|
/**
|
||||||
|
* Saving all connections that are allowed to receive this event.
|
||||||
|
*/
|
||||||
foreach (array_keys($this->subscriptions[$event['project']][$role][$channel]) as $id) {
|
foreach (array_keys($this->subscriptions[$event['project']][$role][$channel]) as $id) {
|
||||||
|
/**
|
||||||
|
* To prevent duplicates, we save the connections as array keys.
|
||||||
|
*/
|
||||||
$receivers[$id] = 0;
|
$receivers[$id] = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue