FIX: Do not send presence leave beacon if not present in any channels

FIX: Do not send presence leave beacon if not present in any channels

diff --git a/app/assets/javascripts/discourse/app/services/presence.js b/app/assets/javascripts/discourse/app/services/presence.js
index 346dcef..229963f 100644
--- a/app/assets/javascripts/discourse/app/services/presence.js
+++ b/app/assets/javascripts/discourse/app/services/presence.js
@@ -415,9 +415,14 @@ export default class PresenceService extends Service {
       .filter((e) => e.type === "leave")
       .map((e) => e.channel);
 
+    channelsToLeave.push(...this._presentChannels);
+
+    if (channelsToLeave.length === 0) {
+      return;
+    }
+
     const data = new FormData();
     data.append("client_id", this.messageBus.clientId);
-    this._presentChannels.forEach((ch) => data.append("leave_channels[]", ch));
     channelsToLeave.forEach((ch) => data.append("leave_channels[]", ch));
 
     data.append("authenticity_token", Session.currentProp("csrfToken"));

GitHub sha: 54ca7a9618bd8b10ce43e1fad92c4c36dd0ca581

This commit appears in #14718 which was approved by markvanlan. It was merged by davidtaylorhq.