From 9806e092df7c7e7227275217c4e6dca43aa28a97 Mon Sep 17 00:00:00 2001 From: yuri Date: Fri, 1 Feb 2019 15:56:48 +0200 Subject: [PATCH] cleanup --- application/Espo/Core/WebSocket/Pusher.php | 21 ++++++++++++--------- client/src/views/notification/badge.js | 7 +------ 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/application/Espo/Core/WebSocket/Pusher.php b/application/Espo/Core/WebSocket/Pusher.php index 5f8d72c775..d2368568cc 100644 --- a/application/Espo/Core/WebSocket/Pusher.php +++ b/application/Espo/Core/WebSocket/Pusher.php @@ -36,6 +36,8 @@ class Pusher implements WampServerInterface { private $categoryList; + protected $isDebugMode = false; + protected $connectionIdUserIdMap = []; protected $userIdConnectionIdListMap = []; @@ -44,9 +46,10 @@ class Pusher implements WampServerInterface protected $connections = []; - public function __construct(array $categoryList = []) + public function __construct(array $categoryList = [], $isDebugMode = false) { $this->categoryList = $categoryList; + $this->isDebugMode = $isDebugMode; } public function onSubscribe(ConnectionInterface $connection, $topic) @@ -64,7 +67,7 @@ class Pusher implements WampServerInterface if (!isset($this->connectionIdTopicIdListMap[$connectionId])) $this->connectionIdTopicIdListMap[$connectionId] = []; if (!in_array($topicId, $this->connectionIdTopicIdListMap[$connectionId])) { - echo "add topic {$topicId} for user {$userId}\n"; + if ($this->isDebugMode) echo "add topic {$topicId} for user {$userId}\n"; $this->connectionIdTopicIdListMap[$connectionId][] = $topicId; } } @@ -84,7 +87,7 @@ class Pusher implements WampServerInterface if (isset($this->connectionIdTopicIdListMap[$connectionId])) { $index = array_search($topicId, $this->connectionIdTopicIdListMap[$connectionId]); if ($index !== false) { - echo "remove topic {$topicId} for user {$userId}\n"; + if ($this->isDebugMode) echo "remove topic {$topicId} for user {$userId}\n"; $this->connectionIdTopicIdListMap[$connectionId] = array_splice($this->connectionIdTopicIdListMap[$connectionId], $index, 1); } } @@ -121,7 +124,7 @@ class Pusher implements WampServerInterface $this->connections[$resourceId] = $connection; - echo "{$userId} subscribed\n"; + if ($this->isDebugMode) echo "{$userId} subscribed\n"; } protected function unsubscribeUser(ConnectionInterface $connection, $userId) @@ -137,12 +140,12 @@ class Pusher implements WampServerInterface } } - echo "{$userId} unsubscribed\n"; + if ($this->isDebugMode) echo "{$userId} unsubscribed\n"; } public function onOpen(ConnectionInterface $connection) { - echo "onOpen {$connection->resourceId}\n"; + if ($this->isDebugMode) echo "onOpen {$connection->resourceId}\n"; $query = $connection->httpRequest->getUri()->getQuery(); $params = \GuzzleHttp\Psr7\parse_query($query ?: ''); @@ -180,7 +183,7 @@ class Pusher implements WampServerInterface public function onClose(ConnectionInterface $connection) { - echo "onClose {$connection->resourceId}\n"; + if ($this->isDebugMode) echo "onClose {$connection->resourceId}\n"; $userId = $this->getUserIdByConnection($connection); @@ -227,11 +230,11 @@ class Pusher implements WampServerInterface $connection = $this->connections[$connectionId]; if (in_array($category, $this->connectionIdTopicIdListMap[$connectionId])) { - echo "send {$category} for connection {$connectionId}\n"; + if ($this->isDebugMode) echo "send {$category} for connection {$connectionId}\n"; $connection->event($category, $data); } } - echo "onMessage {$category} for {$userId}\n"; + if ($this->isDebugMode) echo "onMessage {$category} for {$userId}\n"; } } diff --git a/client/src/views/notification/badge.js b/client/src/views/notification/badge.js index 98ff98260b..3d22b19cf8 100644 --- a/client/src/views/notification/badge.js +++ b/client/src/views/notification/badge.js @@ -168,8 +168,7 @@ Espo.define('views/notification/badge', 'view', function (Dep) { this.checkUpdates(isFirstCheck); if (this.useWebSocket) { - this.getHelper().webSocketManager.subscribe('newNotification', function (a, b) { - console.log(a, b); + this.getHelper().webSocketManager.subscribe('newNotification', function () { this.checkUpdates(); }.bind(this)) return; @@ -194,7 +193,6 @@ Espo.define('views/notification/badge', 'view', function (Dep) { this.getHelper().webSocketManager.subscribe(category, function (c, response) { if (!response.list) return; response.list.forEach(function (item) { - console.log(item); this.showPopupNotification(name, item); }, this); }.bind(this)) @@ -209,7 +207,6 @@ Espo.define('views/notification/badge', 'view', function (Dep) { } var jqxhr = Espo.Ajax.getRequest(url).done(function (list) { list.forEach(function (item) { - console.log(item); this.showPopupNotification(name, item, isNotFirstCheck); }, this); }.bind(this)); @@ -312,7 +309,5 @@ Espo.define('views/notification/badge', 'view', function (Dep) { $document.off('mouseup.notification'); $container.remove(); }, - }); - });