forked from github/wulkanowy-mirror
Fix empty maybe when loading message content (#343)
This commit is contained in:
parent
1f5088cfc9
commit
667c4b6af7
@ -23,8 +23,8 @@ interface MessagesDao {
|
||||
@Query("SELECT * FROM Messages WHERE student_id = :studentId AND folder_id = :folder AND removed = 0 ORDER BY date DESC")
|
||||
fun loadAll(studentId: Int, folder: Int): Maybe<List<Message>>
|
||||
|
||||
@Query("SELECT * FROM Messages WHERE student_id = :studentId AND real_id = :id")
|
||||
fun load(studentId: Int, id: Int): Maybe<Message>
|
||||
@Query("SELECT * FROM Messages WHERE id = :id")
|
||||
fun load(id: Long): Maybe<Message>
|
||||
|
||||
@Query("SELECT * FROM Messages WHERE student_id = :studentId AND removed = 1 ORDER BY date DESC")
|
||||
fun loadDeleted(studentId: Int): Maybe<List<Message>>
|
||||
|
@ -23,8 +23,8 @@ class MessageLocal @Inject constructor(private val messagesDb: MessagesDao) {
|
||||
messagesDb.deleteAll(messages)
|
||||
}
|
||||
|
||||
fun getMessage(student: Student, id: Int): Maybe<Message> {
|
||||
return messagesDb.load(student.id.toInt(), id)
|
||||
fun getMessage(id: Long): Maybe<Message> {
|
||||
return messagesDb.load(id)
|
||||
}
|
||||
|
||||
fun getMessages(student: Student, folder: MessageFolder): Maybe<List<Message>> {
|
||||
|
@ -46,14 +46,14 @@ class MessageRepository @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun getMessage(student: Student, messageId: Int, markAsRead: Boolean = false): Single<Message> {
|
||||
fun getMessage(student: Student, messageDbId: Long, markAsRead: Boolean = false): Single<Message> {
|
||||
return Single.just(apiHelper.initApi(student))
|
||||
.flatMap { _ ->
|
||||
local.getMessage(student, messageId)
|
||||
local.getMessage(messageDbId)
|
||||
.filter { !it.content.isNullOrEmpty() }
|
||||
.switchIfEmpty(ReactiveNetwork.checkInternetConnectivity(settings)
|
||||
.flatMap {
|
||||
if (it) local.getMessage(student, messageId).toSingle()
|
||||
if (it) local.getMessage(messageDbId).toSingle()
|
||||
else Single.error(UnknownHostException())
|
||||
}
|
||||
.flatMap { dbMessage ->
|
||||
@ -64,7 +64,7 @@ class MessageRepository @Inject constructor(
|
||||
}))
|
||||
}
|
||||
}.flatMap {
|
||||
local.getMessage(student, messageId).toSingle()
|
||||
local.getMessage(messageDbId).toSingle()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
@ -27,7 +27,9 @@ class MessagePreviewFragment : BaseSessionFragment(), MessagePreviewView, MainVi
|
||||
lateinit var presenter: MessagePreviewPresenter
|
||||
|
||||
private var menuReplyButton: MenuItem? = null
|
||||
|
||||
private var menuForwardButton: MenuItem? = null
|
||||
|
||||
private var menuDeleteButton: MenuItem? = null
|
||||
|
||||
override val titleStringId: Int
|
||||
@ -42,9 +44,9 @@ class MessagePreviewFragment : BaseSessionFragment(), MessagePreviewView, MainVi
|
||||
companion object {
|
||||
const val MESSAGE_ID_KEY = "message_id"
|
||||
|
||||
fun newInstance(messageId: Int?): MessagePreviewFragment {
|
||||
fun newInstance(messageId: Long): MessagePreviewFragment {
|
||||
return MessagePreviewFragment().apply {
|
||||
arguments = Bundle().apply { putInt(MESSAGE_ID_KEY, messageId ?: 0) }
|
||||
arguments = Bundle().apply { putLong(MESSAGE_ID_KEY, messageId) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -61,7 +63,7 @@ class MessagePreviewFragment : BaseSessionFragment(), MessagePreviewView, MainVi
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
messageContainer = messagePreviewContainer
|
||||
presenter.onAttachView(this, (savedInstanceState ?: arguments)?.getInt(MESSAGE_ID_KEY) ?: 0)
|
||||
presenter.onAttachView(this, (savedInstanceState ?: arguments)?.getLong(MESSAGE_ID_KEY) ?: 0L)
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
@ -145,7 +147,7 @@ class MessagePreviewFragment : BaseSessionFragment(), MessagePreviewView, MainVi
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
outState.putInt(MESSAGE_ID_KEY, presenter.messageId)
|
||||
outState.putLong(MESSAGE_ID_KEY, presenter.messageId)
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
|
@ -20,16 +20,16 @@ class MessagePreviewPresenter @Inject constructor(
|
||||
private val analytics: FirebaseAnalyticsHelper
|
||||
) : BaseSessionPresenter<MessagePreviewView>(errorHandler) {
|
||||
|
||||
var messageId: Int = 0
|
||||
var messageId = 0L
|
||||
|
||||
private var message: Message? = null
|
||||
|
||||
fun onAttachView(view: MessagePreviewView, id: Int) {
|
||||
fun onAttachView(view: MessagePreviewView, id: Long) {
|
||||
super.onAttachView(view)
|
||||
loadData(id)
|
||||
}
|
||||
|
||||
private fun loadData(id: Int) {
|
||||
private fun loadData(id: Long) {
|
||||
Timber.i("Loading message $id preview started")
|
||||
messageId = id
|
||||
disposable.apply {
|
||||
|
@ -56,7 +56,7 @@ class MessageTabFragment : BaseSessionFragment(), MessageTabView {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
messageContainer = messageTabRecycler
|
||||
presenter.onAttachView(this, MessageFolder.valueOf(
|
||||
(savedInstanceState ?: arguments)?.getString(MessageTabFragment.MESSAGE_TAB_FOLDER_ID).orEmpty()
|
||||
(savedInstanceState ?: arguments)?.getString(MESSAGE_TAB_FOLDER_ID).orEmpty()
|
||||
))
|
||||
}
|
||||
|
||||
@ -106,7 +106,7 @@ class MessageTabFragment : BaseSessionFragment(), MessageTabView {
|
||||
messageTabSwipe.isRefreshing = show
|
||||
}
|
||||
|
||||
override fun openMessage(messageId: Int?) {
|
||||
override fun openMessage(messageId: Long) {
|
||||
(activity as? MainActivity)?.pushView(MessagePreviewFragment.newInstance(messageId))
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ class MessageTabFragment : BaseSessionFragment(), MessageTabView {
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
outState.putString(MessageTabFragment.MESSAGE_TAB_FOLDER_ID, presenter.folder.name)
|
||||
outState.putString(MESSAGE_TAB_FOLDER_ID, presenter.folder.name)
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
|
@ -44,9 +44,9 @@ class MessageTabPresenter @Inject constructor(
|
||||
|
||||
fun onMessageItemSelected(item: AbstractFlexibleItem<*>) {
|
||||
if (item is MessageItem) {
|
||||
Timber.i("Select message ${item.message.realId} item")
|
||||
Timber.i("Select message ${item.message.id} item")
|
||||
view?.run {
|
||||
openMessage(item.message.realId)
|
||||
openMessage(item.message.id)
|
||||
if (item.message.unread) {
|
||||
item.message.unread = false
|
||||
updateItem(item)
|
||||
@ -90,13 +90,13 @@ class MessageTabPresenter @Inject constructor(
|
||||
}
|
||||
|
||||
private fun updateMessage(message: Message) {
|
||||
Timber.i("Attempt to update message ${message.realId}")
|
||||
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.realId} result: Success") })
|
||||
.subscribe({ Timber.d("Update message ${message.id} result: Success") })
|
||||
{ error ->
|
||||
Timber.i("Update message ${message.realId} result: An exception occurred")
|
||||
Timber.i("Update message ${message.id} result: An exception occurred")
|
||||
errorHandler.dispatch(error)
|
||||
})
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ interface MessageTabView : BaseSessionView {
|
||||
|
||||
fun showRefresh(show: Boolean)
|
||||
|
||||
fun openMessage(messageId: Int?)
|
||||
fun openMessage(messageId: Long)
|
||||
|
||||
fun notifyParentDataLoaded()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user