Skip to content
Snippets Groups Projects
Verified Commit bec2c2d7 authored by Mikolai Gütschow's avatar Mikolai Gütschow
Browse files

addressed review comments

parent f9adf46d
No related branches found
No related tags found
No related merge requests found
Pipeline #8048 passed
......@@ -45,7 +45,10 @@ fun ContactList(
},
content = {
LazyColumn {
items(viewModel.contactList) { contactItem ->
items(
items = viewModel.contactList,
key = { it.contact.id }
) { contactItem ->
ContactCard(
contactItem,
{ viewModel.selectContact(contactItem.contact.id) },
......
......@@ -57,9 +57,10 @@ constructor(
override fun updateFilteredList() {
super.updateFilteredList()
_selectedContactId.value?.let { id ->
if (!contactList.map { it.contact.id }.contains(id))
_selectedContactId.value = null
// reset selected contact to null if not available after filtering
val id = _selectedContactId.value
if (id != null && !contactList.map { it.contact.id }.contains(id)) {
_selectedContactId.value = null
}
}
......
......@@ -79,7 +79,10 @@ fun Conversation(
contentPadding = PaddingValues(8.dp),
modifier = Modifier.padding(padding).fillMaxHeight()
) {
items(conversationViewModel.messages) { m ->
items(
items = conversationViewModel.messages,
key = { it.id }
) { m ->
if (m is ConversationMessageItem)
TextBubble(m)
}
......
......@@ -85,6 +85,9 @@ constructor(
val text = _newMessage.value
_newMessage.value = ""
// don't send empty or blank messages
if (text.isBlank()) return
val start = LogUtils.now()
val m = createMessage(text)
messagingManager.addLocalMessage(m)
......@@ -125,18 +128,20 @@ constructor(
try {
val start = LogUtils.now()
val headers = conversationManager.getMessageHeaders(_contactId.value!!)
LogUtils.logDuration(LOG, "Loading messages", start)
LogUtils.logDuration(LOG, "Loading message headers", start)
// Sort headers by timestamp in *descending* order
val sorted = headers.sortedByDescending { it.timestamp }
_messages.apply {
clear()
val start = LogUtils.now()
addAll(
// todo: use ConversationVisitor to also display Request and Notice Messages
sorted.filterIsInstance<PrivateMessageHeader>().map(::messageHeaderToItem)
)
LogUtils.logDuration(LOG, "Loading messages", start)
}
} catch (e: NoSuchContactException) {
// finishOnUiThread()
LogUtils.logException(LOG, Level.WARNING, e)
} catch (e: DbException) {
LogUtils.logException(LOG, Level.WARNING, e)
}
......@@ -147,17 +152,15 @@ constructor(
val item = ConversationMessageItem(h)
if (h.hasText()) {
item.text = loadMessageText(h.id)
} else {
LOG.warning { "private message without text" }
}
return item
}
private fun loadMessageText(m: MessageId): String? {
try {
val start = LogUtils.now()
val text = messagingManager.getMessageText(m)
LogUtils.logDuration(LOG, "Loading text", start)
return text
return messagingManager.getMessageText(m)
} catch (e: DbException) {
LogUtils.logException(LOG, Level.WARNING, e)
}
......
......@@ -24,13 +24,12 @@ fun PrivateMessageView(
ContactList(contactListViewModel, addContactViewModel)
VerticalDivider()
Column(modifier = Modifier.weight(1f).fillMaxHeight()) {
contactListViewModel.selectedContactId.value?.also { contactId ->
Conversation(
contactId,
conversationViewModel,
introductionViewModel
)
} ?: UiPlaceholder()
val id = contactListViewModel.selectedContactId.value
if (id != null) {
Conversation(id, conversationViewModel, introductionViewModel)
} else {
UiPlaceholder()
}
}
}
}
......@@ -44,7 +44,9 @@ fun TextBubble(m: ConversationMessageItem) {
if (!m.isIncoming) {
val modifier = Modifier.size(12.dp).align(Alignment.CenterVertically)
val icon =
if (m.isSeen) Icons.Filled.DoneAll else if (m.isSent) Icons.Filled.Done else Icons.Filled.Schedule
if (m.isSeen) Icons.Filled.DoneAll // acknowledged
else if (m.isSent) Icons.Filled.Done // sent
else Icons.Filled.Schedule // waiting
Icon(icon, "sent", modifier)
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment