forked from upstream-mirrors/quik
Divide MessageRepository into itself and Conversation Repository
This commit is contained in:
@@ -41,6 +41,7 @@ import mapper.CursorToPartImpl
|
||||
import receiver.MarkReadReceiver
|
||||
import receiver.MarkSeenReceiver
|
||||
import receiver.RemoteMessagingReceiver
|
||||
import repository.ConversationRepository
|
||||
import repository.MessageRepository
|
||||
import util.Preferences
|
||||
import util.extensions.isImage
|
||||
@@ -51,8 +52,9 @@ import javax.inject.Singleton
|
||||
@Singleton
|
||||
class NotificationManagerImpl @Inject constructor(
|
||||
private val context: Context,
|
||||
private val prefs: Preferences,
|
||||
private val colors: Colors,
|
||||
private val conversationRepo: ConversationRepository,
|
||||
private val prefs: Preferences,
|
||||
private val messageRepo: MessageRepository
|
||||
) : manager.NotificationManager {
|
||||
|
||||
@@ -96,7 +98,7 @@ class NotificationManagerImpl @Inject constructor(
|
||||
return
|
||||
}
|
||||
|
||||
val conversation = messageRepo.getConversation(threadId) ?: return
|
||||
val conversation = conversationRepo.getConversation(threadId) ?: return
|
||||
|
||||
val contentIntent = Intent(context, ComposeActivity::class.java).putExtra("threadId", threadId)
|
||||
val taskStackBuilder = TaskStackBuilder.create(context)
|
||||
@@ -221,7 +223,7 @@ class NotificationManagerImpl @Inject constructor(
|
||||
return
|
||||
}
|
||||
|
||||
val conversation = messageRepo.getConversation(message.threadId) ?: return
|
||||
val conversation = conversationRepo.getConversation(message.threadId) ?: return
|
||||
val threadId = conversation.id
|
||||
|
||||
val contentIntent = Intent(context, ComposeActivity::class.java).putExtra("threadId", threadId)
|
||||
@@ -270,7 +272,7 @@ class NotificationManagerImpl @Inject constructor(
|
||||
// Only proceed if the android version supports notification channels
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return
|
||||
|
||||
messageRepo.getConversation(threadId)?.let { conversation ->
|
||||
conversationRepo.getConversation(threadId)?.let { conversation ->
|
||||
val channelId = buildNotificationChannelId(threadId)
|
||||
val name = conversation.getTitle()
|
||||
val importance = NotificationManager.IMPORTANCE_HIGH
|
||||
|
||||
@@ -26,21 +26,21 @@ import common.base.QkViewModel
|
||||
import interactor.MarkUnblocked
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.rxkotlin.withLatestFrom
|
||||
import repository.MessageRepository
|
||||
import repository.ConversationRepository
|
||||
import util.Preferences
|
||||
import util.tryOrNull
|
||||
import javax.inject.Inject
|
||||
|
||||
class BlockedViewModel @Inject constructor(
|
||||
private val context: Context,
|
||||
private val conversationRepo: ConversationRepository,
|
||||
private val markUnblocked: MarkUnblocked,
|
||||
private val messageRepo: MessageRepository,
|
||||
private val navigator: Navigator,
|
||||
private val prefs: Preferences
|
||||
) : QkViewModel<BlockedView, BlockedState>(BlockedState()) {
|
||||
|
||||
init {
|
||||
newState { copy(data = messageRepo.getBlockedConversations()) }
|
||||
newState { copy(data = conversationRepo.getBlockedConversations()) }
|
||||
|
||||
disposables += prefs.sia.asObservable()
|
||||
.subscribe { enabled -> newState { copy(siaEnabled = enabled) } }
|
||||
|
||||
@@ -56,6 +56,7 @@ import model.Message
|
||||
import model.PhoneNumber
|
||||
import model.Recipient
|
||||
import repository.ContactRepository
|
||||
import repository.ConversationRepository
|
||||
import repository.MessageRepository
|
||||
import util.ActiveSubscriptionObservable
|
||||
import util.extensions.asObservable
|
||||
@@ -78,6 +79,7 @@ class ComposeViewModel @Inject constructor(
|
||||
private val cancelMessage: CancelDelayedMessage,
|
||||
private val contactFilter: ContactFilter,
|
||||
private val contactsRepo: ContactRepository,
|
||||
private val conversationRepo: ConversationRepository,
|
||||
private val deleteMessages: DeleteMessages,
|
||||
private val markRead: MarkRead,
|
||||
private val messageRepo: MessageRepository,
|
||||
@@ -104,7 +106,7 @@ class ComposeViewModel @Inject constructor(
|
||||
|
||||
init {
|
||||
val initialConversation = threadId.takeIf { it != 0L }
|
||||
?.let(messageRepo::getConversationAsync)
|
||||
?.let(conversationRepo::getConversationAsync)
|
||||
?.asObservable()
|
||||
?: Observable.empty()
|
||||
|
||||
@@ -120,7 +122,7 @@ class ComposeViewModel @Inject constructor(
|
||||
.doOnNext { newState { copy(loading = false) } }
|
||||
.switchMap { (threadId, addresses) ->
|
||||
val recipients = RealmList(*addresses.map { address -> Recipient(address = address) }.toTypedArray())
|
||||
messageRepo.getConversations().asObservable()
|
||||
conversationRepo.getConversations().asObservable()
|
||||
.map { conversations -> conversations.filter { it.id == threadId } }
|
||||
.map { conversations ->
|
||||
conversations.firstOrNull() ?: Conversation(id = threadId, recipients = recipients)
|
||||
@@ -407,7 +409,7 @@ class ComposeViewModel @Inject constructor(
|
||||
.withLatestFrom(conversation, { _, conversation -> conversation.id })
|
||||
.observeOn(Schedulers.io())
|
||||
.withLatestFrom(view.textChangedIntent, { threadId, draft ->
|
||||
messageRepo.saveDraft(threadId, draft.toString())
|
||||
conversationRepo.saveDraft(threadId, draft.toString())
|
||||
})
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
@@ -533,7 +535,7 @@ class ComposeViewModel @Inject constructor(
|
||||
.map { number -> number.address }
|
||||
.forEach { addr ->
|
||||
val threadId = TelephonyCompat.getOrCreateThreadId(context, addr)
|
||||
val address = listOf(messageRepo.getConversation(threadId)?.recipients?.firstOrNull()?.address
|
||||
val address = listOf(conversationRepo.getConversation(threadId)?.recipients?.firstOrNull()?.address
|
||||
?: addr)
|
||||
sendMessage.execute(SendMessage.Params(subId, threadId, address, body, attachments))
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import io.reactivex.rxkotlin.withLatestFrom
|
||||
import io.reactivex.subjects.BehaviorSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import model.Conversation
|
||||
import repository.ConversationRepository
|
||||
import repository.MessageRepository
|
||||
import util.extensions.asObservable
|
||||
import javax.inject.Inject
|
||||
@@ -39,6 +40,7 @@ import javax.inject.Named
|
||||
|
||||
class ConversationInfoViewModel @Inject constructor(
|
||||
@Named("threadId") threadId: Long,
|
||||
private val conversationRepo: ConversationRepository,
|
||||
private val markArchived: MarkArchived,
|
||||
private val markUnarchived: MarkUnarchived,
|
||||
private val markBlocked: MarkBlocked,
|
||||
@@ -53,7 +55,7 @@ class ConversationInfoViewModel @Inject constructor(
|
||||
private val conversation: Subject<Conversation> = BehaviorSubject.create()
|
||||
|
||||
init {
|
||||
disposables += messageRepo.getConversationAsync(threadId)
|
||||
disposables += conversationRepo.getConversationAsync(threadId)
|
||||
.asObservable<Conversation>()
|
||||
.filter { conversation -> conversation.isLoaded }
|
||||
.doOnNext { conversation ->
|
||||
@@ -109,7 +111,7 @@ class ConversationInfoViewModel @Inject constructor(
|
||||
// Set the conversation title
|
||||
view.nameChangedIntent
|
||||
.withLatestFrom(conversation) { name, conversation ->
|
||||
messageRepo.setConversationName(conversation.id, name)
|
||||
conversationRepo.setConversationName(conversation.id, name)
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
@@ -29,6 +29,7 @@ import interactor.SaveImage
|
||||
import io.reactivex.Flowable
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.rxkotlin.withLatestFrom
|
||||
import repository.ConversationRepository
|
||||
import repository.MessageRepository
|
||||
import util.extensions.mapNotNull
|
||||
import javax.inject.Inject
|
||||
@@ -36,6 +37,7 @@ import javax.inject.Inject
|
||||
class GalleryViewModel @Inject constructor(
|
||||
private val intent: Intent,
|
||||
private val context: Context,
|
||||
private val conversationRepo: ConversationRepository,
|
||||
private val messageRepo: MessageRepository,
|
||||
private val saveImage: SaveImage
|
||||
) : QkViewModel<GalleryView, GalleryState>(GalleryState()) {
|
||||
@@ -51,7 +53,7 @@ class GalleryViewModel @Inject constructor(
|
||||
|
||||
disposables += partIdFlowable
|
||||
.mapNotNull { partId -> messageRepo.getMessageForPart(partId) }
|
||||
.mapNotNull { message -> messageRepo.getConversation(message.threadId) }
|
||||
.mapNotNull { message -> conversationRepo.getConversation(message.threadId) }
|
||||
.subscribe { conversation -> newState { copy(title = conversation.getTitle()) } }
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ import io.realm.Realm
|
||||
import manager.PermissionManager
|
||||
import manager.RatingManager
|
||||
import model.SyncLog
|
||||
import repository.ConversationRepository
|
||||
import repository.MessageRepository
|
||||
import repository.SyncRepository
|
||||
import util.extensions.removeAccents
|
||||
@@ -51,6 +52,7 @@ import javax.inject.Inject
|
||||
class MainViewModel @Inject constructor(
|
||||
private val messageRepo: MessageRepository,
|
||||
private val markAllSeen: MarkAllSeen,
|
||||
private val conversationRepo: ConversationRepository,
|
||||
private val deleteConversations: DeleteConversations,
|
||||
private val markRead: MarkRead,
|
||||
private val markUnread: MarkUnread,
|
||||
@@ -63,7 +65,7 @@ class MainViewModel @Inject constructor(
|
||||
private val ratingManager: RatingManager,
|
||||
private val syncMessages: SyncMessages,
|
||||
private val syncRepository: SyncRepository
|
||||
) : QkViewModel<MainView, MainState>(MainState(page = Inbox(data = messageRepo.getConversations()))) {
|
||||
) : QkViewModel<MainView, MainState>(MainState(page = Inbox(data = conversationRepo.getConversations()))) {
|
||||
|
||||
init {
|
||||
disposables += deleteConversations
|
||||
@@ -138,7 +140,7 @@ class MainViewModel @Inject constructor(
|
||||
.map { query -> query.removeAccents() }
|
||||
.withLatestFrom(state, { query, state ->
|
||||
if (query.isEmpty() && state.page is Searching) {
|
||||
newState { copy(page = Inbox(data = messageRepo.getConversations())) }
|
||||
newState { copy(page = Inbox(data = conversationRepo.getConversations())) }
|
||||
}
|
||||
query
|
||||
})
|
||||
@@ -150,7 +152,7 @@ class MainViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
.observeOn(Schedulers.io())
|
||||
.switchMap { query -> Observable.just(query).map { messageRepo.searchConversations(it) } }
|
||||
.switchMap { query -> Observable.just(query).map { conversationRepo.searchConversations(it) } }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { data -> newState { copy(page = Searching(loading = false, data = data)) } }
|
||||
|
||||
@@ -186,8 +188,8 @@ class MainViewModel @Inject constructor(
|
||||
.distinctUntilChanged()
|
||||
.doOnNext {
|
||||
when (it) {
|
||||
DrawerItem.INBOX -> newState { copy(page = Inbox(data = messageRepo.getConversations())) }
|
||||
DrawerItem.ARCHIVED -> newState { copy(page = Archived(data = messageRepo.getConversations(true))) }
|
||||
DrawerItem.INBOX -> newState { copy(page = Inbox(data = conversationRepo.getConversations())) }
|
||||
DrawerItem.ARCHIVED -> newState { copy(page = Archived(data = conversationRepo.getConversations(true))) }
|
||||
DrawerItem.SCHEDULED -> newState { copy(page = Scheduled()) }
|
||||
else -> {
|
||||
} // Do nothing
|
||||
@@ -244,7 +246,7 @@ class MainViewModel @Inject constructor(
|
||||
view.conversationsSelectedIntent
|
||||
.withLatestFrom(state, { selection, state ->
|
||||
val read = selection
|
||||
.mapNotNull(messageRepo::getConversation)
|
||||
.mapNotNull(conversationRepo::getConversation)
|
||||
.sumBy { if (it.read) -1 else 1 } >= 0
|
||||
val selected = selection.size
|
||||
|
||||
@@ -321,7 +323,7 @@ class MainViewModel @Inject constructor(
|
||||
|
||||
state.page is Archived && state.page.selected > 0 -> view.clearSelection()
|
||||
|
||||
state.page !is Inbox -> newState { copy(page = Inbox(data = messageRepo.getConversations())) }
|
||||
state.page !is Inbox -> newState { copy(page = Inbox(data = conversationRepo.getConversations())) }
|
||||
|
||||
else -> newState { copy(hasError = true) }
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ import common.base.QkViewModel
|
||||
import io.reactivex.Flowable
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import repository.MessageRepository
|
||||
import repository.ConversationRepository
|
||||
import util.Preferences
|
||||
import util.extensions.mapNotNull
|
||||
import javax.inject.Inject
|
||||
@@ -39,7 +39,7 @@ import javax.inject.Inject
|
||||
class NotificationPrefsViewModel @Inject constructor(
|
||||
private val intent: Intent,
|
||||
private val context: Context,
|
||||
private val messageRepo: MessageRepository,
|
||||
private val conversationRepo: ConversationRepository,
|
||||
private val navigator: Navigator,
|
||||
private val prefs: Preferences
|
||||
) : QkViewModel<NotificationPrefsView, NotificationPrefsState>(NotificationPrefsState()) {
|
||||
@@ -58,7 +58,7 @@ class NotificationPrefsViewModel @Inject constructor(
|
||||
ringtone = prefs.ringtone(threadId)
|
||||
|
||||
disposables += Flowable.just(threadId)
|
||||
.mapNotNull { threadId -> messageRepo.getConversation(threadId) }
|
||||
.mapNotNull { threadId -> conversationRepo.getConversation(threadId) }
|
||||
.map { conversation -> conversation.getTitle() }
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe { title -> newState { copy(conversationTitle = title) } }
|
||||
|
||||
@@ -36,6 +36,7 @@ import io.reactivex.subjects.Subject
|
||||
import io.realm.RealmResults
|
||||
import model.Conversation
|
||||
import model.Message
|
||||
import repository.ConversationRepository
|
||||
import repository.MessageRepository
|
||||
import util.ActiveSubscriptionObservable
|
||||
import util.extensions.asObservable
|
||||
@@ -46,6 +47,7 @@ import javax.inject.Named
|
||||
|
||||
class QkReplyViewModel @Inject constructor(
|
||||
@Named("threadId") threadId: Long,
|
||||
private val conversationRepo: ConversationRepository,
|
||||
private val markRead: MarkRead,
|
||||
private val messageRepo: MessageRepository,
|
||||
private val navigator: Navigator,
|
||||
@@ -54,7 +56,7 @@ class QkReplyViewModel @Inject constructor(
|
||||
) : QkViewModel<QkReplyView, QkReplyState>(QkReplyState()) {
|
||||
|
||||
private val conversation by lazy {
|
||||
messageRepo.getConversationAsync(threadId)
|
||||
conversationRepo.getConversationAsync(threadId)
|
||||
.asObservable<Conversation>()
|
||||
.filter { it.isLoaded }
|
||||
.filter { it.isValid }
|
||||
@@ -183,7 +185,7 @@ class QkReplyViewModel @Inject constructor(
|
||||
.map { draft -> draft.toString() }
|
||||
.observeOn(Schedulers.io())
|
||||
.withLatestFrom(conversation.map { it.id }, { draft, threadId ->
|
||||
messageRepo.saveDraft(threadId, draft)
|
||||
conversationRepo.saveDraft(threadId, draft)
|
||||
})
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
@@ -41,7 +41,7 @@ import injection.appComponent
|
||||
import model.Contact
|
||||
import model.Conversation
|
||||
import model.PhoneNumber
|
||||
import repository.MessageRepository
|
||||
import repository.ConversationRepository
|
||||
import util.Preferences
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -53,8 +53,8 @@ class WidgetAdapter(intent: Intent) : RemoteViewsService.RemoteViewsFactory {
|
||||
|
||||
@Inject lateinit var context: Context
|
||||
@Inject lateinit var colors: Colors
|
||||
@Inject lateinit var conversationRepo: ConversationRepository
|
||||
@Inject lateinit var dateFormatter: DateFormatter
|
||||
@Inject lateinit var messageRepo: MessageRepository
|
||||
@Inject lateinit var prefs: Preferences
|
||||
|
||||
private val appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID)
|
||||
@@ -83,7 +83,7 @@ class WidgetAdapter(intent: Intent) : RemoteViewsService.RemoteViewsFactory {
|
||||
}
|
||||
|
||||
override fun onDataSetChanged() {
|
||||
conversations = messageRepo.getConversationsSnapshot()
|
||||
conversations = conversationRepo.getConversationsSnapshot()
|
||||
|
||||
val remoteViews = RemoteViews(context.packageName, R.layout.widget)
|
||||
appWidgetManager.partiallyUpdateAppWidget(appWidgetId, remoteViews)
|
||||
|
||||
@@ -53,6 +53,8 @@ import mapper.CursorToRecipientImpl
|
||||
import mapper.RatingManagerImpl
|
||||
import repository.ContactRepository
|
||||
import repository.ContactRepositoryImpl
|
||||
import repository.ConversationRepository
|
||||
import repository.ConversationRepositoryImpl
|
||||
import repository.ImageRepository
|
||||
import repository.ImageRepostoryImpl
|
||||
import repository.MessageRepository
|
||||
@@ -128,6 +130,9 @@ class AppModule(private var application: Application) {
|
||||
@Provides
|
||||
fun provideContactRepository(repository: ContactRepositoryImpl): ContactRepository = repository
|
||||
|
||||
@Provides
|
||||
fun provideConversationRepository(repository: ConversationRepositoryImpl): ConversationRepository = repository
|
||||
|
||||
@Provides
|
||||
fun provideImageRepository(repository: ImageRepostoryImpl): ImageRepository = repository
|
||||
|
||||
|
||||
Reference in New Issue
Block a user