Skip to content

Commit 27d4daa

Browse files
committed
hardening code in case of error
Signed-off-by: rapterjet2004 <[email protected]>
1 parent 9a043b0 commit 27d4daa

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ class ChatActivity :
673673

674674
this.lifecycleScope.launch {
675675
chatViewModel.getConversationFlow
676-
.onEach { conversationModel ->
676+
.collect { conversationModel ->
677677
currentConversation = conversationModel
678678
chatViewModel.updateConversation(
679679
currentConversation!!
@@ -701,15 +701,17 @@ class ChatActivity :
701701
conversationModel.lastPinnedId.toString()
702702
)
703703
.collect { message ->
704-
binding.pinnedMessageContainer.visibility = View.VISIBLE
705-
binding.pinnedMessageComposeView.setContent {
706-
PinnedMessageView(message)
704+
message?.let {
705+
binding.pinnedMessageContainer.visibility = View.VISIBLE
706+
binding.pinnedMessageComposeView.setContent {
707+
PinnedMessageView(message)
708+
}
707709
}
708710
}
709711
} else {
710712
binding.pinnedMessageContainer.visibility = View.GONE
711713
}
712-
}.collect()
714+
}
713715
}
714716

715717
chatViewModel.getRoomViewState.observe(this) { state ->

app/src/main/java/com/nextcloud/talk/chat/viewmodels/ChatViewModel.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ class ChatViewModel @Inject constructor(
806806
baseUrl: String,
807807
token: String,
808808
messageId: String
809-
): Flow<ChatMessage> =
809+
): Flow<ChatMessage?> =
810810
flow {
811811
val messages = chatNetworkDataSource.getContextForChatMessage(
812812
credentials = credentials,
@@ -817,8 +817,12 @@ class ChatViewModel @Inject constructor(
817817
threadId = null
818818
)
819819

820-
val message = messages[0]
821-
emit(message.asModel())
820+
if (messages.isNotEmpty()) {
821+
val message = messages[0]
822+
emit(message.asModel())
823+
} else {
824+
emit(null)
825+
}
822826
}
823827

824828
suspend fun getNumberOfThreadReplies(threadId: Long): Int = chatRepository.getNumberOfThreadReplies(threadId)

0 commit comments

Comments
 (0)