mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-06-05 21:49:22 +02:00
Always calculate snippet when reading conversations
This ensures that correct snippet is displayed, because of moving messages to recycle bin. This must be done for conversations in recycle bin as well as regular conversations, because both can be affected, depending on which messages are moved to recycle bin.
This commit is contained in:
@ -2,20 +2,33 @@ package com.simplemobiletools.smsmessenger.interfaces
|
|||||||
|
|
||||||
import androidx.room.*
|
import androidx.room.*
|
||||||
import com.simplemobiletools.smsmessenger.models.Conversation
|
import com.simplemobiletools.smsmessenger.models.Conversation
|
||||||
|
import com.simplemobiletools.smsmessenger.models.ConversationWithSnippetOverride
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface ConversationsDao {
|
interface ConversationsDao {
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
fun insertOrUpdate(conversation: Conversation): Long
|
fun insertOrUpdate(conversation: Conversation): Long
|
||||||
|
|
||||||
@Query("SELECT * FROM conversations WHERE archived = 0")
|
@Query("SELECT (SELECT body FROM messages LEFT OUTER JOIN recycle_bin_messages ON messages.id = recycle_bin_messages.id WHERE recycle_bin_messages.id IS NULL AND messages.thread_id = conversations.thread_id ORDER BY messages.date DESC LIMIT 1) as new_snippet, * FROM conversations WHERE archived = 0")
|
||||||
fun getNonArchived(): List<Conversation>
|
fun getNonArchivedWithLatestSnippet(): List<ConversationWithSnippetOverride>
|
||||||
|
|
||||||
@Query("SELECT * FROM conversations WHERE archived = 1")
|
fun getNonArchived(): List<Conversation> {
|
||||||
fun getAllArchived(): List<Conversation>
|
return getNonArchivedWithLatestSnippet().map { it.toConversation() }
|
||||||
|
}
|
||||||
|
|
||||||
@Query("SELECT * FROM conversations WHERE (SELECT COUNT(*) FROM messages LEFT OUTER JOIN recycle_bin_messages ON messages.id = recycle_bin_messages.id WHERE recycle_bin_messages.id IS NOT NULL AND messages.thread_id = conversations.thread_id) > 0")
|
@Query("SELECT (SELECT body FROM messages LEFT OUTER JOIN recycle_bin_messages ON messages.id = recycle_bin_messages.id WHERE recycle_bin_messages.id IS NULL AND messages.thread_id = conversations.thread_id ORDER BY messages.date DESC LIMIT 1) as new_snippet, * FROM conversations WHERE archived = 1")
|
||||||
fun getAllWithMessagesInRecycleBin(): List<Conversation>
|
fun getAllArchivedWithLatestSnippet(): List<ConversationWithSnippetOverride>
|
||||||
|
|
||||||
|
fun getAllArchived(): List<Conversation> {
|
||||||
|
return getAllArchivedWithLatestSnippet().map { it.toConversation() }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Query("SELECT (SELECT body FROM messages LEFT OUTER JOIN recycle_bin_messages ON messages.id = recycle_bin_messages.id WHERE recycle_bin_messages.id IS NOT NULL AND messages.thread_id = conversations.thread_id ORDER BY messages.date DESC LIMIT 1) as new_snippet, * FROM conversations WHERE (SELECT COUNT(*) FROM messages LEFT OUTER JOIN recycle_bin_messages ON messages.id = recycle_bin_messages.id WHERE recycle_bin_messages.id IS NOT NULL AND messages.thread_id = conversations.thread_id) > 0")
|
||||||
|
fun getAllWithMessagesInRecycleBinWithLatestSnippet(): List<ConversationWithSnippetOverride>
|
||||||
|
|
||||||
|
fun getAllWithMessagesInRecycleBin(): List<Conversation> {
|
||||||
|
return getAllWithMessagesInRecycleBinWithLatestSnippet().map { it.toConversation() }
|
||||||
|
}
|
||||||
|
|
||||||
@Query("SELECT * FROM conversations WHERE thread_id = :threadId")
|
@Query("SELECT * FROM conversations WHERE thread_id = :threadId")
|
||||||
fun getConversationWithThreadId(threadId: Long): Conversation?
|
fun getConversationWithThreadId(threadId: Long): Conversation?
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.simplemobiletools.smsmessenger.models
|
||||||
|
|
||||||
|
import androidx.room.ColumnInfo
|
||||||
|
import androidx.room.Embedded
|
||||||
|
|
||||||
|
data class ConversationWithSnippetOverride(
|
||||||
|
@ColumnInfo(name = "new_snippet") val snippet: String?,
|
||||||
|
@Embedded val conversation: Conversation
|
||||||
|
) {
|
||||||
|
fun toConversation() =
|
||||||
|
if (snippet == null) {
|
||||||
|
conversation
|
||||||
|
} else {
|
||||||
|
conversation.copy(snippet = snippet)
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user