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