mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-16 02:58:52 +01:00
Remove link between messages and conversations
This commit is contained in:
@@ -23,13 +23,18 @@ import repository.MessageRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
class DeleteMessage @Inject constructor(
|
||||
private val messageRepository: MessageRepository,
|
||||
private val messageRepo: MessageRepository,
|
||||
private val updateBadge: UpdateBadge
|
||||
) : Interactor<Long>() {
|
||||
|
||||
override fun buildObservable(params: Long): Flowable<*> {
|
||||
return Flowable.just(params)
|
||||
.doOnNext { messageId -> messageRepository.deleteMessage(messageId) }
|
||||
.doOnNext { messageId ->
|
||||
val threadId = messageRepo.getMessage(messageId)?.threadId
|
||||
messageRepo.deleteMessage(messageId)
|
||||
threadId?.let { messageRepo.updateConversation(it) }
|
||||
}
|
||||
.doOnNext { messageRepo.updateConversation(params) } // Update the conversation
|
||||
.flatMap { updateBadge.buildObservable(Unit) } // Update the badge
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ class MarkRead @Inject constructor(
|
||||
override fun buildObservable(params: Long): Flowable<*> {
|
||||
return Flowable.just(Unit)
|
||||
.doOnNext { messageRepo.markRead(params) }
|
||||
.doOnNext { messageRepo.updateConversation(params) } // Update the conversation
|
||||
.doOnNext { notificationManager.update(params) }
|
||||
.flatMap { updateBadge.buildObservable(Unit) } // Update the badge
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import manager.NotificationManager
|
||||
import repository.MessageRepository
|
||||
import repository.SyncRepository
|
||||
import util.extensions.mapNotNull
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
|
||||
class ReceiveMms @Inject constructor(
|
||||
@@ -36,10 +37,13 @@ class ReceiveMms @Inject constructor(
|
||||
override fun buildObservable(params: Uri): Flowable<*> {
|
||||
return Flowable.just(params)
|
||||
.flatMap { uri -> syncManager.syncMessage(uri) } // Sync the message
|
||||
.mapNotNull { message -> message.conversation } // Map message to conversation
|
||||
.doOnNext { message -> messageRepo.updateConversation(message.threadId) } // Update the conversation
|
||||
.mapNotNull { message -> messageRepo.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 -> notificationManager.update(conversation.id) } // Update the notification
|
||||
.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
|
||||
.flatMap { updateBadge.buildObservable(Unit) } // Update the badge
|
||||
}
|
||||
|
||||
|
||||
@@ -44,11 +44,13 @@ class ReceiveSms @Inject constructor(
|
||||
|
||||
messageRepo.insertReceivedSms(address, body, time) // Add the message to the db
|
||||
}
|
||||
.mapNotNull { message -> message.conversation } // Map message to conversation
|
||||
.doOnNext { message -> messageRepo.updateConversation(message.threadId) } // Update the conversation
|
||||
.mapNotNull { message -> messageRepo.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
|
||||
.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 { conversation -> notificationManager.update(conversation.id) } // Update the notification
|
||||
.doOnNext { threadId -> notificationManager.update(threadId) } // Update the notification
|
||||
.flatMap { updateBadge.buildObservable(Unit) } // Update the badge
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ class UpdateBadge @Inject constructor(
|
||||
|
||||
override fun buildObservable(params: Unit): Flowable<*> {
|
||||
return Flowable.just(params)
|
||||
.map { messageRepo.getUnreadMessageCount() }
|
||||
.map { messageRepo.getUnreadCount() }
|
||||
.map { count -> count.toInt() }
|
||||
.doOnNext { count -> widgetManager.updateUnreadCount(count) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user