forked from upstream-mirrors/quik
Format domain module
This commit is contained in:
@@ -27,16 +27,21 @@ class AddScheduledMessage @Inject constructor(
|
|||||||
private val updateScheduledMessageAlarms: UpdateScheduledMessageAlarms
|
private val updateScheduledMessageAlarms: UpdateScheduledMessageAlarms
|
||||||
) : Interactor<AddScheduledMessage.Params>() {
|
) : Interactor<AddScheduledMessage.Params>() {
|
||||||
|
|
||||||
data class Params(val date: Long,
|
data class Params(
|
||||||
val subId: Int,
|
val date: Long,
|
||||||
val recipients: List<String>,
|
val subId: Int,
|
||||||
val sendAsGroup: Boolean,
|
val recipients: List<String>,
|
||||||
val body: String,
|
val sendAsGroup: Boolean,
|
||||||
val attachments: List<String>)
|
val body: String,
|
||||||
|
val attachments: List<String>
|
||||||
|
)
|
||||||
|
|
||||||
override fun buildObservable(params: Params): Flowable<*> {
|
override fun buildObservable(params: Params): Flowable<*> {
|
||||||
return Flowable.just(params)
|
return Flowable.just(params)
|
||||||
.map { scheduledMessageRepo.saveScheduledMessage(it.date, it.subId, it.recipients, it.sendAsGroup, it.body, it.attachments) }
|
.map {
|
||||||
|
scheduledMessageRepo.saveScheduledMessage(it.date, it.subId, it.recipients, it.sendAsGroup, it.body,
|
||||||
|
it.attachments)
|
||||||
|
}
|
||||||
.flatMap { updateScheduledMessageAlarms.buildObservable(Unit) }
|
.flatMap { updateScheduledMessageAlarms.buildObservable(Unit) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,9 @@ class DeleteMessages @Inject constructor(
|
|||||||
override fun buildObservable(params: Params): Flowable<*> {
|
override fun buildObservable(params: Params): Flowable<*> {
|
||||||
return Flowable.just(params.messageIds.toLongArray())
|
return Flowable.just(params.messageIds.toLongArray())
|
||||||
.doOnNext { messageIds -> messageRepo.deleteMessages(*messageIds) } // Delete the messages
|
.doOnNext { messageIds -> messageRepo.deleteMessages(*messageIds) } // Delete the messages
|
||||||
.doOnNext { params.threadId?.let { conversationRepo.updateConversations(it) } } // Update the conversation
|
.doOnNext {
|
||||||
|
params.threadId?.let { conversationRepo.updateConversations(it) } // Update the conversation
|
||||||
|
}
|
||||||
.doOnNext { params.threadId?.let { notificationManager.update(it) } }
|
.doOnNext { params.threadId?.let { notificationManager.update(it) } }
|
||||||
.flatMap { updateBadge.buildObservable(Unit) } // Update the badge
|
.flatMap { updateBadge.buildObservable(Unit) } // Update the badge
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,10 +58,17 @@ class ReceiveMms @Inject constructor(
|
|||||||
if (blocked) messageRepo.deleteMessages(message.id)
|
if (blocked) messageRepo.deleteMessages(message.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.doOnNext { message -> conversationRepo.updateConversations(message.threadId) } // Update the conversation
|
.doOnNext { message ->
|
||||||
.mapNotNull { message -> conversationRepo.getOrCreateConversation(message.threadId) } // Map message to conversation
|
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
|
.filter { conversation -> !conversation.blocked } // Don't notify for blocked conversations
|
||||||
.doOnNext { conversation -> if (conversation.archived) conversationRepo.markUnarchived(conversation.id) } // Unarchive conversation if necessary
|
.doOnNext { conversation ->
|
||||||
|
// Unarchive conversation if necessary
|
||||||
|
if (conversation.archived) conversationRepo.markUnarchived(conversation.id)
|
||||||
|
}
|
||||||
.map { conversation -> conversation.id } // Map to the id because [delay] will put us on the wrong thread
|
.map { conversation -> conversation.id } // Map to the id because [delay] will put us on the wrong thread
|
||||||
.doOnNext(notificationManager::update) // Update the notification
|
.doOnNext(notificationManager::update) // Update the notification
|
||||||
.flatMap { updateBadge.buildObservable(Unit) } // Update the badge
|
.flatMap { updateBadge.buildObservable(Unit) } // Update the badge
|
||||||
|
|||||||
@@ -53,14 +53,21 @@ class ReceiveSms @Inject constructor(
|
|||||||
val time = messages[0].timestampMillis
|
val time = messages[0].timestampMillis
|
||||||
val body: String = messages
|
val body: String = messages
|
||||||
.mapNotNull { message -> message.displayMessageBody }
|
.mapNotNull { message -> message.displayMessageBody }
|
||||||
.reduce { body, new -> body + new } ?: ""
|
.reduce { body, new -> body + new }
|
||||||
|
|
||||||
messageRepo.insertReceivedSms(it.subId, address, body, time) // Add the message to the db
|
messageRepo.insertReceivedSms(it.subId, address, body, time) // Add the message to the db
|
||||||
}
|
}
|
||||||
.doOnNext { message -> conversationRepo.updateConversations(message.threadId) } // Update the conversation
|
.doOnNext { message ->
|
||||||
.mapNotNull { message -> conversationRepo.getOrCreateConversation(message.threadId) } // Map message to conversation
|
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
|
.filter { conversation -> !conversation.blocked } // Don't notify for blocked conversations
|
||||||
.doOnNext { conversation -> if (conversation.archived) conversationRepo.markUnarchived(conversation.id) } // Unarchive conversation if necessary
|
.doOnNext { conversation ->
|
||||||
|
// Unarchive conversation if necessary
|
||||||
|
if (conversation.archived) conversationRepo.markUnarchived(conversation.id)
|
||||||
|
}
|
||||||
.map { conversation -> conversation.id } // Map to the id because [delay] will put us on the wrong thread
|
.map { conversation -> conversation.id } // Map to the id because [delay] will put us on the wrong thread
|
||||||
.doOnNext { threadId -> notificationManager.update(threadId) } // Update the notification
|
.doOnNext { threadId -> notificationManager.update(threadId) } // Update the notification
|
||||||
.doOnNext { shortcutManager.updateShortcuts() } // Update shortcuts
|
.doOnNext { shortcutManager.updateShortcuts() } // Update shortcuts
|
||||||
|
|||||||
@@ -21,14 +21,12 @@ package com.moez.QKSMS.interactor
|
|||||||
import com.moez.QKSMS.model.Attachment
|
import com.moez.QKSMS.model.Attachment
|
||||||
import com.moez.QKSMS.repository.ConversationRepository
|
import com.moez.QKSMS.repository.ConversationRepository
|
||||||
import com.moez.QKSMS.repository.MessageRepository
|
import com.moez.QKSMS.repository.MessageRepository
|
||||||
import com.moez.QKSMS.repository.SyncRepository
|
|
||||||
import io.reactivex.Flowable
|
import io.reactivex.Flowable
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class SendMessage @Inject constructor(
|
class SendMessage @Inject constructor(
|
||||||
private val conversationRepo: ConversationRepository,
|
private val conversationRepo: ConversationRepository,
|
||||||
private val messageRepo: MessageRepository,
|
private val messageRepo: MessageRepository
|
||||||
private val syncRepo: SyncRepository
|
|
||||||
) : Interactor<SendMessage.Params>() {
|
) : Interactor<SendMessage.Params>() {
|
||||||
|
|
||||||
data class Params(
|
data class Params(
|
||||||
@@ -37,11 +35,15 @@ class SendMessage @Inject constructor(
|
|||||||
val addresses: List<String>,
|
val addresses: List<String>,
|
||||||
val body: String,
|
val body: String,
|
||||||
val attachments: List<Attachment> = listOf(),
|
val attachments: List<Attachment> = listOf(),
|
||||||
val delay: Int = 0)
|
val delay: Int = 0
|
||||||
|
)
|
||||||
|
|
||||||
override fun buildObservable(params: Params): Flowable<*> = Flowable.just(Unit)
|
override fun buildObservable(params: Params): Flowable<*> = Flowable.just(Unit)
|
||||||
.filter { params.addresses.isNotEmpty() }
|
.filter { params.addresses.isNotEmpty() }
|
||||||
.doOnNext { messageRepo.sendMessage(params.subId, params.threadId, params.addresses, params.body, params.attachments, params.delay) }
|
.doOnNext {
|
||||||
|
messageRepo.sendMessage(params.subId, params.threadId, params.addresses, params.body,
|
||||||
|
params.attachments, params.delay)
|
||||||
|
}
|
||||||
.map {
|
.map {
|
||||||
// On some manufacturers, we can't obtain a threadId for a new conversation. In
|
// On some manufacturers, we can't obtain a threadId for a new conversation. In
|
||||||
// this case, find the threadId manually now that it contains a message
|
// this case, find the threadId manually now that it contains a message
|
||||||
|
|||||||
@@ -34,7 +34,9 @@ class UpdateScheduledMessageAlarms @Inject constructor(
|
|||||||
.map { scheduledMessageRepo.getScheduledMessages() } // Get all the scheduled messages
|
.map { scheduledMessageRepo.getScheduledMessages() } // Get all the scheduled messages
|
||||||
.map { it.map { message -> Pair(message.id, message.date) } } // Map the data we need out of Realm
|
.map { it.map { message -> Pair(message.id, message.date) } } // Map the data we need out of Realm
|
||||||
.flatMap { messages -> Flowable.fromIterable(messages) } // Turn the list into a stream
|
.flatMap { messages -> Flowable.fromIterable(messages) } // Turn the list into a stream
|
||||||
.doOnNext { (id, date) -> alarmManager.setAlarm(date, alarmManager.getScheduledMessageIntent(id)) } // Create alarm
|
.doOnNext { (id, date) ->
|
||||||
|
alarmManager.setAlarm(date, alarmManager.getScheduledMessageIntent(id)) // Create alarm
|
||||||
|
}
|
||||||
.filter { (_, date) -> date < System.currentTimeMillis() } // Filter messages that should have already been sent
|
.filter { (_, date) -> date < System.currentTimeMillis() } // Filter messages that should have already been sent
|
||||||
.flatMap { (id, _) -> sendScheduledMessage.buildObservable(id) } // Send them
|
.flatMap { (id, _) -> sendScheduledMessage.buildObservable(id) } // Send them
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,4 +51,4 @@ sealed class Attachment {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Attachments(attachments: List<Attachment>): List<Attachment> by attachments
|
class Attachments(attachments: List<Attachment>) : List<Attachment> by attachments
|
||||||
|
|||||||
@@ -36,8 +36,7 @@ open class Conversation(
|
|||||||
var me: Boolean = false,
|
var me: Boolean = false,
|
||||||
var draft: String = "",
|
var draft: String = "",
|
||||||
|
|
||||||
// For group chats, the user is allowed to set a custom title for the conversation
|
var name: String = "" // For group chats, the user is allowed to set a custom title for the conversation
|
||||||
var name: String = ""
|
|
||||||
) : RealmObject() {
|
) : RealmObject() {
|
||||||
|
|
||||||
fun getTitle(): String {
|
fun getTitle(): String {
|
||||||
|
|||||||
@@ -32,13 +32,15 @@ open class ScheduledMessage(
|
|||||||
var attachments: RealmList<String> = RealmList()
|
var attachments: RealmList<String> = RealmList()
|
||||||
) : RealmObject() {
|
) : RealmObject() {
|
||||||
|
|
||||||
fun copy(id: Long = this.id,
|
fun copy(
|
||||||
date: Long = this.date,
|
id: Long = this.id,
|
||||||
subId: Int = this.subId,
|
date: Long = this.date,
|
||||||
recipients: RealmList<String> = this.recipients,
|
subId: Int = this.subId,
|
||||||
sendAsGroup: Boolean = this.sendAsGroup,
|
recipients: RealmList<String> = this.recipients,
|
||||||
body: String = this.body,
|
sendAsGroup: Boolean = this.sendAsGroup,
|
||||||
attachments: RealmList<String> = this.attachments): ScheduledMessage {
|
body: String = this.body,
|
||||||
|
attachments: RealmList<String> = this.attachments
|
||||||
|
): ScheduledMessage {
|
||||||
|
|
||||||
return ScheduledMessage(id, date, subId, recipients, sendAsGroup, body, attachments)
|
return ScheduledMessage(id, date, subId, recipients, sendAsGroup, body, attachments)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,14 @@ interface MessageRepository {
|
|||||||
|
|
||||||
fun markUnread(vararg threadIds: Long)
|
fun markUnread(vararg threadIds: Long)
|
||||||
|
|
||||||
fun sendMessage(subId: Int, threadId: Long, addresses: List<String>, body: String, attachments: List<Attachment>, delay: Int = 0)
|
fun sendMessage(
|
||||||
|
subId: Int,
|
||||||
|
threadId: Long,
|
||||||
|
addresses: List<String>,
|
||||||
|
body: String,
|
||||||
|
attachments: List<Attachment>,
|
||||||
|
delay: Int = 0
|
||||||
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to send the SMS message. This can be called if the message has already been persisted
|
* Attempts to send the SMS message. This can be called if the message has already been persisted
|
||||||
|
|||||||
@@ -26,8 +26,14 @@ interface ScheduledMessageRepository {
|
|||||||
/**
|
/**
|
||||||
* Saves a scheduled message
|
* Saves a scheduled message
|
||||||
*/
|
*/
|
||||||
fun saveScheduledMessage(date: Long, subId: Int, recipients: List<String>, sendAsGroup: Boolean, body: String,
|
fun saveScheduledMessage(
|
||||||
attachments: List<String>)
|
date: Long,
|
||||||
|
subId: Int,
|
||||||
|
recipients: List<String>,
|
||||||
|
sendAsGroup: Boolean,
|
||||||
|
body: String,
|
||||||
|
attachments: List<String>
|
||||||
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all of the scheduled messages, sorted chronologically
|
* Returns all of the scheduled messages, sorted chronologically
|
||||||
|
|||||||
Reference in New Issue
Block a user