@@ -123,8 +123,8 @@ class NewMessageViewModel @Inject constructor(
123
123
// 3. When saving or sending the draft now, the channel still holds the previous body as it wasn't consumed.
124
124
// channelExpirationIdTarget lets us identify and discard outdated messages, ensuring the correct message is processed.
125
125
private var channelExpirationIdTarget = 0
126
- private val _subjectAndBodyChannel : Channel <Triple < String , String , Int > > = Channel (capacity = CONFLATED )
127
- private val subjectAndBodyChannel: ReceiveChannel <Triple < String , String , Int > > = _subjectAndBodyChannel
126
+ private val _subjectAndBodyChannel : Channel <SubjectAndBodyData > = Channel (capacity = CONFLATED )
127
+ private val subjectAndBodyChannel: ReceiveChannel <SubjectAndBodyData > = _subjectAndBodyChannel
128
128
private var subjectAndBodyJob: Job ? = null
129
129
130
130
var isAutoCompletionOpened = false
@@ -769,7 +769,7 @@ class NewMessageViewModel @Inject constructor(
769
769
770
770
fun saveBodyAndSubject (subject : String , html : String ) {
771
771
globalCoroutineScope.launch(ioDispatcher) {
772
- _subjectAndBodyChannel .send(Triple (subject, html, channelExpirationIdTarget))
772
+ _subjectAndBodyChannel .send(SubjectAndBodyData (subject, html, channelExpirationIdTarget))
773
773
}
774
774
}
775
775
@@ -783,6 +783,7 @@ class NewMessageViewModel @Inject constructor(
783
783
val subject: String
784
784
val body: String
785
785
while (true ) {
786
+ // receive() is a blocking call as long as it has no data
786
787
val (receivedSubject, receivedBody, expirationId) = subjectAndBodyChannel.receive()
787
788
if (expirationId == channelExpirationIdTarget) {
788
789
subject = receivedSubject
@@ -1009,6 +1010,8 @@ class NewMessageViewModel @Inject constructor(
1009
1010
val attachmentsLocalUuids : Set <String >,
1010
1011
)
1011
1012
1013
+ private data class SubjectAndBodyData (val subject : String , val body : String , val expirationId : Int )
1014
+
1012
1015
companion object {
1013
1016
private val TAG = NewMessageViewModel ::class .java.simpleName
1014
1017
private const val ATTACHMENTS_MAX_SIZE = 25L * 1_024L * 1_024L // 25 MB
0 commit comments