mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-21 13:18:52 +01:00
Add ability to toggle blocked state of conversation
This commit is contained in:
@@ -27,6 +27,7 @@ open class Conversation : RealmObject() {
|
|||||||
@PrimaryKey var id: Long = 0
|
@PrimaryKey var id: Long = 0
|
||||||
var recipients: RealmList<Recipient> = RealmList()
|
var recipients: RealmList<Recipient> = RealmList()
|
||||||
var archived: Boolean = false
|
var archived: Boolean = false
|
||||||
|
var blocked: Boolean = false
|
||||||
var draft: String = ""
|
var draft: String = ""
|
||||||
|
|
||||||
fun getTitle(): String {
|
fun getTitle(): String {
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ class MessageRepository @Inject constructor(
|
|||||||
|
|
||||||
val conversationFlowable = realm.where(Conversation::class.java)
|
val conversationFlowable = realm.where(Conversation::class.java)
|
||||||
.equalTo("archived", archived)
|
.equalTo("archived", archived)
|
||||||
|
.equalTo("blocked", false)
|
||||||
.findAllAsync()
|
.findAllAsync()
|
||||||
.asFlowable()
|
.asFlowable()
|
||||||
.filter { it.isLoaded }
|
.filter { it.isLoaded }
|
||||||
@@ -87,6 +88,13 @@ class MessageRepository @Inject constructor(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getBlockedConversations(): RealmResults<Conversation> {
|
||||||
|
return Realm.getDefaultInstance()
|
||||||
|
.where(Conversation::class.java)
|
||||||
|
.equalTo("blocked", true)
|
||||||
|
.findAll()
|
||||||
|
}
|
||||||
|
|
||||||
fun getConversationAsync(threadId: Long): Conversation {
|
fun getConversationAsync(threadId: Long): Conversation {
|
||||||
return Realm.getDefaultInstance()
|
return Realm.getDefaultInstance()
|
||||||
.where(Conversation::class.java)
|
.where(Conversation::class.java)
|
||||||
@@ -212,7 +220,6 @@ class MessageRepository @Inject constructor(
|
|||||||
val realm = Realm.getDefaultInstance()
|
val realm = Realm.getDefaultInstance()
|
||||||
val conversation = realm.where(Conversation::class.java)
|
val conversation = realm.where(Conversation::class.java)
|
||||||
.equalTo("id", threadId)
|
.equalTo("id", threadId)
|
||||||
.equalTo("archived", false)
|
|
||||||
.findFirst()
|
.findFirst()
|
||||||
|
|
||||||
realm.executeTransaction { conversation?.archived = true }
|
realm.executeTransaction { conversation?.archived = true }
|
||||||
@@ -223,13 +230,32 @@ class MessageRepository @Inject constructor(
|
|||||||
val realm = Realm.getDefaultInstance()
|
val realm = Realm.getDefaultInstance()
|
||||||
val conversation = realm.where(Conversation::class.java)
|
val conversation = realm.where(Conversation::class.java)
|
||||||
.equalTo("id", threadId)
|
.equalTo("id", threadId)
|
||||||
.equalTo("archived", true)
|
|
||||||
.findFirst()
|
.findFirst()
|
||||||
|
|
||||||
realm.executeTransaction { conversation?.archived = false }
|
realm.executeTransaction { conversation?.archived = false }
|
||||||
realm.close()
|
realm.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun markBlocked(threadId: Long) {
|
||||||
|
val realm = Realm.getDefaultInstance()
|
||||||
|
val conversation = realm.where(Conversation::class.java)
|
||||||
|
.equalTo("id", threadId)
|
||||||
|
.findFirst()
|
||||||
|
|
||||||
|
realm.executeTransaction { conversation?.blocked = true }
|
||||||
|
realm.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun markUnblocked(threadId: Long) {
|
||||||
|
val realm = Realm.getDefaultInstance()
|
||||||
|
val conversation = realm.where(Conversation::class.java)
|
||||||
|
.equalTo("id", threadId)
|
||||||
|
.findFirst()
|
||||||
|
|
||||||
|
realm.executeTransaction { conversation?.blocked = false }
|
||||||
|
realm.close()
|
||||||
|
}
|
||||||
|
|
||||||
fun markAllSeen() {
|
fun markAllSeen() {
|
||||||
val realm = Realm.getDefaultInstance()
|
val realm = Realm.getDefaultInstance()
|
||||||
val messages = realm.where(Message::class.java).equalTo("seen", false).findAll()
|
val messages = realm.where(Message::class.java).equalTo("seen", false).findAll()
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of QKSMS.
|
||||||
|
*
|
||||||
|
* QKSMS is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* QKSMS is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package interactor
|
||||||
|
|
||||||
|
import data.repository.MessageRepository
|
||||||
|
import io.reactivex.Flowable
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class MarkBlocked @Inject constructor(private val messageRepo: MessageRepository) : Interactor<Long, Unit>() {
|
||||||
|
|
||||||
|
override fun buildObservable(params: Long): Flowable<Unit> {
|
||||||
|
return Flowable.just(Unit)
|
||||||
|
.doOnNext { messageRepo.markBlocked(params) }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of QKSMS.
|
||||||
|
*
|
||||||
|
* QKSMS is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* QKSMS is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package interactor
|
||||||
|
|
||||||
|
import data.repository.MessageRepository
|
||||||
|
import io.reactivex.Flowable
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class MarkUnblocked @Inject constructor(private val messageRepo: MessageRepository) : Interactor<Long, Unit>() {
|
||||||
|
|
||||||
|
override fun buildObservable(params: Long): Flowable<Unit> {
|
||||||
|
return Flowable.just(Unit)
|
||||||
|
.doOnNext { messageRepo.markUnblocked(params) }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -35,6 +35,7 @@ class ConversationInfoActivity : QkThemedActivity<ConversationInfoViewModel>(),
|
|||||||
override val viewModelClass = ConversationInfoViewModel::class
|
override val viewModelClass = ConversationInfoViewModel::class
|
||||||
override val notificationsIntent by lazy { notifications.clicks() }
|
override val notificationsIntent by lazy { notifications.clicks() }
|
||||||
override val archiveIntent by lazy { archive.clicks() }
|
override val archiveIntent by lazy { archive.clicks() }
|
||||||
|
override val blockIntent by lazy { block.clicks() }
|
||||||
override val deleteIntent by lazy { delete.clicks() }
|
override val deleteIntent by lazy { delete.clicks() }
|
||||||
override val confirmDeleteIntent: PublishSubject<Unit> = PublishSubject.create()
|
override val confirmDeleteIntent: PublishSubject<Unit> = PublishSubject.create()
|
||||||
|
|
||||||
@@ -76,6 +77,11 @@ class ConversationInfoActivity : QkThemedActivity<ConversationInfoViewModel>(),
|
|||||||
false -> R.string.info_archive
|
false -> R.string.info_archive
|
||||||
})
|
})
|
||||||
|
|
||||||
|
block.title = getString(when (state.blocked) {
|
||||||
|
true -> R.string.info_unblock
|
||||||
|
false -> R.string.info_block
|
||||||
|
})
|
||||||
|
|
||||||
mediaAdapter.data = state.media
|
mediaAdapter.data = state.media
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import data.model.Recipient
|
|||||||
data class ConversationInfoState(
|
data class ConversationInfoState(
|
||||||
val recipients: List<Recipient> = listOf(),
|
val recipients: List<Recipient> = listOf(),
|
||||||
val archived: Boolean = false,
|
val archived: Boolean = false,
|
||||||
|
val blocked: Boolean = false,
|
||||||
val media: List<MmsPart> = ArrayList(),
|
val media: List<MmsPart> = ArrayList(),
|
||||||
val hasError: Boolean = false
|
val hasError: Boolean = false
|
||||||
)
|
)
|
||||||
@@ -25,6 +25,7 @@ interface ConversationInfoView : QkView<ConversationInfoState> {
|
|||||||
|
|
||||||
val notificationsIntent: Observable<Unit>
|
val notificationsIntent: Observable<Unit>
|
||||||
val archiveIntent: Observable<Unit>
|
val archiveIntent: Observable<Unit>
|
||||||
|
val blockIntent: Observable<Unit>
|
||||||
val deleteIntent: Observable<Unit>
|
val deleteIntent: Observable<Unit>
|
||||||
val confirmDeleteIntent: Observable<Unit>
|
val confirmDeleteIntent: Observable<Unit>
|
||||||
|
|
||||||
|
|||||||
+24
-7
@@ -20,17 +20,13 @@ package presentation.feature.conversationinfo
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import com.moez.QKSMS.R
|
|
||||||
import com.uber.autodispose.android.lifecycle.scope
|
import com.uber.autodispose.android.lifecycle.scope
|
||||||
import com.uber.autodispose.kotlin.autoDisposable
|
import com.uber.autodispose.kotlin.autoDisposable
|
||||||
import common.di.appComponent
|
import common.di.appComponent
|
||||||
import common.util.extensions.asObservable
|
import common.util.extensions.asObservable
|
||||||
import common.util.extensions.makeToast
|
|
||||||
import data.model.Conversation
|
import data.model.Conversation
|
||||||
import data.repository.MessageRepository
|
import data.repository.MessageRepository
|
||||||
import interactor.DeleteConversation
|
import interactor.*
|
||||||
import interactor.MarkArchived
|
|
||||||
import interactor.MarkUnarchived
|
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
import io.reactivex.rxkotlin.plusAssign
|
import io.reactivex.rxkotlin.plusAssign
|
||||||
import io.reactivex.rxkotlin.withLatestFrom
|
import io.reactivex.rxkotlin.withLatestFrom
|
||||||
@@ -45,6 +41,8 @@ class ConversationInfoViewModel(intent: Intent) : QkViewModel<ConversationInfoVi
|
|||||||
@Inject lateinit var messageRepo: MessageRepository
|
@Inject lateinit var messageRepo: MessageRepository
|
||||||
@Inject lateinit var markArchived: MarkArchived
|
@Inject lateinit var markArchived: MarkArchived
|
||||||
@Inject lateinit var markUnarchived: MarkUnarchived
|
@Inject lateinit var markUnarchived: MarkUnarchived
|
||||||
|
@Inject lateinit var markBlocked: MarkBlocked
|
||||||
|
@Inject lateinit var markUnblocked: MarkUnblocked
|
||||||
@Inject lateinit var navigator: Navigator
|
@Inject lateinit var navigator: Navigator
|
||||||
@Inject lateinit var deleteConversation: DeleteConversation
|
@Inject lateinit var deleteConversation: DeleteConversation
|
||||||
|
|
||||||
@@ -67,6 +65,8 @@ class ConversationInfoViewModel(intent: Intent) : QkViewModel<ConversationInfoVi
|
|||||||
|
|
||||||
disposables += markArchived
|
disposables += markArchived
|
||||||
disposables += markUnarchived
|
disposables += markUnarchived
|
||||||
|
disposables += markBlocked
|
||||||
|
disposables += markUnblocked
|
||||||
disposables += deleteConversation
|
disposables += deleteConversation
|
||||||
|
|
||||||
// Update the recipients whenever they change
|
// Update the recipients whenever they change
|
||||||
@@ -81,6 +81,12 @@ class ConversationInfoViewModel(intent: Intent) : QkViewModel<ConversationInfoVi
|
|||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.subscribe { archived -> newState { it.copy(archived = archived) } }
|
.subscribe { archived -> newState { it.copy(archived = archived) } }
|
||||||
|
|
||||||
|
// Update the view's blocked state whenever it changes
|
||||||
|
disposables += conversation
|
||||||
|
.map { conversation -> conversation.blocked }
|
||||||
|
.distinctUntilChanged()
|
||||||
|
.subscribe { blocked -> newState { it.copy(blocked = blocked) } }
|
||||||
|
|
||||||
// Load the attachments from the conversation
|
// Load the attachments from the conversation
|
||||||
disposables += messageRepo.getPartsForConversation(threadId)
|
disposables += messageRepo.getPartsForConversation(threadId)
|
||||||
.map { parts -> parts.filter { part -> part.isImage() } }
|
.map { parts -> parts.filter { part -> part.isImage() } }
|
||||||
@@ -103,8 +109,19 @@ class ConversationInfoViewModel(intent: Intent) : QkViewModel<ConversationInfoVi
|
|||||||
.autoDisposable(view.scope())
|
.autoDisposable(view.scope())
|
||||||
.subscribe { conversation ->
|
.subscribe { conversation ->
|
||||||
when (conversation.archived) {
|
when (conversation.archived) {
|
||||||
true -> markUnarchived.execute(conversation.id, { context.makeToast(R.string.toast_unarchived) })
|
true -> markUnarchived.execute(conversation.id)
|
||||||
false -> markArchived.execute(conversation.id, { context.makeToast(R.string.toast_archived) })
|
false -> markArchived.execute(conversation.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Toggle the blocked state of the conversation
|
||||||
|
view.blockIntent
|
||||||
|
.withLatestFrom(conversation, { _, conversation -> conversation })
|
||||||
|
.autoDisposable(view.scope())
|
||||||
|
.subscribe { conversation ->
|
||||||
|
when (conversation.blocked) {
|
||||||
|
true -> markUnblocked.execute(conversation.id)
|
||||||
|
false -> markBlocked.execute(conversation.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -69,6 +69,13 @@
|
|||||||
app:icon="@drawable/ic_folder_black_24dp"
|
app:icon="@drawable/ic_folder_black_24dp"
|
||||||
app:title="@string/info_archive" />
|
app:title="@string/info_archive" />
|
||||||
|
|
||||||
|
<presentation.common.widget.PreferenceView
|
||||||
|
android:id="@+id/block"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:icon="@drawable/ic_block_black_24dp"
|
||||||
|
app:title="@string/info_block" />
|
||||||
|
|
||||||
<presentation.common.widget.PreferenceView
|
<presentation.common.widget.PreferenceView
|
||||||
android:id="@+id/delete"
|
android:id="@+id/delete"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
@@ -71,6 +71,8 @@
|
|||||||
<string name="info_notifications">Notifications</string>
|
<string name="info_notifications">Notifications</string>
|
||||||
<string name="info_archive">Archive</string>
|
<string name="info_archive">Archive</string>
|
||||||
<string name="info_unarchive">Unarchive</string>
|
<string name="info_unarchive">Unarchive</string>
|
||||||
|
<string name="info_block">Block</string>
|
||||||
|
<string name="info_unblock">Unblock</string>
|
||||||
<string name="info_delete">Delete conversation</string>
|
<string name="info_delete">Delete conversation</string>
|
||||||
|
|
||||||
<string name="settings_default_sms_title">Default SMS app</string>
|
<string name="settings_default_sms_title">Default SMS app</string>
|
||||||
@@ -138,7 +140,6 @@
|
|||||||
|
|
||||||
<string name="toast_copied">Copied</string>
|
<string name="toast_copied">Copied</string>
|
||||||
<string name="toast_archived">Archived conversation</string>
|
<string name="toast_archived">Archived conversation</string>
|
||||||
<string name="toast_unarchived">Moved to inbox</string>
|
|
||||||
<string name="toast_qksms_plus">You must unlock QKSMS+ to use this</string>
|
<string name="toast_qksms_plus">You must unlock QKSMS+ to use this</string>
|
||||||
|
|
||||||
<string name="notification_message_failed_title">Message not sent</string>
|
<string name="notification_message_failed_title">Message not sent</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user