Verified Commit 478f691a authored by Mikolai Gütschow's avatar Mikolai Gütschow
Browse files

addressed review comments

parent f9adf46d
Pipeline #8051 passed with stage
in 1 minute and 57 seconds
......@@ -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
}
}
......
......@@ -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)
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment