Prefer last modified time over last message time
This commit is contained in:
parent
6f07d6971a
commit
203f10618f
|
@ -36,7 +36,6 @@ import org.greenrobot.eventbus.Subscribe
|
|||
import org.greenrobot.eventbus.ThreadMode
|
||||
import java.io.FileOutputStream
|
||||
import java.io.OutputStream
|
||||
import java.util.*
|
||||
|
||||
class MainActivity : SimpleActivity() {
|
||||
private val MAKE_DEFAULT_APP_REQUEST = 1
|
||||
|
@ -220,14 +219,6 @@ class MainActivity : SimpleActivity() {
|
|||
val privateContacts = MyContactsContentProvider.getSimpleContacts(this, privateCursor)
|
||||
val conversations = getConversations(privateContacts = privateContacts)
|
||||
|
||||
val scheduledConversations = cachedConversations.filter { it.isScheduled }
|
||||
val allConversations = conversations.toArrayList().apply {
|
||||
addAll(scheduledConversations)
|
||||
}
|
||||
runOnUiThread {
|
||||
setupConversations(allConversations)
|
||||
}
|
||||
|
||||
conversations.forEach { clonedConversation ->
|
||||
val threadIds = cachedConversations.map { it.threadId }
|
||||
if (!threadIds.contains(clonedConversation.threadId)) {
|
||||
|
@ -256,13 +247,19 @@ class MainActivity : SimpleActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
cachedConversations.forEach { cachedConversation ->
|
||||
val conv = conversations.firstOrNull { it.threadId == cachedConversation.threadId && it.toString() != cachedConversation.toString() }
|
||||
cachedConversations.forEach { cachedConv ->
|
||||
val conv = conversations.find { it.threadId == cachedConv.threadId && !cachedConv.areContentsTheSame(it) }
|
||||
if (conv != null) {
|
||||
conversationsDB.insertOrUpdate(conv)
|
||||
val conversation = conv.copy(date = maxOf(cachedConv.date, conv.date))
|
||||
conversationsDB.insertOrUpdate(conversation)
|
||||
}
|
||||
}
|
||||
|
||||
val allConversations = conversationsDB.getAll() as ArrayList<Conversation>
|
||||
runOnUiThread {
|
||||
setupConversations(allConversations)
|
||||
}
|
||||
|
||||
if (config.appRunCount == 1) {
|
||||
conversations.map { it.threadId }.forEach { threadId ->
|
||||
val messages = getMessages(threadId, getImageResolutions = false, includeScheduledMessages = false)
|
||||
|
@ -336,7 +333,7 @@ class MainActivity : SimpleActivity() {
|
|||
|
||||
val manager = getSystemService(ShortcutManager::class.java)
|
||||
try {
|
||||
manager.dynamicShortcuts = Arrays.asList(newConversation)
|
||||
manager.dynamicShortcuts = listOf(newConversation)
|
||||
config.lastHandledShortcutColor = appIconColor
|
||||
} catch (ignored: Exception) {
|
||||
}
|
||||
|
|
|
@ -977,6 +977,11 @@ class ThreadActivity : SimpleActivity() {
|
|||
createTemporaryThread(message, message.threadId)
|
||||
}
|
||||
messagesDB.insertOrUpdate(message)
|
||||
val conversation = conversationsDB.getConversationWithThreadId(threadId)
|
||||
if (conversation != null) {
|
||||
val nowSeconds = (System.currentTimeMillis() / 1000).toInt()
|
||||
conversationsDB.insertOrUpdate(conversation.copy(date = nowSeconds))
|
||||
}
|
||||
scheduleMessage(message)
|
||||
}
|
||||
clearCurrentMessage()
|
||||
|
@ -1257,6 +1262,7 @@ class ThreadActivity : SimpleActivity() {
|
|||
private fun cancelScheduledMessageAndRefresh(messageId: Long) {
|
||||
ensureBackgroundThread {
|
||||
deleteScheduledMessage(messageId)
|
||||
cancelScheduleSendPendingIntent(messageId)
|
||||
refreshMessages()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -609,7 +609,6 @@ fun Context.deleteMessage(id: Long, isMMS: Boolean) {
|
|||
fun Context.deleteScheduledMessage(messageId: Long) {
|
||||
try {
|
||||
messagesDB.delete(messageId)
|
||||
cancelScheduleSendPendingIntent(messageId)
|
||||
} catch (e: Exception) {
|
||||
showErrorToast(e)
|
||||
}
|
||||
|
|
|
@ -16,4 +16,15 @@ data class Conversation(
|
|||
@ColumnInfo(name = "is_group_conversation") var isGroupConversation: Boolean,
|
||||
@ColumnInfo(name = "phone_number") var phoneNumber: String,
|
||||
@ColumnInfo(name = "is_scheduled") var isScheduled: Boolean = false
|
||||
)
|
||||
) {
|
||||
|
||||
fun areContentsTheSame(other: Conversation): Boolean {
|
||||
return snippet == other.snippet &&
|
||||
date == other.date &&
|
||||
read == other.read &&
|
||||
title == other.title &&
|
||||
photoUri == other.photoUri &&
|
||||
isGroupConversation == other.isGroupConversation &&
|
||||
phoneNumber == other.phoneNumber
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue