mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-16 02:58:52 +01:00
Update newState signature to not require calling it.copy()
This commit is contained in:
@@ -121,12 +121,12 @@ class ComposeViewModel @Inject constructor(
|
||||
|
||||
val initialConversation: Observable<Conversation> = when {
|
||||
threadId != 0L -> {
|
||||
newState { it.copy(selectedConversation = threadId, editingMode = false) }
|
||||
newState { copy(selectedConversation = threadId, editingMode = false) }
|
||||
messageRepo.getConversationAsync(threadId).asObservable()
|
||||
}
|
||||
|
||||
address.isNotBlank() -> {
|
||||
newState { it.copy(editingMode = false) }
|
||||
newState { copy(editingMode = false) }
|
||||
Observable.just(address)
|
||||
.mapNotNull { messageRepo.getOrCreateConversation(it) }
|
||||
.subscribeOn(Schedulers.io())
|
||||
@@ -134,14 +134,14 @@ class ComposeViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
else -> {
|
||||
newState { it.copy(editingMode = true) }
|
||||
newState { copy(editingMode = true) }
|
||||
Observable.empty()
|
||||
}
|
||||
}
|
||||
|
||||
selectedContacts = contactsReducer
|
||||
.scan(listOf<Contact>(), { previousState, reducer -> reducer(previousState) })
|
||||
.doOnNext { contacts -> newState { it.copy(selectedContacts = contacts) } }
|
||||
.doOnNext { contacts -> newState { copy(selectedContacts = contacts) } }
|
||||
|
||||
// Merges two potential conversation sources (threadId from constructor and contact selection) into a single
|
||||
// stream of conversations. If the conversation was deleted, notify the activity to shut down
|
||||
@@ -154,7 +154,7 @@ class ComposeViewModel @Inject constructor(
|
||||
.filter { conversation -> conversation.isLoaded }
|
||||
.doOnNext { conversation ->
|
||||
if (!conversation.isValid) {
|
||||
newState { it.copy(hasError = true) }
|
||||
newState { copy(hasError = true) }
|
||||
}
|
||||
}
|
||||
.filter { conversation -> conversation.isValid }
|
||||
@@ -168,7 +168,7 @@ class ComposeViewModel @Inject constructor(
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.map { conversation ->
|
||||
val messages = messageRepo.getMessages(conversation.id)
|
||||
newState { it.copy(selectedConversation = conversation.id, messages = Pair(conversation, messages)) }
|
||||
newState { copy(selectedConversation = conversation.id, messages = Pair(conversation, messages)) }
|
||||
messages
|
||||
}
|
||||
.switchMap { messages -> messages.asObservable() }
|
||||
@@ -177,10 +177,10 @@ class ComposeViewModel @Inject constructor(
|
||||
disposables += conversation
|
||||
.map { conversation -> conversation.getTitle() }
|
||||
.distinctUntilChanged()
|
||||
.subscribe { title -> newState { it.copy(conversationtitle = title) } }
|
||||
.subscribe { title -> newState { copy(conversationtitle = title) } }
|
||||
|
||||
disposables += attachments
|
||||
.subscribe { attachments -> newState { it.copy(attachments = attachments) } }
|
||||
.subscribe { attachments -> newState { copy(attachments = attachments) } }
|
||||
|
||||
disposables += conversation
|
||||
.map { conversation -> conversation.id }
|
||||
@@ -197,7 +197,7 @@ class ComposeViewModel @Inject constructor(
|
||||
messages.lastOrNull()?.let { message -> searchSelection.onNext(message.id) }
|
||||
} else {
|
||||
val position = messages.indexOfFirst { it.id == selected } + 1
|
||||
newState { it.copy(searchSelectionPosition = position, searchResults = messages.size) }
|
||||
newState { copy(searchSelectionPosition = position, searchResults = messages.size) }
|
||||
}
|
||||
}.subscribe()
|
||||
|
||||
@@ -207,7 +207,7 @@ class ComposeViewModel @Inject constructor(
|
||||
|
||||
disposables += Observables.combineLatest(latestSubId, subUtils.subscriptionsObservable) { subId, subs ->
|
||||
val sub = if (subs.size > 1) subs.firstOrNull { it.subscriptionId == subId } ?: subs[0] else null
|
||||
newState { it.copy(subscription = sub) }
|
||||
newState { copy(subscription = sub) }
|
||||
}.subscribe()
|
||||
|
||||
if (threadId == 0L) {
|
||||
@@ -228,7 +228,7 @@ class ComposeViewModel @Inject constructor(
|
||||
.takeUntil(state.filter { state -> !state.editingMode })
|
||||
.distinctUntilChanged()
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { contactsVisible -> newState { it.copy(contactsVisible = contactsVisible && it.editingMode) } }
|
||||
.subscribe { contactsVisible -> newState { copy(contactsVisible = contactsVisible && editingMode) } }
|
||||
|
||||
// Update the list of contact suggestions based on the query input, while also filtering out any contacts
|
||||
// that have already been selected
|
||||
@@ -257,7 +257,7 @@ class ComposeViewModel @Inject constructor(
|
||||
.takeUntil(state.filter { state -> !state.editingMode })
|
||||
.subscribeOn(Schedulers.computation())
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { contacts -> newState { it.copy(contacts = contacts) } }
|
||||
.subscribe { contacts -> newState { copy(contacts = contacts) } }
|
||||
|
||||
// Backspaces should delete the most recent contact if there's no text input
|
||||
// Close the activity if user presses back
|
||||
@@ -297,7 +297,7 @@ class ComposeViewModel @Inject constructor(
|
||||
// When the menu is loaded, trigger a new state so that the menu options can be rendered correctly
|
||||
view.menuReadyIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { it.copy() } }
|
||||
.subscribe { newState { copy() } }
|
||||
|
||||
// Open the phone dialer if the call button is clicked
|
||||
view.optionsItemIntent
|
||||
@@ -379,19 +379,19 @@ class ComposeViewModel @Inject constructor(
|
||||
view.optionsItemIntent
|
||||
.filter { it == R.id.clear }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { it.copy(query = "", searchSelectionId = -1) } }
|
||||
.subscribe { newState { copy(query = "", searchSelectionId = -1) } }
|
||||
|
||||
|
||||
// Toggle the group sending mode
|
||||
view.sendAsGroupIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { it.copy(sendAsGroup = !it.sendAsGroup) } }
|
||||
.subscribe { newState { copy(sendAsGroup = !sendAsGroup) } }
|
||||
|
||||
|
||||
// Scroll to search position
|
||||
searchSelection
|
||||
.filter { id -> id != -1L }
|
||||
.doOnNext { id -> newState { it.copy(searchSelectionId = id) } }
|
||||
.doOnNext { id -> newState { copy(searchSelectionId = id) } }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe(view::scrollToMessage)
|
||||
|
||||
@@ -407,7 +407,7 @@ class ComposeViewModel @Inject constructor(
|
||||
view.messagesSelectedIntent
|
||||
.map { selection -> selection.size }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { messages -> newState { it.copy(selectedMessages = messages, editingMode = false) } }
|
||||
.subscribe { messages -> newState { copy(selectedMessages = messages, editingMode = false) } }
|
||||
|
||||
// Cancel sending a message
|
||||
view.cancelSendingIntent
|
||||
@@ -438,7 +438,7 @@ class ComposeViewModel @Inject constructor(
|
||||
// Open the attachment options
|
||||
view.attachIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { it.copy(attaching = !it.attaching) } }
|
||||
.subscribe { newState { copy(attaching = !attaching) } }
|
||||
|
||||
// Attach a photo from camera
|
||||
view.cameraIntent
|
||||
@@ -462,7 +462,7 @@ class ComposeViewModel @Inject constructor(
|
||||
.withLatestFrom(attachments, { attachment, attachments -> attachments + attachment })
|
||||
.doOnNext { attachments.onNext(it) }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { it.copy(attaching = false) } }
|
||||
.subscribe { newState { copy(attaching = false) } }
|
||||
|
||||
// Detach a photo
|
||||
view.attachmentDeletedIntent
|
||||
@@ -494,7 +494,7 @@ class ComposeViewModel @Inject constructor(
|
||||
text.isNotBlank() || attachments.isNotEmpty()
|
||||
})
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { canSend -> newState { it.copy(canSend = canSend) } }
|
||||
.subscribe { canSend -> newState { copy(canSend = canSend) } }
|
||||
|
||||
// Show the remaining character counter when necessary
|
||||
view.textChangedIntent
|
||||
@@ -512,7 +512,7 @@ class ComposeViewModel @Inject constructor(
|
||||
}
|
||||
.distinctUntilChanged()
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { remaining -> newState { it.copy(remaining = remaining) } }
|
||||
.subscribe { remaining -> newState { copy(remaining = remaining) } }
|
||||
|
||||
// Toggle to the next sim slot
|
||||
view.changeSimIntent
|
||||
@@ -524,7 +524,7 @@ class ComposeViewModel @Inject constructor(
|
||||
subIndex < subs.size - 1 -> subs[subIndex + 1]
|
||||
else -> subs[0]
|
||||
}
|
||||
newState { it.copy(subscription = subscription) }
|
||||
newState { copy(subscription = subscription) }
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
@@ -557,7 +557,7 @@ class ComposeViewModel @Inject constructor(
|
||||
this.attachments.onNext(ArrayList())
|
||||
|
||||
if (state.editingMode) {
|
||||
newState { it.copy(editingMode = false, sendAsGroup = true, hasError = !state.sendAsGroup) }
|
||||
newState { copy(editingMode = false, sendAsGroup = true, hasError = !state.sendAsGroup) }
|
||||
}
|
||||
})
|
||||
.autoDisposable(view.scope())
|
||||
@@ -571,7 +571,7 @@ class ComposeViewModel @Inject constructor(
|
||||
.withLatestFrom(state, { _, state ->
|
||||
when {
|
||||
state.selectedMessages > 0 -> view.clearSelection()
|
||||
else -> newState { it.copy(hasError = true) }
|
||||
else -> newState { copy(hasError = true) }
|
||||
}
|
||||
})
|
||||
.autoDisposable(view.scope())
|
||||
|
||||
Reference in New Issue
Block a user