forked from github/wulkanowy-mirror
Fix marking message as read in hybrid and mobile api mode (#722)
This commit is contained in:
parent
37842a3603
commit
478596c4e6
@ -122,7 +122,7 @@ configurations.all {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "io.github.wulkanowy:sdk:0.16.0"
|
||||
implementation "io.github.wulkanowy:sdk:85d47f6"
|
||||
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||
implementation "androidx.core:core-ktx:1.2.0"
|
||||
|
@ -55,7 +55,7 @@ class MessageRepository @Inject constructor(
|
||||
.filter {
|
||||
it.content.isNotEmpty().also { status ->
|
||||
Timber.d("Message content in db empty: ${!status}")
|
||||
}
|
||||
} && !it.unread
|
||||
}
|
||||
.switchIfEmpty(ReactiveNetwork.checkInternetConnectivity(settings)
|
||||
.flatMap {
|
||||
@ -83,10 +83,6 @@ class MessageRepository @Inject constructor(
|
||||
.toSingle(emptyList())
|
||||
}
|
||||
|
||||
fun updateMessage(message: Message): Completable {
|
||||
return Completable.fromCallable { local.updateMessages(listOf(message)) }
|
||||
}
|
||||
|
||||
fun updateMessages(messages: List<Message>): Completable {
|
||||
return Completable.fromCallable { local.updateMessages(messages) }
|
||||
}
|
||||
@ -99,13 +95,12 @@ class MessageRepository @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteMessage(message: Message): Maybe<Boolean> {
|
||||
fun deleteMessage(message: Message): Single<Boolean> {
|
||||
return ReactiveNetwork.checkInternetConnectivity(settings)
|
||||
.flatMap {
|
||||
if (it) remote.deleteMessage(message)
|
||||
else Single.error(UnknownHostException())
|
||||
}
|
||||
.filter { it }
|
||||
.doOnSuccess {
|
||||
if (!message.removed) local.updateMessages(listOf(message.copy(removed = true).apply {
|
||||
id = message.id
|
||||
|
@ -119,8 +119,6 @@ class MessagePreviewPresenter @Inject constructor(
|
||||
}, { error ->
|
||||
retryCallback = { onMessageDelete() }
|
||||
errorHandler.dispatch(error)
|
||||
}, {
|
||||
view?.showErrorView(true)
|
||||
})
|
||||
)
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package io.github.wulkanowy.ui.modules.message.tab
|
||||
|
||||
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
|
||||
import io.github.wulkanowy.data.db.entities.Message
|
||||
import io.github.wulkanowy.data.repositories.message.MessageFolder
|
||||
import io.github.wulkanowy.data.repositories.message.MessageRepository
|
||||
import io.github.wulkanowy.data.repositories.semester.SemesterRepository
|
||||
@ -67,7 +66,6 @@ class MessageTabPresenter @Inject constructor(
|
||||
if (item.message.unread) {
|
||||
item.message.unread = false
|
||||
updateItem(item)
|
||||
updateMessage(item.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -119,16 +117,4 @@ class MessageTabPresenter @Inject constructor(
|
||||
} else showError(message, error)
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateMessage(message: Message) {
|
||||
Timber.i("Attempt to update message ${message.id}")
|
||||
disposable.add(messageRepository.updateMessage(message)
|
||||
.subscribeOn(schedulers.backgroundThread)
|
||||
.observeOn(schedulers.mainThread)
|
||||
.subscribe({ Timber.d("Update message ${message.id} result: Success") })
|
||||
{ error ->
|
||||
Timber.i("Update message ${message.id} result: An exception occurred")
|
||||
errorHandler.dispatch(error)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -94,4 +94,17 @@ class MessageRepositoryTest {
|
||||
message.subscribe(messageObserver)
|
||||
messageObserver.assertError(UnknownHostException::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `get message when content in db is empty, unread and there is no internet connection`() {
|
||||
val testMessage = Message(1, 1, 123, "", 1, "", "", "", now(), 1, true, 1, 1, false)
|
||||
|
||||
testObservingStrategy.isInternetConnection = false
|
||||
`when`(local.getMessage(123)).thenReturn(Single.just(testMessage))
|
||||
|
||||
val message = repo.getMessage(student, 123)
|
||||
val messageObserver = TestObserver<Message>()
|
||||
message.subscribe(messageObserver)
|
||||
messageObserver.assertError(UnknownHostException::class.java)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user