Skip to content

Commit ecd98bd

Browse files
committed
Refactor getSelectedAttachments in AttachmentsPickerViewModel
1 parent f37a77a commit ecd98bd

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/viewmodel/messages/AttachmentsPickerViewModel.kt

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,20 +185,17 @@ public class AttachmentsPickerViewModel(
185185
}
186186

187187
/**
188-
* Loads up the currently selected attachments and maps them to [Attachment] objects
189-
* based on their type.
188+
* Loads up the currently selected attachments and maps them to [Attachment] objects.
190189
*/
191-
public fun getSelectedAttachments(): List<Attachment> {
192-
val selectedAttachments = attachments.filter { it.isSelected }
193-
194-
return storageHelper.getAttachmentsForUpload(selectedAttachments.map { it.attachmentMetaData })
195-
}
190+
public fun getSelectedAttachments(): List<Attachment> =
191+
attachments.filter(AttachmentPickerItemState::isSelected)
192+
.map(AttachmentPickerItemState::attachmentMetaData)
193+
.let(storageHelper::getAttachmentsForUpload)
196194

197195
/**
198-
* Loads up the currently selected attachments. It uses the [attachmentsPickerMode] to know which
199-
* attachments to use - files or images.
196+
* Asynchronously loads up the currently selected attachments and maps them to [Attachment] objects.
200197
*
201-
* @param onComplete The callback passing the selected attachments.
198+
* @param onComplete The callback called when the attachments are loaded.
202199
*/
203200
internal fun getSelectedAttachmentsAsync(onComplete: (List<Attachment>) -> Unit) {
204201
viewModelScope.launch {

0 commit comments

Comments
 (0)