From f20c9a0de6bc4c1c27b48bb78dfd09802da7ea0c Mon Sep 17 00:00:00 2001
From: Janne Koschinski <janne@kuschku.de>
Date: Mon, 21 Jan 2019 19:45:04 +0100
Subject: [PATCH] Fixed crash where multiple activities at the same time would
 subscribe

---
 .../main/java/de/kuschku/libquassel/session/Session.kt | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/lib/src/main/java/de/kuschku/libquassel/session/Session.kt b/lib/src/main/java/de/kuschku/libquassel/session/Session.kt
index 48a65e5d2..f454b3c97 100644
--- a/lib/src/main/java/de/kuschku/libquassel/session/Session.kt
+++ b/lib/src/main/java/de/kuschku/libquassel/session/Session.kt
@@ -71,8 +71,10 @@ class Session(
   )
   override val state = coreConnection.state
 
-  override val error = ReusableUnicastSubject.create<Error>()
-  override val connectionError = ReusableUnicastSubject.create<Throwable>()
+  private val _error = ReusableUnicastSubject.create<Error>()
+  override val error = _error.publish().refCount()
+  private val _connectionError = ReusableUnicastSubject.create<Throwable>()
+  override val connectionError = _connectionError.publish().refCount()
 
   override val aliasManager = AliasManager(this)
   override val backlogManager = BacklogManager(this, backlogStorage)
@@ -116,7 +118,7 @@ class Session(
 
   private fun handleError(error: Error) {
     hasErroredCallback?.invoke(error)
-    this.error.onNext(error)
+    _error.onNext(error)
   }
 
   override fun handle(f: HandshakeMessage.ClientInitAck): Boolean {
@@ -173,7 +175,7 @@ class Session(
   }
 
   fun handleConnectionError(connectionError: Throwable) {
-    this.connectionError.onNext(connectionError)
+    _connectionError.onNext(connectionError)
   }
 
   fun addNetwork(networkId: NetworkId) {
-- 
GitLab