forked from upstream-mirrors/quik
Divide MessageRepository into itself and Conversation Repository
This commit is contained in:
@@ -19,17 +19,17 @@
|
||||
package interactor
|
||||
|
||||
import io.reactivex.Flowable
|
||||
import repository.MessageRepository
|
||||
import repository.ConversationRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
class DeleteConversations @Inject constructor(
|
||||
private val messageRepo: MessageRepository,
|
||||
private val conversationRepo: ConversationRepository,
|
||||
private val updateBadge: UpdateBadge
|
||||
) : Interactor<List<Long>>() {
|
||||
|
||||
override fun buildObservable(params: List<Long>): Flowable<*> {
|
||||
return Flowable.just(params.toLongArray())
|
||||
.doOnNext { threadIds -> messageRepo.deleteConversations(*threadIds) }
|
||||
.doOnNext { threadIds -> conversationRepo.deleteConversations(*threadIds) }
|
||||
.flatMap { updateBadge.buildObservable(Unit) } // Update the badge
|
||||
}
|
||||
|
||||
|
||||
@@ -19,10 +19,12 @@
|
||||
package interactor
|
||||
|
||||
import io.reactivex.Flowable
|
||||
import repository.ConversationRepository
|
||||
import repository.MessageRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
class DeleteMessages @Inject constructor(
|
||||
private val conversationRepo: ConversationRepository,
|
||||
private val messageRepo: MessageRepository,
|
||||
private val updateBadge: UpdateBadge
|
||||
) : Interactor<DeleteMessages.Params>() {
|
||||
@@ -32,7 +34,7 @@ class DeleteMessages @Inject constructor(
|
||||
override fun buildObservable(params: Params): Flowable<*> {
|
||||
return Flowable.just(params.messageIds.toLongArray())
|
||||
.doOnNext { messageIds -> messageRepo.deleteMessages(*messageIds) } // Delete the messages
|
||||
.doOnNext { params.threadId?.let { messageRepo.updateConversations(it) } } // Update the conversation
|
||||
.doOnNext { params.threadId?.let { conversationRepo.updateConversations(it) } } // Update the conversation
|
||||
.flatMap { updateBadge.buildObservable(Unit) } // Update the badge
|
||||
}
|
||||
|
||||
|
||||
@@ -19,14 +19,14 @@
|
||||
package interactor
|
||||
|
||||
import io.reactivex.Flowable
|
||||
import repository.MessageRepository
|
||||
import repository.ConversationRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
class MarkArchived @Inject constructor(private val messageRepo: MessageRepository) : Interactor<List<Long>>() {
|
||||
class MarkArchived @Inject constructor(private val conversationRepo: ConversationRepository) : Interactor<List<Long>>() {
|
||||
|
||||
override fun buildObservable(params: List<Long>): Flowable<*> {
|
||||
return Flowable.just(params.toLongArray())
|
||||
.doOnNext { threadIds -> messageRepo.markArchived(*threadIds) }
|
||||
.doOnNext { threadIds -> conversationRepo.markArchived(*threadIds) }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,14 +19,14 @@
|
||||
package interactor
|
||||
|
||||
import io.reactivex.Flowable
|
||||
import repository.MessageRepository
|
||||
import repository.ConversationRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
class MarkBlocked @Inject constructor(private val messageRepo: MessageRepository) : Interactor<List<Long>>() {
|
||||
class MarkBlocked @Inject constructor(private val conversationRepo: ConversationRepository) : Interactor<List<Long>>() {
|
||||
|
||||
override fun buildObservable(params: List<Long>): Flowable<*> {
|
||||
return Flowable.just(params.toLongArray())
|
||||
.doOnNext { threadIds -> messageRepo.markBlocked(*threadIds) }
|
||||
.doOnNext { threadIds -> conversationRepo.markBlocked(*threadIds) }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,10 +20,12 @@ package interactor
|
||||
|
||||
import io.reactivex.Flowable
|
||||
import manager.NotificationManager
|
||||
import repository.ConversationRepository
|
||||
import repository.MessageRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
class MarkRead @Inject constructor(
|
||||
private val conversationRepo: ConversationRepository,
|
||||
private val messageRepo: MessageRepository,
|
||||
private val notificationManager: NotificationManager,
|
||||
private val updateBadge: UpdateBadge
|
||||
@@ -32,7 +34,7 @@ class MarkRead @Inject constructor(
|
||||
override fun buildObservable(params: List<Long>): Flowable<*> {
|
||||
return Flowable.just(params.toLongArray())
|
||||
.doOnNext { threadIds -> messageRepo.markRead(*threadIds) }
|
||||
.doOnNext { threadIds -> messageRepo.updateConversations(*threadIds) } // Update the conversation
|
||||
.doOnNext { threadIds -> conversationRepo.updateConversations(*threadIds) } // Update the conversation
|
||||
.doOnNext { threadIds -> threadIds.forEach(notificationManager::update) }
|
||||
.flatMap { updateBadge.buildObservable(Unit) } // Update the badge
|
||||
}
|
||||
|
||||
@@ -19,14 +19,14 @@
|
||||
package interactor
|
||||
|
||||
import io.reactivex.Flowable
|
||||
import repository.MessageRepository
|
||||
import repository.ConversationRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
class MarkUnarchived @Inject constructor(private val messageRepo: MessageRepository) : Interactor<List<Long>>() {
|
||||
class MarkUnarchived @Inject constructor(private val conversationRepo: ConversationRepository) : Interactor<List<Long>>() {
|
||||
|
||||
override fun buildObservable(params: List<Long>): Flowable<*> {
|
||||
return Flowable.just(params.toLongArray())
|
||||
.doOnNext { threadIds -> messageRepo.markUnarchived(*threadIds) }
|
||||
.doOnNext { threadIds -> conversationRepo.markUnarchived(*threadIds) }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,14 +19,14 @@
|
||||
package interactor
|
||||
|
||||
import io.reactivex.Flowable
|
||||
import repository.MessageRepository
|
||||
import repository.ConversationRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
class MarkUnblocked @Inject constructor(private val messageRepo: MessageRepository) : Interactor<List<Long>>() {
|
||||
class MarkUnblocked @Inject constructor(private val conversationRepo: ConversationRepository) : Interactor<List<Long>>() {
|
||||
|
||||
override fun buildObservable(params: List<Long>): Flowable<*> {
|
||||
return Flowable.just(params.toLongArray())
|
||||
.doOnNext { threadIds -> messageRepo.markUnblocked(*threadIds) }
|
||||
.doOnNext { threadIds -> conversationRepo.markUnblocked(*threadIds) }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import android.net.Uri
|
||||
import io.reactivex.Flowable
|
||||
import manager.ExternalBlockingManager
|
||||
import manager.NotificationManager
|
||||
import repository.ConversationRepository
|
||||
import repository.MessageRepository
|
||||
import repository.SyncRepository
|
||||
import util.extensions.mapNotNull
|
||||
@@ -29,6 +30,7 @@ import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
|
||||
class ReceiveMms @Inject constructor(
|
||||
private val conversationRepo: ConversationRepository,
|
||||
private val externalBlockingManager: ExternalBlockingManager,
|
||||
private val syncManager: SyncRepository,
|
||||
private val messageRepo: MessageRepository,
|
||||
@@ -48,10 +50,10 @@ class ReceiveMms @Inject constructor(
|
||||
if (blocked) messageRepo.deleteMessages(message.id)
|
||||
}
|
||||
}
|
||||
.doOnNext { message -> messageRepo.updateConversations(message.threadId) } // Update the conversation
|
||||
.mapNotNull { message -> messageRepo.getOrCreateConversation(message.threadId) } // Map message to conversation
|
||||
.doOnNext { message -> conversationRepo.updateConversations(message.threadId) } // Update the conversation
|
||||
.mapNotNull { message -> conversationRepo.getOrCreateConversation(message.threadId) } // Map message to conversation
|
||||
.filter { conversation -> !conversation.blocked } // Don't notify for blocked conversations
|
||||
.doOnNext { conversation -> if (conversation.archived) messageRepo.markUnarchived(conversation.id) } // Unarchive conversation if necessary
|
||||
.doOnNext { conversation -> if (conversation.archived) conversationRepo.markUnarchived(conversation.id) } // Unarchive conversation if necessary
|
||||
.map { conversation -> conversation.id } // Map to the id because [delay] will put us on the wrong thread
|
||||
.delay(1, TimeUnit.SECONDS) // Wait one second before trying to notify, in case the foreground app marks it as read first
|
||||
.doOnNext { threadId -> notificationManager.update(threadId) } // Update the notification
|
||||
|
||||
@@ -22,12 +22,14 @@ import android.telephony.SmsMessage
|
||||
import io.reactivex.Flowable
|
||||
import manager.ExternalBlockingManager
|
||||
import manager.NotificationManager
|
||||
import repository.ConversationRepository
|
||||
import repository.MessageRepository
|
||||
import util.extensions.mapNotNull
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
|
||||
class ReceiveSms @Inject constructor(
|
||||
private val conversationRepo: ConversationRepository,
|
||||
private val externalBlockingManager: ExternalBlockingManager,
|
||||
private val messageRepo: MessageRepository,
|
||||
private val notificationManager: NotificationManager,
|
||||
@@ -39,7 +41,8 @@ class ReceiveSms @Inject constructor(
|
||||
override fun buildObservable(params: Params): Flowable<*> {
|
||||
return Flowable.just(params)
|
||||
.filter { it.messages.isNotEmpty() }
|
||||
.filter { // Don't continue if the sender is blocked
|
||||
.filter {
|
||||
// Don't continue if the sender is blocked
|
||||
val address = it.messages[0].displayOriginatingAddress
|
||||
!externalBlockingManager.shouldBlock(address).blockingGet()
|
||||
}
|
||||
@@ -53,10 +56,10 @@ class ReceiveSms @Inject constructor(
|
||||
|
||||
messageRepo.insertReceivedSms(it.subId, address, body, time) // Add the message to the db
|
||||
}
|
||||
.doOnNext { message -> messageRepo.updateConversations(message.threadId) } // Update the conversation
|
||||
.mapNotNull { message -> messageRepo.getOrCreateConversation(message.threadId) } // Map message to conversation
|
||||
.doOnNext { message -> conversationRepo.updateConversations(message.threadId) } // Update the conversation
|
||||
.mapNotNull { message -> conversationRepo.getOrCreateConversation(message.threadId) } // Map message to conversation
|
||||
.filter { conversation -> !conversation.blocked } // Don't notify for blocked conversations
|
||||
.doOnNext { conversation -> if (conversation.archived) messageRepo.markUnarchived(conversation.id) } // Unarchive conversation if necessary
|
||||
.doOnNext { conversation -> if (conversation.archived) conversationRepo.markUnarchived(conversation.id) } // Unarchive conversation if necessary
|
||||
.map { conversation -> conversation.id } // Map to the id because [delay] will put us on the wrong thread
|
||||
.delay(1, TimeUnit.SECONDS) // Wait one second before trying to notify, in case the foreground app marks it as read first
|
||||
.doOnNext { threadId -> notificationManager.update(threadId) } // Update the notification
|
||||
|
||||
@@ -20,10 +20,12 @@ package interactor
|
||||
|
||||
import io.reactivex.Flowable
|
||||
import model.Attachment
|
||||
import repository.ConversationRepository
|
||||
import repository.MessageRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
class SendMessage @Inject constructor(
|
||||
private val conversationRepo: ConversationRepository,
|
||||
private val messageRepo: MessageRepository
|
||||
) : Interactor<SendMessage.Params>() {
|
||||
|
||||
@@ -40,9 +42,9 @@ class SendMessage @Inject constructor(
|
||||
}
|
||||
}
|
||||
// If this was the first message sent in the conversation, the conversation might not exist yet
|
||||
.doOnNext { messageRepo.getOrCreateConversation(params.threadId) }
|
||||
.doOnNext { messageRepo.updateConversations(params.threadId) }
|
||||
.doOnNext { messageRepo.markUnarchived(params.threadId) }
|
||||
.doOnNext { conversationRepo.getOrCreateConversation(params.threadId) }
|
||||
.doOnNext { conversationRepo.updateConversations(params.threadId) }
|
||||
.doOnNext { conversationRepo.markUnarchived(params.threadId) }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,20 +21,20 @@ package interactor
|
||||
import android.net.Uri
|
||||
import io.reactivex.Flowable
|
||||
import model.Message
|
||||
import repository.MessageRepository
|
||||
import repository.ConversationRepository
|
||||
import repository.SyncRepository
|
||||
import util.extensions.mapNotNull
|
||||
import javax.inject.Inject
|
||||
|
||||
class SyncMessage @Inject constructor(
|
||||
private val messageRepo: MessageRepository,
|
||||
private val conversationRepo: ConversationRepository,
|
||||
private val syncManager: SyncRepository
|
||||
) : Interactor<Uri>() {
|
||||
|
||||
override fun buildObservable(params: Uri): Flowable<Message> {
|
||||
return Flowable.just(params)
|
||||
.mapNotNull { uri -> syncManager.syncMessage(uri) }
|
||||
.doOnNext { message -> messageRepo.updateConversations(message.threadId) }
|
||||
.doOnNext { message -> conversationRepo.updateConversations(message.threadId) }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package repository
|
||||
|
||||
import io.realm.RealmResults
|
||||
import model.Conversation
|
||||
import model.SearchResult
|
||||
|
||||
interface ConversationRepository {
|
||||
|
||||
fun getConversations(archived: Boolean = false): RealmResults<Conversation>
|
||||
|
||||
fun getConversationsSnapshot(): List<Conversation>
|
||||
|
||||
fun setConversationName(id: Long, name: String)
|
||||
|
||||
fun searchConversations(query: String): List<SearchResult>
|
||||
|
||||
fun getBlockedConversations(): RealmResults<Conversation>
|
||||
|
||||
fun getConversationAsync(threadId: Long): Conversation
|
||||
|
||||
fun getConversation(threadId: Long): Conversation?
|
||||
|
||||
fun getOrCreateConversation(threadId: Long): Conversation?
|
||||
|
||||
fun getOrCreateConversation(address: String): Conversation?
|
||||
|
||||
fun getOrCreateConversation(addresses: List<String>): Conversation?
|
||||
|
||||
fun saveDraft(threadId: Long, draft: String)
|
||||
|
||||
/**
|
||||
* Updates message-related fields in the conversation, like the date and snippet
|
||||
*/
|
||||
fun updateConversations(vararg threadIds: Long)
|
||||
|
||||
fun markArchived(vararg threadIds: Long)
|
||||
|
||||
fun markUnarchived(vararg threadIds: Long)
|
||||
|
||||
fun markBlocked(vararg threadIds: Long)
|
||||
|
||||
fun markUnblocked(vararg threadIds: Long)
|
||||
|
||||
fun deleteConversations(vararg threadIds: Long)
|
||||
|
||||
}
|
||||
@@ -20,35 +20,11 @@ package repository
|
||||
|
||||
import io.realm.RealmResults
|
||||
import model.Attachment
|
||||
import model.Conversation
|
||||
import model.Message
|
||||
import model.MmsPart
|
||||
import model.SearchResult
|
||||
|
||||
interface MessageRepository {
|
||||
|
||||
fun getConversations(archived: Boolean = false): RealmResults<Conversation>
|
||||
|
||||
fun getConversationsSnapshot(): List<Conversation>
|
||||
|
||||
fun setConversationName(id: Long, name: String)
|
||||
|
||||
fun searchConversations(query: String): List<SearchResult>
|
||||
|
||||
fun getBlockedConversations(): RealmResults<Conversation>
|
||||
|
||||
fun getConversationAsync(threadId: Long): Conversation
|
||||
|
||||
fun getConversation(threadId: Long): Conversation?
|
||||
|
||||
fun getOrCreateConversation(threadId: Long): Conversation?
|
||||
|
||||
fun getOrCreateConversation(address: String): Conversation?
|
||||
|
||||
fun getOrCreateConversation(addresses: List<String>): Conversation?
|
||||
|
||||
fun saveDraft(threadId: Long, draft: String)
|
||||
|
||||
fun getMessages(threadId: Long, query: String = ""): RealmResults<Message>
|
||||
|
||||
fun getMessage(id: Long): Message?
|
||||
@@ -73,19 +49,6 @@ interface MessageRepository {
|
||||
*/
|
||||
fun getUnreadMessages(threadId: Long): RealmResults<Message>
|
||||
|
||||
/**
|
||||
* Updates message-related fields in the conversation, like the date and snippet
|
||||
*/
|
||||
fun updateConversations(vararg threadIds: Long)
|
||||
|
||||
fun markArchived(vararg threadIds: Long)
|
||||
|
||||
fun markUnarchived(vararg threadIds: Long)
|
||||
|
||||
fun markBlocked(vararg threadIds: Long)
|
||||
|
||||
fun markUnblocked(vararg threadIds: Long)
|
||||
|
||||
fun markAllSeen()
|
||||
|
||||
fun markSeen(threadId: Long)
|
||||
@@ -130,6 +93,4 @@ interface MessageRepository {
|
||||
|
||||
fun deleteMessages(vararg messageIds: Long)
|
||||
|
||||
fun deleteConversations(vararg threadIds: Long)
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user