Skip to content

Commit

Permalink
Removed resetMsgsWithSendingState() in MessageDaoSource. Refactored c…
Browse files Browse the repository at this point in the history
…ode.| #793
  • Loading branch information
DenBond7 committed Dec 25, 2019
1 parent d284efa commit 52bd186
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ abstract class MessagesDao : BaseDao<MessageEntity> {
@Query("UPDATE messages SET state=:newValues WHERE email = :account AND folder = :label AND state = :oldValue")
abstract fun changeMsgsState(account: String?, label: String?, oldValue: Int, newValues: Int): Int

/**
* Add the messages which have a current state equal [MessageState.SENDING] to the sending queue again.
*
* @param account The email that the message linked
*/
@Query("UPDATE messages SET state=2 WHERE email = :account AND folder = :label AND state =:oldValue")
abstract fun resetMsgsWithSendingState(account: String?,
label: String = JavaEmailConstants.FOLDER_OUTBOX,
oldValue: Int = MessageState.SENDING.value): Int

@Query("SELECT uid, flags FROM messages WHERE email = :account AND folder = :label")
abstract fun getUIDAndFlagsPairs(account: String?, label: String): List<UidFlagsPair>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import android.database.Cursor
import android.os.Build
import android.provider.BaseColumns
import android.text.TextUtils
import com.flowcrypt.email.api.email.JavaEmailConstants
import com.flowcrypt.email.api.email.model.GeneralMessageDetails
import com.flowcrypt.email.api.email.model.LocalFolder
import com.flowcrypt.email.api.email.model.MessageFlag
Expand Down Expand Up @@ -288,26 +287,6 @@ class MessageDaoSource : BaseDaoSource() {
return details
}

/**
* Add the messages which have a current state equal [MessageState.SENDING] to the sending queue again.
*
* @param context Interface to global information about an application environment
* @param email The email that the message linked
* @return The count of the updated row or -1 up.
*/
fun resetMsgsWithSendingState(context: Context, email: String?): Int {
val contentValues = ContentValues()
contentValues.put(COL_STATE, MessageState.QUEUED.value)

val contentResolver = context.contentResolver
return if (email != null && contentResolver != null) {
val selection = "$COL_EMAIL= ? AND $COL_FOLDER = ? AND $COL_STATE = ? "
val selectionArgs = arrayOf(email, JavaEmailConstants.FOLDER_OUTBOX, MessageState.SENDING.value.toString())
contentResolver.update(baseContentUri, contentValues, selection, selectionArgs)
} else
-1
}

private fun parseFlags(string: String): Array<String> {
return parseArray(string, "\\s")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class MessagesSenderJobService : JobService() {
val attsCacheDir = File(context.cacheDir, Constants.ATTACHMENTS_CACHE_DIR)

if (account != null) {
msgDaoSource.resetMsgsWithSendingState(context, account.email)
roomDatabase.msgDao().resetMsgsWithSendingState(account.email)

val queuedMsgs = roomDatabase.msgDao().getOutboxMessages(account = account.email,
msgStateValue = MessageState.QUEUED.value)
Expand Down Expand Up @@ -214,7 +214,7 @@ class MessagesSenderJobService : JobService() {
val msgLabel = msgEntity.folder

try {
msgDaoSource.resetMsgsWithSendingState(context, email)
roomDatabase.msgDao().resetMsgsWithSendingState(account.email)
msgDaoSource.updateMsgState(context, msgEmail, msgLabel, msgUid, MessageState.SENDING)
Thread.sleep(2000)

Expand Down

0 comments on commit 52bd186

Please sign in to comment.