Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ object AppDependencies {
fun provideMegaphoneRepository(): MegaphoneRepository
fun provideEarlyMessageCache(): EarlyMessageCache
fun provideMessageNotifier(): MessageNotifier
fun provideIncomingMessageObserver(): IncomingMessageObserver
fun provideIncomingMessageObserver(signalWebSocket: SignalWebSocket): IncomingMessageObserver
fun provideTrimThreadsByDateManager(): TrimThreadsByDateManager
fun provideViewOnceMessageManager(): ViewOnceMessageManager
fun provideExpiringStoriesManager(): ExpiringStoriesManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ public ApplicationDependencyProvider(@NonNull Application context) {
}

@Override
public @NonNull IncomingMessageObserver provideIncomingMessageObserver() {
return new IncomingMessageObserver(context);
public @NonNull IncomingMessageObserver provideIncomingMessageObserver(@NonNull SignalWebSocket signalWebSocket) {
return new IncomingMessageObserver(context, signalWebSocket);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class NetworkDependenciesModule(
val signalServiceMessageSender: SignalServiceMessageSender by _signalServiceMessageSender

val incomingMessageObserver: IncomingMessageObserver by lazy {
provider.provideIncomingMessageObserver()
provider.provideIncomingMessageObserver(signalWebSocket)
}

val pushServiceSocket: PushServiceSocket by lazy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import org.thoughtcrime.securesms.util.AlarmSleepTimer
import org.thoughtcrime.securesms.util.AppForegroundObserver
import org.thoughtcrime.securesms.util.SignalLocalMetrics
import org.thoughtcrime.securesms.util.asChain
import org.whispersystems.signalservice.api.SignalWebSocket
import org.whispersystems.signalservice.api.push.ServiceId
import org.whispersystems.signalservice.api.util.SleepTimer
import org.whispersystems.signalservice.api.util.UptimeSleepTimer
Expand All @@ -54,7 +55,7 @@ import kotlin.time.Duration.Companion.seconds
*
* This class is responsible for opening/closing the websocket based on the app's state and observing new inbound messages received on the websocket.
*/
class IncomingMessageObserver(private val context: Application) {
class IncomingMessageObserver(private val context: Application, private val signalWebSocket: SignalWebSocket) {

companion object {
private val TAG = Log.tag(IncomingMessageObserver::class.java)
Expand Down Expand Up @@ -238,7 +239,7 @@ class IncomingMessageObserver(private val context: Application) {
}

private fun disconnect() {
AppDependencies.signalWebSocket.disconnect()
signalWebSocket.disconnect()
}

@JvmOverloads
Expand Down Expand Up @@ -378,8 +379,7 @@ class IncomingMessageObserver(private val context: Application) {
waitForConnectionNecessary()
Log.i(TAG, "Making websocket connection....")

val signalWebSocket = AppDependencies.signalWebSocket
val webSocketDisposable = AppDependencies.webSocketObserver.subscribe { state: WebSocketConnectionState ->
val webSocketDisposable = signalWebSocket.webSocketState.subscribe { state: WebSocketConnectionState ->
Log.d(TAG, "WebSocket State: $state")

// Any change to a non-connected state means that we are not drained
Expand All @@ -394,7 +394,7 @@ class IncomingMessageObserver(private val context: Application) {

signalWebSocket.connect()
try {
while (isConnectionNecessary()) {
while (!terminated && isConnectionNecessary()) {
try {
Log.d(TAG, "Reading message...")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class MockApplicationDependencyProvider : AppDependencies.Provider {
return mockk()
}

override fun provideIncomingMessageObserver(): IncomingMessageObserver {
override fun provideIncomingMessageObserver(signalWebSocket: SignalWebSocket): IncomingMessageObserver {
return mockk()
}

Expand Down