mark messages as read in the local db too
This commit is contained in:
parent
0db8b202c7
commit
8dd3fc561f
|
@ -421,6 +421,7 @@ class ThreadActivity : SimpleActivity() {
|
|||
if (!it.read) {
|
||||
hadUnreadItems = true
|
||||
markMessageRead(it.id, it.isMMS)
|
||||
conversationsDB.markRead(threadId.toLong())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -468,8 +468,6 @@ fun Context.insertNewSMS(address: String, subject: String, body: String, date: L
|
|||
}
|
||||
|
||||
fun Context.deleteConversation(threadId: Int) {
|
||||
conversationsDB.deleteThreadId(threadId.toLong())
|
||||
|
||||
var uri = Sms.CONTENT_URI
|
||||
val selection = "${Sms.THREAD_ID} = ?"
|
||||
val selectionArgs = arrayOf(threadId.toString())
|
||||
|
@ -477,6 +475,8 @@ fun Context.deleteConversation(threadId: Int) {
|
|||
|
||||
uri = Mms.CONTENT_URI
|
||||
contentResolver.delete(uri, selection, selectionArgs)
|
||||
|
||||
conversationsDB.deleteThreadId(threadId.toLong())
|
||||
}
|
||||
|
||||
fun Context.deleteMessage(id: Int, isMMS: Boolean) {
|
||||
|
@ -550,6 +550,7 @@ fun Context.showReceivedMessageNotification(address: String, body: String, threa
|
|||
action = MARK_AS_READ
|
||||
putExtra(MESSAGE_ID, messageId)
|
||||
putExtra(MESSAGE_IS_MMS, isMMS)
|
||||
putExtra(THREAD_ID, threadID)
|
||||
}
|
||||
val markAsReadPendingIntent = PendingIntent.getBroadcast(this, 0, markAsReadIntent, PendingIntent.FLAG_CANCEL_CURRENT)
|
||||
|
||||
|
|
|
@ -14,6 +14,9 @@ interface ConversationsDao {
|
|||
@Query("SELECT * FROM conversations")
|
||||
fun getAll(): List<Conversation>
|
||||
|
||||
@Query("UPDATE conversations SET read = 1 WHERE thread_id = :threadId")
|
||||
fun markRead(threadId: Long)
|
||||
|
||||
@Query("DELETE FROM conversations WHERE id = :id")
|
||||
fun delete(id: Long)
|
||||
|
||||
|
|
|
@ -4,19 +4,27 @@ import android.content.BroadcastReceiver
|
|||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.simplemobiletools.commons.extensions.notificationManager
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import com.simplemobiletools.smsmessenger.extensions.conversationsDB
|
||||
import com.simplemobiletools.smsmessenger.extensions.markMessageRead
|
||||
import com.simplemobiletools.smsmessenger.helpers.MARK_AS_READ
|
||||
import com.simplemobiletools.smsmessenger.helpers.MESSAGE_ID
|
||||
import com.simplemobiletools.smsmessenger.helpers.MESSAGE_IS_MMS
|
||||
import com.simplemobiletools.smsmessenger.helpers.THREAD_ID
|
||||
|
||||
class MarkAsReadReceiver : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
when (intent.action) {
|
||||
MARK_AS_READ -> {
|
||||
val messageId = intent.getIntExtra(MESSAGE_ID, 0)
|
||||
context.notificationManager.cancel(messageId)
|
||||
ensureBackgroundThread {
|
||||
val isMMS = intent.getBooleanExtra(MESSAGE_IS_MMS, false)
|
||||
context.markMessageRead(messageId, isMMS)
|
||||
context.notificationManager.cancel(messageId)
|
||||
|
||||
val threadId = intent.getIntExtra(THREAD_ID, 0)
|
||||
context.conversationsDB.markRead(threadId.toLong())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue