Skip to content

Commit

Permalink
Fixed drafts in DRAFT folder.| #74
Browse files Browse the repository at this point in the history
  • Loading branch information
DenBond7 committed Nov 27, 2024
1 parent 7c4ecf9 commit ad0cf1a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,8 @@ class GmailApiHelper {
.users()
.history()
.list(DEFAULT_USER_ID)
.setStartHistoryId(historyId).apply {
.setStartHistoryId(historyId)
.apply {
if (!localFolder.isAll) {
labelId = localFolder.fullName
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ abstract class MessageDao : BaseDao<MessageEntity> {

@Query(
"SELECT * FROM messages " +
"WHERE account = :account AND folder = :folder AND is_visible = 1 ORDER BY thread_id DESC LIMIT 1"
"WHERE account = :account AND is_visible = 1 ORDER BY thread_id DESC LIMIT 1"
)
abstract suspend fun getNewestThread(account: String?, folder: String?): MessageEntity?
abstract suspend fun getNewestThread(account: String?): MessageEntity?

@Query("SELECT max(uid) FROM messages WHERE account = :account AND folder = :folder")
abstract suspend fun getLastUIDOfMsgForLabelSuspend(account: String?, folder: String?): Int?
Expand Down Expand Up @@ -434,7 +434,7 @@ abstract class MessageDao : BaseDao<MessageEntity> {
@Query("DELETE FROM messages WHERE account = :account AND folder = :folder AND thread_id = :threadId AND is_visible = 0")
abstract suspend fun clearCacheForGmailThread(account: String?, folder: String, threadId: Long)

@Query("DELETE FROM messages WHERE account = :account AND folder = :folder AND thread_id IN (:threadIdList)")
@Query("DELETE FROM messages WHERE account = :account AND folder = :folder AND thread_id IN (:threadIdList) AND is_visible = 0")
abstract suspend fun deleteCacheForGmailThreads(
account: String?,
folder: String,
Expand All @@ -446,7 +446,7 @@ abstract class MessageDao : BaseDao<MessageEntity> {
&& accountEntity.useAPI
&& accountEntity.useConversationMode
) {
getNewestThread(accountEntity.email, folder)
getNewestThread(accountEntity.email)
} else {
getNewestMsg(accountEntity.email, folder)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ class DraftViewModel(
).copy(
state = MessageState.PENDING_UPLOADING_DRAFT.value,
threadId = gmailThreadId,
labelIds = GmailApiHelper.LABEL_DRAFT
labelIds = GmailApiHelper.LABEL_DRAFT,
isVisible = false
)
val id = roomDatabase.msgDao().insertSuspend(newDraftMessageEntity)
return@withContext newDraftMessageEntity.copy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,10 +561,16 @@ class MessagesListFragment : BaseFragment<FragmentMessagesListBinding>(), ListPr
}

private fun isItSyncOrCachedFolder(localFolder: LocalFolder?): Boolean {
val checkDrafts = if (account?.useConversationMode == true) {
false
} else {
isDraftsFolder
}

return localFolder?.fullName.equals(
JavaEmailConstants.FOLDER_INBOX,
ignoreCase = true
) || isOutboxFolder || isDraftsFolder
) || isOutboxFolder || checkDrafts
}

/**
Expand Down Expand Up @@ -903,7 +909,7 @@ class MessagesListFragment : BaseFragment<FragmentMessagesListBinding>(), ListPr
msgsViewModel.changeMsgsState(
ids = ids,
localFolder = it,
newMsgState = if (it.isDrafts) {
newMsgState = if (account?.useConversationMode == false && it.isDrafts) {
MessageState.PENDING_DELETING_DRAFT
} else {
MessageState.PENDING_DELETING
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,14 @@ class MsgsPagedListAdapter(private val onMessageClickListener: OnMessageClickLis
messageEntity.getThreadSpannableString(context).let { spannableString ->
SpannableStringBuilder(senderAddress).apply {
if (spannableString.isNotEmpty()) {
if (spannableString.startsWith("(")) {
append(" ")
} else {
append(", ")
when {
spannableString.startsWith("(") -> {
append(" ")
}

senderAddress.isNotEmpty() -> {
append(", ")
}
}
}
append(spannableString)
Expand Down

0 comments on commit ad0cf1a

Please sign in to comment.