From cdcb2f274b669e9d3a325e1ace2008c8d236082b Mon Sep 17 00:00:00 2001 From: gavine99 Date: Wed, 12 Mar 2025 14:14:30 +1100 Subject: [PATCH] fix setting haserror (which is a bit misused to finish() the compose activity) when sending from a new convo as group. also fix associated bug that was sending sms to individual recipients in 'send as group mode' when send as group pref was saved as true --- .../QKSMS/feature/compose/ComposeActivity.kt | 5 ++--- .../moez/QKSMS/feature/compose/ComposeView.kt | 3 +-- .../QKSMS/feature/compose/ComposeViewModel.kt | 22 +++++++++---------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeActivity.kt b/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeActivity.kt index f8dd6dca..6606e6bc 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeActivity.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeActivity.kt @@ -187,8 +187,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView { override val viewQksmsPlusIntent: Subject = PublishSubject.create() override val backPressedIntent: Subject = PublishSubject.create() override val confirmDeleteIntent: Subject> = PublishSubject.create() - override val confirmClearCurrentMessageIntent: Subject = PublishSubject.create() - override val clearCurrentMessageIntent: Subject = PublishSubject.create() + override val clearCurrentMessageIntent: Subject = PublishSubject.create() override val messageLinkAskIntent: Subject by lazy { messageAdapter.messageLinkClicks } override val speechRecogniserIntent by lazy { speechToTextIcon.clicks() } override val shadeIntent by lazy { shadeBackground.clicks() } @@ -729,7 +728,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView { .setTitle(R.string.dialog_clear_compose_title) .setMessage(R.string.dialog_clear_compose) .setPositiveButton(R.string.button_clear) { _, _ -> - clearCurrentMessageIntent.onNext(Unit) + clearCurrentMessageIntent.onNext(false) } .setNegativeButton(R.string.button_cancel, null) .show() diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeView.kt b/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeView.kt index dac6193f..df615bc3 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeView.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeView.kt @@ -75,8 +75,7 @@ interface ComposeView : QkView { val viewQksmsPlusIntent: Subject val backPressedIntent: Observable val confirmDeleteIntent: Observable> - val confirmClearCurrentMessageIntent: Observable - val clearCurrentMessageIntent: Subject + val clearCurrentMessageIntent: Subject val messageLinkAskIntent: Observable val speechRecogniserIntent: Observable<*> val shadeIntent: Observable diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeViewModel.kt b/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeViewModel.kt index 5f80f98a..85f494e5 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeViewModel.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeViewModel.kt @@ -1028,7 +1028,9 @@ class ComposeViewModel @Inject constructor( true -> conversation.recipients.map { it.address } false -> chips.map { chip -> chip.address } } - val sendAsGroup = !state.editingMode || state.sendAsGroup + val sendAsGroup = ((addresses.size > 1) && // if more than one address to send to + (!state.editingMode || // and is not a new convo + state.sendAsGroup)) // or (is a new convo and) send as group is selected when { // Scheduling a message @@ -1073,8 +1075,13 @@ class ComposeViewModel @Inject constructor( } } - // clear the current message ready for new message composition - view.clearCurrentMessageIntent.onNext(Unit) + // clear the current message ready for new message composition (or finish() + // compose activity) + view.clearCurrentMessageIntent.onNext( + ((addresses.size > 1) && // if more than one address to send to + state.editingMode && // and is a new convo + !state.sendAsGroup) // and is *not* sent as a group + ) } .autoDisposable(view.scope()) .subscribe() @@ -1106,22 +1113,15 @@ class ComposeViewModel @Inject constructor( .autoDisposable(view.scope()) .subscribe { view.clearSelection() } - view.confirmClearCurrentMessageIntent - .autoDisposable(view.scope()) - .subscribe { view.clearCurrentMessageIntent.onNext(Unit) } - // clear the current message schedule, text and attachments view.clearCurrentMessageIntent - .withLatestFrom(state) { _, state -> state } .autoDisposable(view.scope()) .subscribe { view.setDraft("") - // if choosing contacts, don't remove attachments. they may have come from an - // external share newState { copy( editingMode = false, - hasError = !sendAsGroup, + hasError = it, // hasError being kinda misused to finish() compose activity attachments = listOf(), scheduled = 0, )