Skip to content

Commit

Permalink
Fixed a bug of creation a new message.| #793
Browse files Browse the repository at this point in the history
  • Loading branch information
DenBond7 committed Jan 13, 2020
1 parent 6150144 commit 0f085e9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,13 @@ abstract class MessageDao : BaseDao<MessageEntity> {
abstract fun delete(email: String?, label: String?, msgsUID: Collection<Long>): Int

@Query("SELECT * FROM messages WHERE email = :account AND folder = :label AND state NOT IN (:msgStates)")
abstract fun getOutboxMessages(account: String?, label: String = JavaEmailConstants.FOLDER_OUTBOX,
msgStates: Collection<Int> = listOf(
MessageState.SENDING.value,
MessageState.SENT_WITHOUT_LOCAL_COPY.value)): List<MessageEntity>

@Query("SELECT * FROM messages WHERE email = :account AND folder = :label AND state NOT IN (:msgStateValue)")
abstract fun getOutboxMessages(account: String?, label: String = JavaEmailConstants.FOLDER_OUTBOX,
msgStateValue: Int): List<MessageEntity>
abstract fun getOutboxMsgsExceptSent(account: String?, label: String = JavaEmailConstants.FOLDER_OUTBOX,
msgStates: Collection<Int> = listOf(MessageState.SENDING.value,
MessageState.SENT_WITHOUT_LOCAL_COPY.value)): List<MessageEntity>

@Query("SELECT * FROM messages WHERE email = :account AND folder = :label AND state IN (:msgStateValue)")
abstract fun getOutboxMsgsByState(account: String?, label: String = JavaEmailConstants.FOLDER_OUTBOX,
msgStateValue: Int): List<MessageEntity>

@Query("DELETE FROM messages WHERE email = :email AND folder = :label AND uid = :uid AND state NOT IN (:msgStates)")
abstract suspend fun deleteOutgoingMsg(email: String?, label: String?, uid: Long?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class MessagesViewModel(application: Application) : BaseAndroidViewModel(applica

if (isMsgDeleted) {
val account = getActiveAccountSuspend()
val outgoingMsgCount = roomDatabase.msgDao().getOutboxMessages(account?.email).size
val outgoingMsgCount = roomDatabase.msgDao().getOutboxMsgsExceptSent(account?.email).size
val outboxLabel = roomDatabase.labelDao().getLabelSuspend(account?.email,
JavaEmailConstants.FOLDER_OUTBOX)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class ForwardedAttachmentsDownloaderJobService : JobService() {
val account = AccountDaoSource().getActiveAccountInformation(context)

if (account != null) {
val newMsgs = roomDatabase.msgDao().getOutboxMessages(account = account.email,
val newMsgs = roomDatabase.msgDao().getOutboxMsgsByState(account = account.email,
msgStateValue = MessageState.NEW_FORWARDED.value)

if (!CollectionUtils.isEmpty(newMsgs)) {
Expand Down Expand Up @@ -167,7 +167,7 @@ class ForwardedAttachmentsDownloaderJobService : JobService() {
val attDaoSource = AttachmentDaoSource()

while (true) {
val detailsList = roomDatabase.msgDao().getOutboxMessages(account = account.email,
val detailsList = roomDatabase.msgDao().getOutboxMsgsByState(account = account.email,
msgStateValue = MessageState.NEW_FORWARDED.value)

if (CollectionUtils.isEmpty(detailsList)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ class MessagesSenderJobService : JobService() {
if (account != null) {
roomDatabase.msgDao().resetMsgsWithSendingState(account.email)

val queuedMsgs = roomDatabase.msgDao().getOutboxMessages(account = account.email,
val queuedMsgs = roomDatabase.msgDao().getOutboxMsgsByState(account = account.email,
msgStateValue = MessageState.QUEUED.value)

val sentButNotSavedMsgs = roomDatabase.msgDao().getOutboxMessages(account = account.email,
val sentButNotSavedMsgs = roomDatabase.msgDao().getOutboxMsgsByState(account = account.email,
msgStateValue = MessageState.SENT_WITHOUT_LOCAL_COPY.value)

if (!CollectionUtils.isEmpty(queuedMsgs) || !CollectionUtils.isEmpty(sentButNotSavedMsgs)) {
Expand Down Expand Up @@ -183,7 +183,7 @@ class MessagesSenderJobService : JobService() {
val email = account.email
val roomDatabase = FlowCryptRoomDatabase.getDatabase(context)
while (true) {
list = roomDatabase.msgDao().getOutboxMessages(account = account.email,
list = roomDatabase.msgDao().getOutboxMsgsByState(account = account.email,
msgStateValue = MessageState.QUEUED.value)

if (CollectionUtils.isEmpty(list)) {
Expand Down Expand Up @@ -231,7 +231,7 @@ class MessagesSenderJobService : JobService() {
deleteMsgAtts(context, account, attsCacheDir, msgEntity, attsDaoSource)
}

val outgoingMsgCount = roomDatabase.msgDao().getOutboxMessages(email).size
val outgoingMsgCount = roomDatabase.msgDao().getOutboxMsgsExceptSent(email).size
val outboxLabel = roomDatabase.labelDao().getLabel(email, JavaEmailConstants.FOLDER_OUTBOX)

outboxLabel?.let {
Expand Down Expand Up @@ -282,7 +282,7 @@ class MessagesSenderJobService : JobService() {
val email = account.email
val roomDatabase = FlowCryptRoomDatabase.getDatabase(context)
while (true) {
list = roomDatabase.msgDao().getOutboxMessages(account = account.email,
list = roomDatabase.msgDao().getOutboxMsgsByState(account = account.email,
msgStateValue = MessageState.SENT_WITHOUT_LOCAL_COPY.value)
if (CollectionUtils.isEmpty(list)) {
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,12 @@ class PrepareOutgoingMessagesJobIntentService : JobIntentService() {
}

if (CollectionUtils.isEmpty(outgoingMsgInfo.forwardedAtts)) {
roomDatabase.msgDao().update(msgEntity.copy(state = MessageState.QUEUED.value))
MessagesSenderJobService.schedule(applicationContext)
val insertedMsgEntity = roomDatabase.msgDao().getMsg(
msgEntity.email, msgEntity.folder, msgEntity.uid)
insertedMsgEntity?.let {
roomDatabase.msgDao().update(it.copy(state = MessageState.QUEUED.value))
MessagesSenderJobService.schedule(applicationContext)
}
} else {
ForwardedAttachmentsDownloaderJobService.schedule(applicationContext)
}
Expand Down Expand Up @@ -170,7 +174,7 @@ class PrepareOutgoingMessagesJobIntentService : JobIntentService() {
}

private fun updateOutgoingMsgCount(email: String, roomDatabase: FlowCryptRoomDatabase) {
val outgoingMsgCount = roomDatabase.msgDao().getOutboxMessages(email).size
val outgoingMsgCount = roomDatabase.msgDao().getOutboxMsgsExceptSent(email).size
val outboxLabel = roomDatabase.labelDao().getLabel(email, JavaEmailConstants.FOLDER_OUTBOX)

outboxLabel?.let {
Expand Down

0 comments on commit 0f085e9

Please sign in to comment.