mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 19:38:52 +01:00
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
package data.repository
|
||||
|
||||
import android.content.ContentUris
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
@@ -33,14 +34,12 @@ import data.mapper.CursorToRecipient
|
||||
import data.model.Conversation
|
||||
import data.model.InboxItem
|
||||
import data.model.Message
|
||||
import data.model.MmsPart
|
||||
import io.reactivex.Flowable
|
||||
import io.reactivex.Maybe
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.rxkotlin.Flowables
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmList
|
||||
import io.realm.RealmResults
|
||||
import io.realm.Sort
|
||||
import javax.inject.Inject
|
||||
@@ -433,19 +432,17 @@ class MessageRepository @Inject constructor(
|
||||
}
|
||||
|
||||
fun deleteConversation(threadId: Long) {
|
||||
val realm = Realm.getDefaultInstance()
|
||||
Realm.getDefaultInstance().use { realm ->
|
||||
val conversation = realm.where(Conversation::class.java).equalTo("id", threadId).findAll()
|
||||
val messages = realm.where(Message::class.java).equalTo("threadId", threadId).findAll()
|
||||
|
||||
val conversation = realm.where(Conversation::class.java).equalTo("id", threadId).findAll()
|
||||
val messages = realm.where(Message::class.java).equalTo("threadId", threadId).findAll()
|
||||
|
||||
realm.executeTransaction {
|
||||
conversation.deleteAllFromRealm()
|
||||
messages.deleteAllFromRealm()
|
||||
realm.executeTransaction {
|
||||
conversation.deleteAllFromRealm()
|
||||
messages.deleteAllFromRealm()
|
||||
}
|
||||
}
|
||||
|
||||
realm.close()
|
||||
|
||||
val uri = Uri.withAppendedPath(Telephony.Threads.CONTENT_URI, threadId.toString())
|
||||
val uri = ContentUris.withAppendedId(Telephony.Threads.CONTENT_URI, threadId)
|
||||
context.contentResolver.delete(uri, null, null)
|
||||
}
|
||||
|
||||
|
||||
@@ -130,12 +130,12 @@ class ComposeViewModel(intent: Intent) : QkViewModel<ComposeView, ComposeState>(
|
||||
// stream of conversations. If the conversation was deleted, notify the activity to shut down
|
||||
conversation = initialConversation
|
||||
.filter { conversation -> conversation.isLoaded }
|
||||
.mergeWith(selectedConversation)
|
||||
.doOnNext { conversation ->
|
||||
if (!conversation.isValid) {
|
||||
newState { it.copy(hasError = true) }
|
||||
}
|
||||
}
|
||||
.mergeWith(selectedConversation)
|
||||
.filter { conversation -> conversation.isValid }
|
||||
.filter { conversation -> conversation.id != 0L }
|
||||
.distinctUntilChanged()
|
||||
@@ -251,7 +251,7 @@ class ComposeViewModel(intent: Intent) : QkViewModel<ComposeView, ComposeState>(
|
||||
// Mark the conversation read, if in foreground
|
||||
Observables.combineLatest(messages, view.activityVisibleIntent, { _, b -> b })
|
||||
.withLatestFrom(conversation, { visible, conversation ->
|
||||
if (visible) markRead.execute(conversation.id)
|
||||
if (visible && conversation.isValid) markRead.execute(conversation.id)
|
||||
})
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
Reference in New Issue
Block a user