Conversation as field in Message

This commit is contained in:
Moez Bhatti
2018-03-27 17:19:07 -04:00
parent dd8fd3216d
commit 9c7ff3e6ea
16 changed files with 110 additions and 130 deletions
@@ -36,7 +36,7 @@ class ReceiveMms @Inject constructor(
override fun buildObservable(params: Uri): Flowable<*> {
return Flowable.just(params)
.flatMap { uri -> syncManager.syncMessage(uri) } // Sync the message
.mapNotNull { message -> messageRepo.getOrCreateConversation(message.threadId) } // Map message to conversation
.mapNotNull { message -> message.conversation } // 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
@@ -43,7 +43,7 @@ class ReceiveSms @Inject constructor(
messageRepo.insertReceivedSms(address, body, time) // Add the message to the db
}
.mapNotNull { message -> messageRepo.getOrCreateConversation(message.threadId) } // Map message to conversation
.mapNotNull { message -> message.conversation } // 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
@@ -19,6 +19,7 @@
package interactor
import io.reactivex.Flowable
import model.Conversation
import model.Message
import repository.MessageRepository
import javax.inject.Inject
@@ -32,7 +33,7 @@ class RetrySending @Inject constructor(private val messageRepo: MessageRepositor
val message = Message().apply {
id = params.id
type = params.type
threadId = params.threadId
conversation = params.conversation?.id?.let { threadId -> Conversation().apply { id = threadId } }
address = params.address
body = params.body
}
+15 -1
View File
@@ -32,12 +32,26 @@ open class Message : RealmObject() {
@PrimaryKey var id: Long = 0
var conversation: Conversation? = null
set(value) {
field = value
threadId = value?.id ?: 0
}
/**
* This is a hack so that we can index by the threadId, and return distinct threadIds when
* querying for all conversations for the MainActivity
*/
@Index
@Deprecated("This is only here for Realm to access - it should be ignored in our codebase")
var threadId: Long = 0
get() = conversation?.id ?: 0
// The MMS-SMS content provider returns messages where duplicate ids can exist. This is because
// SMS and MMS are stored in separate tables. We can't use these ids as our realm message id
// since it's our primary key for the single message object, so we'll store the original id in
// case we need to access the original message item in the content provider
var contentId: Long = 0
@Index var threadId: Long = 0
var address: String = ""
var boxId: Int = 0
var type: String = ""
@@ -28,9 +28,9 @@ import model.MmsPart
interface MessageRepository {
fun getConversations(archived: Boolean = false): Flowable<List<Pair<Conversation, Message>>>
fun getConversations(archived: Boolean = false): RealmResults<Message>
fun getConversationsForWidget(): List<Pair<Conversation, Message>>
fun getConversationsForWidget(): List<Message>
fun getBlockedConversations(): Flowable<List<Conversation>>