forked from upstream-mirrors/quik
change to start dial of last non-me recipient in a conversation in compose, qkreply and main-activity-swipe call actions
This commit is contained in:
@@ -63,6 +63,7 @@ import dev.octoshrimpy.quik.util.Preferences
|
||||
import dev.octoshrimpy.quik.util.tryOrNull
|
||||
import io.realm.Case
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmQuery
|
||||
import io.realm.RealmResults
|
||||
import io.realm.Sort
|
||||
import timber.log.Timber
|
||||
@@ -73,7 +74,7 @@ import kotlin.collections.ArrayList
|
||||
import kotlin.math.sqrt
|
||||
|
||||
@Singleton
|
||||
class MessageRepositoryImpl @Inject constructor(
|
||||
open class MessageRepositoryImpl @Inject constructor(
|
||||
private val activeConversationManager: ActiveConversationManager,
|
||||
private val context: Context,
|
||||
private val messageIds: KeyManager,
|
||||
@@ -82,23 +83,30 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
private val syncRepository: SyncRepository
|
||||
) : MessageRepository {
|
||||
|
||||
override fun getMessages(threadId: Long, query: String): RealmResults<Message> {
|
||||
private fun getMessagesBase(threadId: Long, query: String): RealmQuery<Message> {
|
||||
return Realm.getDefaultInstance()
|
||||
.where(Message::class.java)
|
||||
.equalTo("threadId", threadId)
|
||||
.let {
|
||||
when (query.isEmpty()) {
|
||||
true -> it
|
||||
false -> it
|
||||
.beginGroup()
|
||||
.contains("body", query, Case.INSENSITIVE)
|
||||
.or()
|
||||
.contains("parts.text", query, Case.INSENSITIVE)
|
||||
.endGroup()
|
||||
}
|
||||
.where(Message::class.java)
|
||||
.equalTo("threadId", threadId)
|
||||
.let {
|
||||
when (query.isEmpty()) {
|
||||
true -> it
|
||||
false -> it
|
||||
.beginGroup()
|
||||
.contains("body", query, Case.INSENSITIVE)
|
||||
.or()
|
||||
.contains("parts.text", query, Case.INSENSITIVE)
|
||||
.endGroup()
|
||||
}
|
||||
.sort("date")
|
||||
.findAllAsync()
|
||||
}
|
||||
.sort("date")
|
||||
}
|
||||
|
||||
override fun getMessages(threadId: Long, query: String): RealmResults<Message> {
|
||||
return getMessagesBase(threadId, query).findAllAsync()
|
||||
}
|
||||
|
||||
override fun getMessagesSync(threadId: Long, query: String): RealmResults<Message> {
|
||||
return getMessagesBase(threadId, query).findAll()
|
||||
}
|
||||
|
||||
override fun getMessage(id: Long): Message? {
|
||||
|
||||
@@ -29,6 +29,8 @@ interface MessageRepository {
|
||||
|
||||
fun getMessages(threadId: Long, query: String = ""): RealmResults<Message>
|
||||
|
||||
fun getMessagesSync(threadId: Long, query: String = ""): RealmResults<Message>
|
||||
|
||||
fun getMessage(id: Long): Message?
|
||||
|
||||
fun getMessageForPart(id: Long): Message?
|
||||
|
||||
@@ -359,12 +359,14 @@ class ComposeViewModel @Inject constructor(
|
||||
|
||||
// Open the phone dialer if the call button is clicked
|
||||
view.optionsItemIntent
|
||||
.filter { it == R.id.call }
|
||||
.withLatestFrom(conversation) { _, conversation -> conversation }
|
||||
.mapNotNull { conversation -> conversation.recipients.firstOrNull() }
|
||||
.map { recipient -> recipient.address }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { address -> navigator.makePhoneCall(address) }
|
||||
.filter { it == R.id.call }
|
||||
.withLatestFrom(state, conversation)
|
||||
.mapNotNull { (_, state, conversation) ->
|
||||
state.messages?.second?.lastOrNull { !it.isMe() }?.address // most recent non-me msg address
|
||||
?: conversation.recipients.firstOrNull()?.address // first recipient in convo
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { navigator.makePhoneCall(it) }
|
||||
|
||||
// Open the conversation settings if info button is clicked
|
||||
view.optionsItemIntent
|
||||
|
||||
@@ -46,6 +46,7 @@ import dev.octoshrimpy.quik.util.Preferences
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.autoDisposable
|
||||
import dev.octoshrimpy.quik.interactor.SpeakThreads
|
||||
import dev.octoshrimpy.quik.repository.MessageRepository
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.rxkotlin.withLatestFrom
|
||||
@@ -66,6 +67,7 @@ class MainViewModel @Inject constructor(
|
||||
syncRepository: SyncRepository,
|
||||
private val changelogManager: ChangelogManager,
|
||||
private val conversationRepo: ConversationRepository,
|
||||
private val messageRepo: MessageRepository,
|
||||
private val deleteConversations: DeleteConversations,
|
||||
private val markArchived: MarkArchived,
|
||||
private val markPinned: MarkPinned,
|
||||
@@ -510,17 +512,28 @@ class MainViewModel @Inject constructor(
|
||||
view.swipeConversationIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { (threadId, direction) ->
|
||||
val action = if (direction == ItemTouchHelper.RIGHT) prefs.swipeRight.get() else prefs.swipeLeft.get()
|
||||
val action =
|
||||
if (direction == ItemTouchHelper.RIGHT) prefs.swipeRight.get()
|
||||
else prefs.swipeLeft.get()
|
||||
when (action) {
|
||||
Preferences.SWIPE_ACTION_ARCHIVE -> markArchived.execute(listOf(threadId))
|
||||
{
|
||||
lastArchivedThreadIds.clear()
|
||||
lastArchivedThreadIds.add(threadId)
|
||||
view.showArchivedSnackbar(1)
|
||||
Preferences.SWIPE_ACTION_ARCHIVE ->
|
||||
markArchived.execute(listOf(threadId)) {
|
||||
lastArchivedThreadIds.clear()
|
||||
lastArchivedThreadIds.add(threadId)
|
||||
view.showArchivedSnackbar(1)
|
||||
}
|
||||
Preferences.SWIPE_ACTION_DELETE ->
|
||||
view.showDeleteDialog(listOf(threadId))
|
||||
Preferences.SWIPE_ACTION_BLOCK ->
|
||||
view.showBlockingDialog(listOf(threadId), true)
|
||||
Preferences.SWIPE_ACTION_CALL -> {
|
||||
(
|
||||
messageRepo.getMessagesSync(threadId).lastOrNull { !it.isMe() }
|
||||
?.address // most recent non-me msg address
|
||||
?: conversationRepo.getConversation(threadId)
|
||||
?.recipients?.firstOrNull()?.address // first recipient in convo
|
||||
)?.let(navigator::makePhoneCall)
|
||||
}
|
||||
Preferences.SWIPE_ACTION_DELETE -> view.showDeleteDialog(listOf(threadId))
|
||||
Preferences.SWIPE_ACTION_BLOCK -> view.showBlockingDialog(listOf(threadId), true)
|
||||
Preferences.SWIPE_ACTION_CALL -> conversationRepo.getConversation(threadId)?.recipients?.firstOrNull()?.address?.let(navigator::makePhoneCall)
|
||||
Preferences.SWIPE_ACTION_READ -> markRead.execute(listOf(threadId))
|
||||
Preferences.SWIPE_ACTION_UNREAD -> markUnread.execute(listOf(threadId))
|
||||
Preferences.SWIPE_ACTION_SPEAK -> speakThreads.execute(listOf(threadId))
|
||||
|
||||
@@ -120,12 +120,15 @@ class QkReplyViewModel @Inject constructor(
|
||||
|
||||
// Call
|
||||
view.menuItemIntent
|
||||
.filter { id -> id == R.id.call }
|
||||
.withLatestFrom(conversation) { _, conversation -> conversation }
|
||||
.mapNotNull { conversation -> conversation.recipients.first()?.address }
|
||||
.doOnNext { address -> navigator.makePhoneCall(address) }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { copy(hasError = true) } }
|
||||
.filter { id -> id == R.id.call }
|
||||
.withLatestFrom(state, conversation)
|
||||
.mapNotNull { (_, state, conversation) ->
|
||||
state.data?.second?.lastOrNull { !it.isMe() }?.address // most recent non-me msg address
|
||||
?: conversation.recipients.firstOrNull()?.address // first recipient in convo
|
||||
}
|
||||
.doOnNext { navigator.makePhoneCall(it) }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { copy(hasError = true) } }
|
||||
|
||||
// Show all messages
|
||||
view.menuItemIntent
|
||||
|
||||
Reference in New Issue
Block a user