Skip to content

Commit

Permalink
allow sending attachments without message text
Browse files Browse the repository at this point in the history
  • Loading branch information
migulyaev committed Oct 1, 2023
1 parent fa2e8dc commit 0088554
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ class ComposeNewMessageViewModel @Inject constructor(
add(attachmentInfoConverter.convert(file))
}
}
_uiState.update {
it.copy(
isSendButtonEnabled = isSendButtonEnabled(uiState.value.recipientAccountId, it.messageText),
)
}
}
}

Expand All @@ -106,6 +111,11 @@ class ComposeNewMessageViewModel @Inject constructor(
_attachments.update {
it.filter { it.fileId != attachmentInfo.fileId }
}
_uiState.update {
it.copy(
isSendButtonEnabled = isSendButtonEnabled(uiState.value.recipientAccountId, it.messageText),
)
}
}
}

Expand Down Expand Up @@ -246,7 +256,7 @@ class ComposeNewMessageViewModel @Inject constructor(
recipientAccountId: String,
messageText: String,
): Boolean {
return contacts.any { recipientAccountId == it.contactVeraId } && messageText.isNotEmptyOrBlank()
return contacts.any { recipientAccountId == it.contactVeraId } && (messageText.isNotEmptyOrBlank() || attachedFiles.isNotEmpty())
}

@IntDef(NEW_CONVERSATION, REPLY_TO_EXISTING_CONVERSATION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import tech.relaycorp.letro.ui.theme.BodyLargeProminent
import tech.relaycorp.letro.ui.theme.BodyMediumProminent
import tech.relaycorp.letro.ui.theme.LabelSmallProminent
import tech.relaycorp.letro.ui.utils.ConversationsStringsProvider
import tech.relaycorp.letro.utils.ext.isNotEmptyOrBlank
import java.util.UUID

@Composable
Expand Down Expand Up @@ -183,8 +184,9 @@ private fun Conversation(
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
val messageDisplayedText = if (conversation.messages.last().text.isNotEmptyOrBlank()) conversation.messages.last().text else conversation.messages.last().attachments.firstOrNull()?.name ?: ""
Text(
text = conversation.messages.last().text,
text = messageDisplayedText,
style = if (!conversation.isRead) MaterialTheme.typography.BodyMediumProminent else MaterialTheme.typography.bodyMedium,
color = if (!conversation.isRead) MaterialTheme.colorScheme.onSurface else MaterialTheme.colorScheme.onSurfaceVariant,
maxLines = 1,
Expand Down

0 comments on commit 0088554

Please sign in to comment.