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