diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/database/dao/MessagesDao.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/database/dao/MessagesDao.kt index 769b5522cc..4a92cd381e 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/database/dao/MessagesDao.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/database/dao/MessagesDao.kt @@ -5,6 +5,7 @@ package com.flowcrypt.email.database.dao +import android.os.Build import androidx.lifecycle.LiveData import androidx.paging.DataSource import androidx.room.Dao @@ -32,7 +33,15 @@ abstract class MessagesDao : BaseDao { abstract fun getMsg(account: String?, folder: String?, uid: Long): MessageEntity? @Query("SELECT * FROM messages WHERE email = :account AND folder = :folder") - abstract fun getMessages(account: String, folder: String): LiveData + abstract fun getMsgs(account: String, folder: String): LiveData + + @Query("SELECT * FROM messages WHERE email = :account AND folder = :folder AND is_new = 1 ORDER BY :orderBy") + abstract fun getNewMsgs(account: String, folder: String, + orderBy: String = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + "received_date ASC" + } else { + "received_date DESC" + }): List @Query("SELECT * FROM messages WHERE email = :account AND folder = :folder AND uid IN (:msgsUID)") abstract fun getMsgsByUids(account: String?, folder: String?, msgsUID: Collection?): List diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/database/dao/source/imap/MessageDaoSource.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/database/dao/source/imap/MessageDaoSource.kt index baf08a4c90..96066382c2 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/database/dao/source/imap/MessageDaoSource.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/database/dao/source/imap/MessageDaoSource.kt @@ -7,18 +7,11 @@ package com.flowcrypt.email.database.dao.source.imap import android.content.ContentValues import android.content.Context -import android.database.Cursor -import android.os.Build -import android.provider.BaseColumns import android.text.TextUtils import com.flowcrypt.email.api.email.model.GeneralMessageDetails -import com.flowcrypt.email.api.email.model.LocalFolder import com.flowcrypt.email.api.email.model.MessageFlag -import com.flowcrypt.email.database.MessageState import com.flowcrypt.email.database.dao.source.BaseDaoSource import java.util.* -import javax.mail.internet.AddressException -import javax.mail.internet.InternetAddress /** * This class describes the dao source for [GeneralMessageDetails] class. @@ -107,100 +100,6 @@ class MessageDaoSource : BaseDaoSource() { -1 } - /** - * Generate a [LocalFolder] object from the current cursor position. - * - * @param cursor The [Cursor] which contains information about [LocalFolder]. - * @return A generated [LocalFolder]. - */ - fun getMsgInfo(cursor: Cursor): GeneralMessageDetails { - val details = GeneralMessageDetails( - cursor.getString(cursor.getColumnIndex(COL_EMAIL)), - cursor.getString(cursor.getColumnIndex(COL_FOLDER)), - cursor.getInt(cursor.getColumnIndex(COL_UID)), - cursor.getInt(cursor.getColumnIndex(BaseColumns._ID)), - cursor.getLong(cursor.getColumnIndex(COL_RECEIVED_DATE)), - cursor.getLong(cursor.getColumnIndex(COL_SENT_DATE)), null, null, null, null, - cursor.getString(cursor.getColumnIndex(COL_SUBJECT)), - listOf(*parseFlags(cursor.getString(cursor.getColumnIndex(COL_FLAGS)))), - !cursor.isNull(cursor.getColumnIndex(COL_RAW_MESSAGE_WITHOUT_ATTACHMENTS)), - cursor.getInt(cursor.getColumnIndex(COL_IS_MESSAGE_HAS_ATTACHMENTS)) == 1, - cursor.getInt(cursor.getColumnIndex(COL_IS_ENCRYPTED)) == 1, - MessageState.generate(cursor.getInt(cursor.getColumnIndex(COL_STATE))), - cursor.getString(cursor.getColumnIndex(COL_ATTACHMENTS_DIRECTORY)), - cursor.getString(cursor.getColumnIndex(COL_ERROR_MSG)) - ) - - try { - val fromAddresses = cursor.getString(cursor.getColumnIndex(COL_FROM_ADDRESSES)) - details.from = if (TextUtils.isEmpty(fromAddresses)) null else listOf(*InternetAddress.parse(fromAddresses)) - } catch (e: AddressException) { - e.printStackTrace() - } - - try { - val replyToAddresses = cursor.getString(cursor.getColumnIndex(COL_REPLY_TO)) - details.replyTo = if (TextUtils.isEmpty(replyToAddresses)) null else listOf(*InternetAddress - .parse(replyToAddresses)) - } catch (e: AddressException) { - e.printStackTrace() - } - - try { - val toAddresses = cursor.getString(cursor.getColumnIndex(COL_TO_ADDRESSES)) - details.to = if (TextUtils.isEmpty(toAddresses)) null else listOf(*InternetAddress.parse(toAddresses)) - } catch (e: AddressException) { - e.printStackTrace() - } - - try { - val ccAddresses = cursor.getString(cursor.getColumnIndex(COL_CC_ADDRESSES)) - details.cc = if (TextUtils.isEmpty(ccAddresses)) null else listOf(*InternetAddress.parse(ccAddresses)) - } catch (e: AddressException) { - e.printStackTrace() - } - - return details - } - - /** - * Get new messages. - * - * @param context Interface to global information about an application environment. - * @param email The user email. - * @param label The label name. - * @return A list of [GeneralMessageDetails] objects. - */ - fun getNewMsgs(context: Context, email: String, label: String): List { - val contentResolver = context.contentResolver - - val orderType: String = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - "ASC" - } else { - "DESC" - } - - val selection = "$COL_EMAIL= ? AND $COL_FOLDER = ? AND $COL_IS_NEW = 1 " - val selectionArgs = arrayOf(email, label) - val cursor = contentResolver.query(baseContentUri, null, selection, selectionArgs, - "$COL_RECEIVED_DATE $orderType") - - val detailsList = ArrayList() - - if (cursor != null) { - while (cursor.moveToNext()) { - detailsList.add(getMsgInfo(cursor)) - } - cursor.close() - } - - return detailsList - } - - private fun parseFlags(string: String): Array { - return parseArray(string, "\\s") - } - companion object { const val TABLE_NAME_MESSAGES = "messages" @@ -222,15 +121,5 @@ class MessageDaoSource : BaseDaoSource() { const val COL_ATTACHMENTS_DIRECTORY = "attachments_directory" const val COL_ERROR_MSG = "error_msg" const val COL_REPLY_TO = "reply_to" - - const val ENCRYPTED_STATE_UNDEFINED = -1 - - private fun parseArray(attributesAsString: String?, regex: String): Array { - return if (attributesAsString != null && attributesAsString.isNotEmpty()) { - attributesAsString.split(regex.toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() - } else { - arrayOf() - } - } } } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/jobscheduler/SyncJobService.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/jobscheduler/SyncJobService.kt index c3e8fb7fb1..e136b873a7 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/jobscheduler/SyncJobService.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/jobscheduler/SyncJobService.kt @@ -26,7 +26,6 @@ import com.flowcrypt.email.api.retrofit.response.model.node.NodeKeyDetails import com.flowcrypt.email.database.FlowCryptRoomDatabase import com.flowcrypt.email.database.dao.source.AccountDao import com.flowcrypt.email.database.dao.source.AccountDaoSource -import com.flowcrypt.email.database.dao.source.imap.MessageDaoSource import com.flowcrypt.email.database.entity.MessageEntity import com.flowcrypt.email.service.MessagesNotificationManager import com.flowcrypt.email.util.GeneralUtil @@ -119,7 +118,6 @@ class SyncJobService : JobService(), SyncListener { remoteFolder: IMAPFolder, newMsgs: Array, updateMsgs: Array, ownerKey: String, requestCode: Int) { try { - val msgDaoSource = MessageDaoSource() val roomDatabase = FlowCryptRoomDatabase.getDatabase(applicationContext) val folderName = localFolder.fullName @@ -127,27 +125,26 @@ class SyncJobService : JobService(), SyncListener { val uidSet = HashSet(mapOfUIDsAndMsgsFlags.keys) val deleteCandidatesUIDs = EmailUtil.genDeleteCandidates(uidSet, remoteFolder, updateMsgs) - val generalMsgDetailsBeforeUpdate = msgDaoSource.getNewMsgs(applicationContext, account.email, folderName) + val msgsBeforeUpdate = roomDatabase.msgDao().getNewMsgs(account.email, folderName) roomDatabase.msgDao().deleteByUIDs(account.email, folderName, deleteCandidatesUIDs) val updateCandidates = EmailUtil.genUpdateCandidates(mapOfUIDsAndMsgsFlags, remoteFolder, updateMsgs).map { remoteFolder.getUID(it) to it.flags }.toMap() roomDatabase.msgDao().updateFlags(account.email, folderName, updateCandidates) - val detailsAfterUpdate = msgDaoSource.getNewMsgs(applicationContext, - account.email, folderName) + val detailsAfterUpdate = roomDatabase.msgDao().getNewMsgs(account.email, folderName) - val detailsDeleteCandidates = LinkedList(generalMsgDetailsBeforeUpdate) - detailsDeleteCandidates.removeAll(detailsAfterUpdate) + val msgsDeleteCandidates = LinkedList(msgsBeforeUpdate) + msgsDeleteCandidates.removeAll(detailsAfterUpdate) val isInbox = FoldersManager.getFolderType(localFolder) === FoldersManager.FolderType.INBOX if (!GeneralUtil.isAppForegrounded() && isInbox) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - for ((_, _, uid) in detailsDeleteCandidates) { - messagesNotificationManager!!.cancel(uid) + for (msgEntity in msgsDeleteCandidates) { + messagesNotificationManager?.cancel(msgEntity.uid.toInt()) } } else { - if (!detailsDeleteCandidates.isEmpty()) { + if (!msgsDeleteCandidates.isEmpty()) { val unseenMsgs = roomDatabase.msgDao().getUIDOfUnseenMsgs(account.email, folderName) messagesNotificationManager?.notify(this, account, localFolder, detailsAfterUpdate, unseenMsgs, true) @@ -198,7 +195,6 @@ class SyncJobService : JobService(), SyncListener { val context = applicationContext val isEncryptedModeEnabled = AccountDaoSource().isEncryptedModeEnabled(context, account.email) - val msgDaoSource = MessageDaoSource() val roomDatabase = FlowCryptRoomDatabase.getDatabase(applicationContext) val folderName = localFolder.fullName @@ -226,8 +222,7 @@ class SyncJobService : JobService(), SyncListener { return } - val newMsgsList = msgDaoSource.getNewMsgs(applicationContext, - account.email, folderName) + val newMsgsList = roomDatabase.msgDao().getNewMsgs(account.email, folderName) val unseenUIDs = roomDatabase.msgDao().getUIDOfUnseenMsgs(account.email, folderName) messagesNotificationManager?.notify(this, account, localFolder, newMsgsList, unseenUIDs, diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/service/EmailSyncService.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/service/EmailSyncService.kt index 4477a49184..a18837f9a0 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/service/EmailSyncService.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/service/EmailSyncService.kt @@ -34,7 +34,6 @@ import com.flowcrypt.email.database.dao.source.AccountDao import com.flowcrypt.email.database.dao.source.AccountDaoSource import com.flowcrypt.email.database.dao.source.imap.AttachmentDaoSource import com.flowcrypt.email.database.dao.source.imap.ImapLabelsDaoSource -import com.flowcrypt.email.database.dao.source.imap.MessageDaoSource import com.flowcrypt.email.database.entity.MessageEntity import com.flowcrypt.email.model.EmailAndNamePair import com.flowcrypt.email.ui.activity.SearchMessagesActivity @@ -288,7 +287,6 @@ class EmailSyncService : BaseService(), SyncListener { val email = account.email val folderName = localFolder.fullName - val msgDaoSource = MessageDaoSource() val folderType = FoldersManager.getFolderType(localFolder) val isNew = !GeneralUtil.isAppForegrounded() && folderType === FoldersManager.FolderType.INBOX @@ -313,7 +311,7 @@ class EmailSyncService : BaseService(), SyncListener { } if (!GeneralUtil.isAppForegrounded()) { - val detailsList = msgDaoSource.getNewMsgs(this, email, folderName) + val detailsList = roomDatabase.msgDao().getNewMsgs(email, folderName) val uidListOfUnseenMsgs = roomDatabase.msgDao().getUIDOfUnseenMsgs(email, folderName) notificationManager.notify(this, account, localFolder, detailsList, uidListOfUnseenMsgs, false) } @@ -379,7 +377,6 @@ class EmailSyncService : BaseService(), SyncListener { val folderName = localFolder.fullName try { - val msgsDaoSource = MessageDaoSource() val roomDatabase = FlowCryptRoomDatabase.getDatabase(applicationContext) val mapOfUIDAndMsgFlags = roomDatabase.msgDao().getMapOfUIDAndMsgFlags(email, folderName) @@ -395,7 +392,7 @@ class EmailSyncService : BaseService(), SyncListener { notificationManager.cancel(uid.toInt()) } } else { - val detailsList = msgsDaoSource.getNewMsgs(this, email, folderName) + val detailsList = roomDatabase.msgDao().getNewMsgs(email, folderName) val uidListOfUnseenMsgs = roomDatabase.msgDao().getUIDOfUnseenMsgs(email, folderName) notificationManager.notify(this, account, localFolder, detailsList, uidListOfUnseenMsgs, false) } @@ -455,7 +452,7 @@ class EmailSyncService : BaseService(), SyncListener { } override fun onFoldersInfoReceived(account: AccountDao, folders: Array, ownerKey: String, requestCode: Int) { - LogsUtil.d(TAG, "onFoldersInfoReceived:" + Arrays.toString(folders)) + LogsUtil.d(TAG, "onFoldersInfoReceived:" + folders.contentToString()) val email = account.email val foldersManager = FoldersManager() @@ -541,11 +538,10 @@ class EmailSyncService : BaseService(), SyncListener { } } else { - val msgDaoSource = MessageDaoSource() val roomDatabase = FlowCryptRoomDatabase.getDatabase(applicationContext) - val detailsList = msgDaoSource.getNewMsgs(this, email, folderName) + val newMsgs = roomDatabase.msgDao().getNewMsgs(email, folderName) val uidListOfUnseenMsgs = roomDatabase.msgDao().getUIDOfUnseenMsgs(email, folderName) - notificationManager.notify(this, account, localFolder, detailsList, uidListOfUnseenMsgs, true) + notificationManager.notify(this, account, localFolder, newMsgs, uidListOfUnseenMsgs, true) } } } @@ -557,10 +553,9 @@ class EmailSyncService : BaseService(), SyncListener { val folderType = FoldersManager.getFolderType(localFolder) if (folderType === FoldersManager.FolderType.INBOX && !GeneralUtil.isAppForegrounded()) { - val msgDaoSource = MessageDaoSource() val roomDatabase = FlowCryptRoomDatabase.getDatabase(applicationContext) - val detailsList = msgDaoSource.getNewMsgs(this, email, folderName) + val detailsList = roomDatabase.msgDao().getNewMsgs(email, folderName) val uidListOfUnseenMsgs = roomDatabase.msgDao().getUIDOfUnseenMsgs(email, folderName) notificationManager.notify(this, account, localFolder, detailsList, uidListOfUnseenMsgs, false) @@ -623,7 +618,7 @@ class EmailSyncService : BaseService(), SyncListener { */ private fun updateLocalContactsIfNeeded(imapFolder: IMAPFolder, messages: Array) { try { - val isSentFolder = Arrays.asList(*imapFolder.attributes).contains("\\Sent") + val isSentFolder = listOf(*imapFolder.attributes).contains("\\Sent") if (isSentFolder) { val emailAndNamePairs = ArrayList() diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/service/MessagesNotificationManager.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/service/MessagesNotificationManager.kt index 4661a57a51..07770442df 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/service/MessagesNotificationManager.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/service/MessagesNotificationManager.kt @@ -22,11 +22,11 @@ import com.flowcrypt.email.Constants import com.flowcrypt.email.R import com.flowcrypt.email.api.email.EmailUtil import com.flowcrypt.email.api.email.FoldersManager -import com.flowcrypt.email.api.email.model.GeneralMessageDetails import com.flowcrypt.email.api.email.model.LocalFolder import com.flowcrypt.email.broadcastreceivers.MarkMessagesAsOldBroadcastReceiver import com.flowcrypt.email.database.dao.source.AccountDao import com.flowcrypt.email.database.dao.source.imap.MessageDaoSource +import com.flowcrypt.email.database.entity.MessageEntity import com.flowcrypt.email.ui.activity.EmailManagerActivity import com.flowcrypt.email.ui.activity.MessageDetailsActivity import com.flowcrypt.email.ui.activity.fragment.preferences.NotificationsSettingsFragment @@ -56,15 +56,15 @@ class MessagesNotificationManager(context: Context) : CustomNotificationManager( * @param context Interface to global information about an application environment. * @param account An [AccountDao] object which contains information about an email account. * @param localFolder A local implementation of a remote folder. - * @param generalMsgDetailsList A list of models which consists information about some messages. + * @param msgs A list of models which consists information about some messages. * @param uidListOfUnseenMsgs A list of UID of unseen messages. * @param isSilent true if we don't need sound and vibration for Android 7.0 and below. */ fun notify(context: Context, account: AccountDao?, localFolder: LocalFolder, - generalMsgDetailsList: List?, uidListOfUnseenMsgs: List, + msgs: List?, uidListOfUnseenMsgs: List, isSilent: Boolean) { - if (account == null || generalMsgDetailsList == null || generalMsgDetailsList.isEmpty()) { + if (account == null || msgs == null || msgs.isEmpty()) { notificationManagerCompat.cancel(NOTIFICATIONS_GROUP_MESSAGES) return } @@ -78,9 +78,9 @@ class MessagesNotificationManager(context: Context) : CustomNotificationManager( } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - notifyWithGroupSupport(context, account, localFolder, generalMsgDetailsList) + notifyWithGroupSupport(context, account, localFolder, msgs) } else { - notifyWithSingleNotification(context, account, localFolder, generalMsgDetailsList, uidListOfUnseenMsgs, isSilent) + notifyWithSingleNotification(context, account, localFolder, msgs, uidListOfUnseenMsgs, isSilent) } } @@ -96,7 +96,7 @@ class MessagesNotificationManager(context: Context) : CustomNotificationManager( } private fun notifyWithSingleNotification(context: Context, account: AccountDao, - folder: LocalFolder, details: List, + folder: LocalFolder, msgs: List, uidOfUnseenMsgs: List, isSilent: Boolean) { val onlyEncrypted = NotificationsSettingsFragment.NOTIFICATION_LEVEL_ENCRYPTED_MESSAGES_ONLY == SharedPreferencesHelper.getString(PreferenceManager.getDefaultSharedPreferences(context), @@ -120,17 +120,18 @@ class MessagesNotificationManager(context: Context) : CustomNotificationManager( builder.setNumber(uidOfUnseenMsgs.size) } - if (details.size > 1) { + if (msgs.size > 1) { var hasAllowedNotifications = false val inboxStyle = NotificationCompat.InboxStyle() - for ((_, _, _, _, _, _, from, _, _, _, subject, _, _, _, isEncrypted) in details) { - if (onlyEncrypted && !isEncrypted) { + for (msgEntity in msgs) { + if (onlyEncrypted && msgEntity.isEncrypted == false) { continue } hasAllowedNotifications = true - inboxStyle.addLine(formatInboxStyleLine(context, EmailUtil.getFirstAddressString(from), subject)) + inboxStyle.addLine(formatInboxStyleLine(context, EmailUtil.getFirstAddressString + (msgEntity.from), msgEntity.subject)) } if (!hasAllowedNotifications) { @@ -140,12 +141,12 @@ class MessagesNotificationManager(context: Context) : CustomNotificationManager( builder.setStyle(inboxStyle) .setSmallIcon(R.drawable.ic_email_multiply_encrypted) .setContentIntent(getInboxPendingIntent(context)) - .setDeleteIntent(genDeletePendingIntent(context, NOTIFICATIONS_GROUP_MESSAGES, account, folder, details)) - .setContentTitle(context.getString(R.string.incoming_message, details.size)) + .setDeleteIntent(genDeletePendingIntent(context, NOTIFICATIONS_GROUP_MESSAGES, account, folder, msgs)) + .setContentTitle(context.getString(R.string.incoming_message, msgs.size)) } else { - val msgDetails = details[0] + val msgDetails = msgs[0] - if (onlyEncrypted && !msgDetails.isEncrypted) { + if (onlyEncrypted && msgDetails.isEncrypted == false) { return } @@ -159,8 +160,9 @@ class MessagesNotificationManager(context: Context) : CustomNotificationManager( .setContentIntent(getMsgDetailsPendingIntent(context, NOTIFICATIONS_GROUP_MESSAGES, folder, msgDetails)) .setContentTitle(EmailUtil.getFirstAddressString(msgDetails.from)) .setStyle(style) - .setDeleteIntent(genDeletePendingIntent(context, NOTIFICATIONS_GROUP_MESSAGES, account, folder, details)) - .setColor(ContextCompat.getColor(context, if (msgDetails.isEncrypted) R.color.colorPrimary else R.color.red)) + .setDeleteIntent(genDeletePendingIntent(context, NOTIFICATIONS_GROUP_MESSAGES, account, folder, msgs)) + .setColor(ContextCompat.getColor(context, if (msgDetails.isEncrypted == true) + R.color.colorPrimary else R.color.red)) .setSmallIcon(R.drawable.ic_email_encrypted) } @@ -168,7 +170,7 @@ class MessagesNotificationManager(context: Context) : CustomNotificationManager( } private fun notifyWithGroupSupport(context: Context, account: AccountDao, - localFolder: LocalFolder, detailsList: List) { + localFolder: LocalFolder, msgs: List) { val isEncryptedModeEnabled = NotificationsSettingsFragment.NOTIFICATION_LEVEL_ENCRYPTED_MESSAGES_ONLY == @@ -176,10 +178,10 @@ class MessagesNotificationManager(context: Context) : CustomNotificationManager( Constants.PREF_KEY_MESSAGES_NOTIFICATION_FILTER, "") val manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager - prepareAndShowMsgGroup(context, account, localFolder, manager, detailsList) + prepareAndShowMsgGroup(context, account, localFolder, manager, msgs) - for (generalMsgDetails in detailsList) { - if (isEncryptedModeEnabled && !generalMsgDetails.isEncrypted) { + for (msg in msgs) { + if (isEncryptedModeEnabled && msg.isEncrypted == false) { continue } @@ -190,37 +192,36 @@ class MessagesNotificationManager(context: Context) : CustomNotificationManager( .setCategory(NotificationCompat.CATEGORY_EMAIL) .setSmallIcon(R.drawable.ic_email_encrypted) .setLargeIcon(generateLargeIcon(context)) - .setColor(ContextCompat.getColor(context, if (generalMsgDetails.isEncrypted) + .setColor(ContextCompat.getColor(context, if (msg.isEncrypted == true) R.color.colorPrimary else R.color.red)) - .setDeleteIntent(genDeletePendingIntent(context, - generalMsgDetails.uid, account, localFolder, generalMsgDetails)) + .setDeleteIntent(genDeletePendingIntent(context, msg.uid.toInt(), account, localFolder, msg)) .setAutoCancel(true) - .setContentTitle(EmailUtil.getFirstAddressString(generalMsgDetails.from)) - .setStyle(NotificationCompat.BigTextStyle().bigText(generalMsgDetails.subject)) + .setContentTitle(EmailUtil.getFirstAddressString(msg.from)) + .setStyle(NotificationCompat.BigTextStyle().bigText(msg.subject)) .setGroup(GROUP_NAME_FLOWCRYPT_MESSAGES) - .setContentText(generalMsgDetails.subject) - .setContentIntent(getMsgDetailsPendingIntent(context, generalMsgDetails.uid, - localFolder, generalMsgDetails)) + .setContentText(msg.subject) + .setContentIntent(getMsgDetailsPendingIntent(context, msg.uid.toInt(), + localFolder, msg)) .setDefaults(Notification.DEFAULT_ALL) .setSubText(account.email) - notificationManagerCompat.notify(groupName, generalMsgDetails.uid, builder.build()) + notificationManagerCompat.notify(groupName, msg.uid.toInt(), builder.build()) } } private fun prepareAndShowMsgGroup(context: Context, account: AccountDao, localFolder: LocalFolder, notificationManager: NotificationManager, - generalMsgDetailsList: List) { + msgs: List) { val isEncryptedModeEnabled = NotificationsSettingsFragment.NOTIFICATION_LEVEL_ENCRYPTED_MESSAGES_ONLY == SharedPreferencesHelper.getString(PreferenceManager.getDefaultSharedPreferences(context), Constants.PREF_KEY_MESSAGES_NOTIFICATION_FILTER, "") if (isEncryptedModeEnabled) { var isEncryptedMsgFound = false - for (msg in generalMsgDetailsList) { - if (msg.isEncrypted) { + for (msg in msgs) { + if (msg.isEncrypted == true) { isEncryptedMsgFound = true break } @@ -233,7 +234,7 @@ class MessagesNotificationManager(context: Context) : CustomNotificationManager( var groupResourceId = R.drawable.ic_email_encrypted - if (generalMsgDetailsList.size > 1) { + if (msgs.size > 1) { groupResourceId = R.drawable.ic_email_multiply_encrypted } else { for (statusBarNotification in notificationManager.activeNotifications) { @@ -253,7 +254,7 @@ class MessagesNotificationManager(context: Context) : CustomNotificationManager( .setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY) .setContentIntent(getInboxPendingIntent(context)) .setDeleteIntent(genDeletePendingIntent(context, NOTIFICATIONS_GROUP_MESSAGES, - account, localFolder, generalMsgDetailsList)) + account, localFolder, msgs)) .setDefaults(Notification.DEFAULT_ALL) .setAutoCancel(true) .setGroupSummary(true) @@ -268,24 +269,24 @@ class MessagesNotificationManager(context: Context) : CustomNotificationManager( private fun genDeletePendingIntent(context: Context, requestCode: Int, account: AccountDao, localFolder: LocalFolder, - generalMsgDetails: GeneralMessageDetails): PendingIntent { - val generalMsgDetailsList = ArrayList() - generalMsgDetailsList.add(generalMsgDetails) - return genDeletePendingIntent(context, requestCode, account, localFolder, generalMsgDetailsList) + messageEntity: MessageEntity): PendingIntent { + val msgs = ArrayList() + msgs.add(messageEntity) + return genDeletePendingIntent(context, requestCode, account, localFolder, msgs) } private fun genDeletePendingIntent(context: Context, requestCode: Int, account: AccountDao, localFolder: LocalFolder, - generalMsgDetailsList: List): PendingIntent { + msgs: List): PendingIntent { val intent = Intent(context, MarkMessagesAsOldBroadcastReceiver::class.java) intent.action = MarkMessagesAsOldBroadcastReceiver.ACTION_MARK_MESSAGES_AS_OLD intent.putExtra(MarkMessagesAsOldBroadcastReceiver.EXTRA_KEY_EMAIL, account.email) intent.putExtra(MarkMessagesAsOldBroadcastReceiver.EXTRA_KEY_LABEL, localFolder.fullName) - if (!CollectionUtils.isEmpty(generalMsgDetailsList)) { + if (!CollectionUtils.isEmpty(msgs)) { val uidList = ArrayList() - for ((_, _, uid) in generalMsgDetailsList) { - uidList.add(uid.toString()) + for (msg in msgs) { + uidList.add(msg.uid.toString()) } intent.putStringArrayListExtra(MarkMessagesAsOldBroadcastReceiver.EXTRA_KEY_UID_LIST, uidList) } @@ -298,8 +299,8 @@ class MessagesNotificationManager(context: Context) : CustomNotificationManager( } private fun getMsgDetailsPendingIntent(context: Context, requestCode: Int, localFolder: LocalFolder, - generalMsgDetails: GeneralMessageDetails): PendingIntent { - val intent = MessageDetailsActivity.getIntent(context, localFolder, generalMsgDetails) + msg: MessageEntity): PendingIntent { + val intent = MessageDetailsActivity.getIntent(context, localFolder, msg) val stackBuilder = TaskStackBuilder.create(context) stackBuilder.addParentStack(MessageDetailsActivity::class.java) diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/MessageDetailsActivity.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/MessageDetailsActivity.kt index 4a903f34fc..d071293836 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/MessageDetailsActivity.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/MessageDetailsActivity.kt @@ -35,6 +35,7 @@ import com.flowcrypt.email.api.retrofit.response.node.ParseDecryptedMsgResult import com.flowcrypt.email.database.MessageState import com.flowcrypt.email.database.dao.source.imap.AttachmentDaoSource import com.flowcrypt.email.database.dao.source.imap.MessageDaoSource +import com.flowcrypt.email.database.entity.MessageEntity import com.flowcrypt.email.jetpack.viewmodel.DecryptMessageViewModel import com.flowcrypt.email.service.EmailSyncService import com.flowcrypt.email.ui.activity.base.BaseBackStackSyncActivity @@ -172,7 +173,8 @@ class MessageDetailsActivity : BaseBackStackSyncActivity(), LoaderManager.Loader } R.id.loader_id_subscribe_to_message_changes -> if (cursor != null && cursor.moveToFirst()) { - details = msgDaoSource.getMsgInfo(cursor) + //todo-denbond7 #793 + //details = msgDaoSource.getMsgInfo(cursor) updateViews() } @@ -466,10 +468,11 @@ class MessageDetailsActivity : BaseBackStackSyncActivity(), LoaderManager.Loader val EXTRA_KEY_GENERAL_MESSAGE_DETAILS = GeneralUtil.generateUniqueExtraKey("EXTRA_KEY_GENERAL_MESSAGE_DETAILS", MessageDetailsActivity::class.java) - fun getIntent(context: Context?, localFolder: LocalFolder?, details: GeneralMessageDetails?): Intent { + fun getIntent(context: Context?, localFolder: LocalFolder?, details: MessageEntity?): Intent { val intent = Intent(context, MessageDetailsActivity::class.java) intent.putExtra(EXTRA_KEY_FOLDER, localFolder) - intent.putExtra(EXTRA_KEY_GENERAL_MESSAGE_DETAILS, details) + //todo-denbond7 #793 + //intent.putExtra(EXTRA_KEY_GENERAL_MESSAGE_DETAILS, details) return intent } }