about summary refs log tree commit diff
path: root/app/javascript/mastodon/stream.js
diff options
context:
space:
mode:
authorDaigo 3 Dango <zunda@users.noreply.github.com>2020-08-24 12:06:45 +0000
committerGitHub <noreply@github.com>2020-08-24 14:06:45 +0200
commit9669557be1d9c8577564242861bdbad9b821906a (patch)
treebc2bfc3fe99d8375bff9b8a505b021b458385510 /app/javascript/mastodon/stream.js
parent46210a65d1cc4c53fb69fd9c904bdf2d5679d179 (diff)
Better manage subscriptionCounters (#14608)
Before this change:
- unsubscribe() was not called for a disconnection
- It seems that WebSocketClient calls connected() and reconnected().
  subscriptionCounters were incremented twice for a single reconnection,
  first from connected() and second from reconnected()

This might be a an additional change to
https://github.com/tootsuite/mastodon/pull/14579
to recover subscriptions after a reconnect.
Diffstat (limited to 'app/javascript/mastodon/stream.js')
-rw-r--r--app/javascript/mastodon/stream.js12
1 files changed, 2 insertions, 10 deletions
diff --git a/app/javascript/mastodon/stream.js b/app/javascript/mastodon/stream.js
index 640455b33..cf1388aed 100644
--- a/app/javascript/mastodon/stream.js
+++ b/app/javascript/mastodon/stream.js
@@ -112,11 +112,10 @@ const sharedCallbacks = {
   },
 
   disconnected () {
-    subscriptions.forEach(({ onDisconnect }) => onDisconnect());
+    subscriptions.forEach(subscription => unsubscribe(subscription));
   },
 
   reconnected () {
-    subscriptions.forEach(subscription => subscribe(subscription));
   },
 };
 
@@ -252,15 +251,8 @@ const createConnection = (streamingAPIBaseURL, accessToken, channelName, { conne
 
   const es = new EventSource(`${streamingAPIBaseURL}/api/v1/streaming/${channelName}?${params.join('&')}`);
 
-  let firstConnect = true;
-
   es.onopen = () => {
-    if (firstConnect) {
-      firstConnect = false;
-      connected();
-    } else {
-      reconnected();
-    }
+    connected();
   };
 
   KNOWN_EVENT_TYPES.forEach(type => {