mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-18 20:08:53 +01:00
Create interactor for sending messages
This commit is contained in:
@@ -5,12 +5,14 @@ import android.arch.lifecycle.ViewModel
|
||||
import com.moez.QKSMS.common.di.AppComponentManager
|
||||
import com.moez.QKSMS.data.model.Conversation
|
||||
import com.moez.QKSMS.data.repository.MessageRepository
|
||||
import com.moez.QKSMS.domain.interactor.SendMessage
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import javax.inject.Inject
|
||||
|
||||
class MessageListViewModel : ViewModel() {
|
||||
|
||||
@Inject lateinit var messageRepo: MessageRepository
|
||||
@Inject lateinit var sendMessage: SendMessage
|
||||
|
||||
val state: MutableLiveData<MessageListViewState> = MutableLiveData()
|
||||
var threadId: Long = 0
|
||||
@@ -48,7 +50,7 @@ class MessageListViewModel : ViewModel() {
|
||||
|
||||
fun sendMessage(body: String) {
|
||||
conversation?.takeIf { conversation -> conversation.isValid }?.let { conversation ->
|
||||
messageRepo.sendMessage(threadId, conversation.contacts[0].address, body)
|
||||
sendMessage.execute({}, SendMessage.Params(threadId, conversation.contacts[0].address, body))
|
||||
partialStates.onNext(PartialState.TextChanged(""))
|
||||
}
|
||||
}
|
||||
@@ -63,6 +65,7 @@ class MessageListViewModel : ViewModel() {
|
||||
|
||||
override fun onCleared() {
|
||||
super.onCleared()
|
||||
sendMessage.dispose()
|
||||
conversation?.removeAllChangeListeners()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user