Skip to content

Commit

Permalink
Fixed a bug of updating the outbox messages count when a user delete …
Browse files Browse the repository at this point in the history
…a message from the message details screen.| #793
  • Loading branch information
DenBond7 committed Jan 13, 2020
1 parent c8935a0 commit 1d33880
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.app.Application
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.flowcrypt.email.api.email.JavaEmailConstants
import com.flowcrypt.email.api.email.model.LocalFolder
import com.flowcrypt.email.api.email.model.MessageFlag
import com.flowcrypt.email.database.FlowCryptRoomDatabase
Expand Down Expand Up @@ -85,6 +86,16 @@ class MsgDetailsViewModel(val localFolder: LocalFolder, val msgEntity: MessageEn
freshMsgEntity?.let { msgEntity ->
viewModelScope.launch {
roomDatabase.msgDao().deleteSuspend(msgEntity)

if (JavaEmailConstants.FOLDER_OUTBOX.equals(localFolder.fullName, ignoreCase = true)) {
val outgoingMsgCount = roomDatabase.msgDao().getOutboxMsgsExceptSentSuspend(msgEntity.email).size
val outboxLabel = roomDatabase.labelDao().getLabelSuspend(msgEntity.email,
JavaEmailConstants.FOLDER_OUTBOX)

outboxLabel?.let {
roomDatabase.labelDao().updateSuspend(it.copy(msgsCount = outgoingMsgCount))
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class MessageDetailsFragment : BaseSyncFragment(), View.OnClickListener {
}

R.id.menuActionDeleteMessage -> {
if (JavaEmailConstants.FOLDER_OUTBOX.equals(msgEntity!!.folder, ignoreCase = true)) {
if (JavaEmailConstants.FOLDER_OUTBOX.equals(msgEntity?.folder, ignoreCase = true)) {
val msgEntity = msgDetailsViewModel?.msgLiveData?.value

msgEntity?.let {
Expand All @@ -234,7 +234,6 @@ class MessageDetailsFragment : BaseSyncFragment(), View.OnClickListener {
Toast.makeText(context, R.string.message_was_deleted, Toast.LENGTH_SHORT).show()
}
}

} else {
msgDetailsViewModel?.changeMsgState(MessageState.PENDING_DELETING)
}
Expand Down

0 comments on commit 1d33880

Please sign in to comment.