Skip to content
This repository has been archived by the owner on Jun 7, 2020. It is now read-only.

Commit

Permalink
Add fallback connect while sending message
Browse files Browse the repository at this point in the history
  • Loading branch information
kb0304 committed Jul 25, 2019
1 parent 78340c1 commit 3d3e95e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import chat.rocket.common.model.UserStatus
import chat.rocket.common.model.roomTypeOf
import chat.rocket.common.util.ifNull
import chat.rocket.core.internal.realtime.setTypingStatus
import chat.rocket.core.internal.realtime.socket.connect
import chat.rocket.core.internal.realtime.socket.model.State
import chat.rocket.core.internal.realtime.subscribeRoomMessages
import chat.rocket.core.internal.realtime.subscribeTypingStatus
Expand Down Expand Up @@ -356,6 +357,9 @@ class ChatRoomPresenter @Inject constructor(
launchUI(strategy) {
try {
view.disableSendMessageButton()
if(client.state is State.Disconnected || client.state is State.Waiting){
client.connect()
}
// ignore message for now, will receive it on the stream
if (messageId == null) {
val id = UUID.randomUUID().toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import chat.rocket.android.server.domain.GetAccountsInteractor
import chat.rocket.android.server.infrastructure.ConnectionManagerFactory
import chat.rocket.android.server.infrastructure.DatabaseMessageMapper
import chat.rocket.android.server.infrastructure.DatabaseMessagesRepository
import chat.rocket.core.internal.realtime.socket.connect
import chat.rocket.core.internal.rest.sendMessage
import chat.rocket.core.model.Message
import dagger.android.AndroidInjection
Expand All @@ -15,6 +16,8 @@ import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject
import chat.rocket.core.internal.realtime.socket.model.State


class MessageService : JobService() {
@Inject
Expand Down Expand Up @@ -53,6 +56,9 @@ class MessageService : JobService() {
val client = factory.create(serverUrl)?.client
temporaryMessages.forEach { message ->
try {
if(client.state is State.Disconnected || client.state is State.Waiting){
client.connect()
}
client?.sendMessage(
message = message.message,
messageId = message.id,
Expand Down Expand Up @@ -88,4 +94,4 @@ class MessageService : JobService() {
companion object {
const val RETRY_SEND_MESSAGE_ID = 1
}
}
}

0 comments on commit 3d3e95e

Please sign in to comment.