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
|
||||
) : Interactor<AddScheduledMessage.Params>() {
|
||||
|
||||
data class Params(val date: Long,
|
||||
val subId: Int,
|
||||
val recipients: List<String>,
|
||||
val sendAsGroup: Boolean,
|
||||
val body: String,
|
||||
val attachments: List<String>)
|
||||
data class Params(
|
||||
val date: Long,
|
||||
val subId: Int,
|
||||
val recipients: List<String>,
|
||||
val sendAsGroup: Boolean,
|
||||
val body: String,
|
||||
val attachments: List<String>
|
||||
)
|
||||
|
||||
override fun buildObservable(params: Params): Flowable<*> {
|
||||
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) }
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,9 @@ 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 { conversationRepo.updateConversations(it) } } // Update the conversation
|
||||
.doOnNext {
|
||||
params.threadId?.let { conversationRepo.updateConversations(it) } // Update the conversation
|
||||
}
|
||||
.doOnNext { params.threadId?.let { notificationManager.update(it) } }
|
||||
.flatMap { updateBadge.buildObservable(Unit) } // Update the badge
|
||||
}
|
||||
|
||||
@@ -58,10 +58,17 @@ class ReceiveMms @Inject constructor(
|
||||
if (blocked) messageRepo.deleteMessages(message.id)
|
||||
}
|
||||
}
|
||||
.doOnNext { message -> conversationRepo.updateConversations(message.threadId) } // Update the conversation
|
||||
.mapNotNull { message -> conversationRepo.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) 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
|
||||
.doOnNext(notificationManager::update) // Update the notification
|
||||
.flatMap { updateBadge.buildObservable(Unit) } // Update the badge
|
||||
|
||||
@@ -53,14 +53,21 @@ class ReceiveSms @Inject constructor(
|
||||
val time = messages[0].timestampMillis
|
||||
val body: String = messages
|
||||
.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
|
||||
}
|
||||
.doOnNext { message -> conversationRepo.updateConversations(message.threadId) } // Update the conversation
|
||||
.mapNotNull { message -> conversationRepo.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) 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
|
||||
.doOnNext { threadId -> notificationManager.update(threadId) } // Update the notification
|
||||
.doOnNext { shortcutManager.updateShortcuts() } // Update shortcuts
|
||||
|
||||
@@ -21,14 +21,12 @@ package com.moez.QKSMS.interactor
|
||||
import com.moez.QKSMS.model.Attachment
|
||||
import com.moez.QKSMS.repository.ConversationRepository
|
||||
import com.moez.QKSMS.repository.MessageRepository
|
||||
import com.moez.QKSMS.repository.SyncRepository
|
||||
import io.reactivex.Flowable
|
||||
import javax.inject.Inject
|
||||
|
||||
class SendMessage @Inject constructor(
|
||||
private val conversationRepo: ConversationRepository,
|
||||
private val messageRepo: MessageRepository,
|
||||
private val syncRepo: SyncRepository
|
||||
private val messageRepo: MessageRepository
|
||||
) : Interactor<SendMessage.Params>() {
|
||||
|
||||
data class Params(
|
||||
@@ -37,11 +35,15 @@ class SendMessage @Inject constructor(
|
||||
val addresses: List<String>,
|
||||
val body: String,
|
||||
val attachments: List<Attachment> = listOf(),
|
||||
val delay: Int = 0)
|
||||
val delay: Int = 0
|
||||
)
|
||||
|
||||
override fun buildObservable(params: Params): Flowable<*> = Flowable.just(Unit)
|
||||
.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 {
|
||||
// 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
|
||||
|
||||
@@ -34,7 +34,9 @@ class UpdateScheduledMessageAlarms @Inject constructor(
|
||||
.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
|
||||
.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
|
||||
.flatMap { (id, _) -> sendScheduledMessage.buildObservable(id) } // Send them
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user