Update empty search

This commit is contained in:
Andrew
2024-05-08 13:16:46 +09:30
parent afd240dcce
commit 1f1c51669c
11 changed files with 182 additions and 121 deletions

View File

@@ -36,21 +36,12 @@ class Contact(val sessionID: String) {
/**
* The name to display in the UI. For local use only.
*/
fun displayName(context: ContactContext): String? {
nickname?.let { return it }
return when (context) {
ContactContext.REGULAR -> name
ContactContext.OPEN_GROUP -> {
// In open groups, where it's more likely that multiple users have the same name,
// we display a bit of the Session ID after a user's display name for added context.
name?.let {
return "$name (${sessionID.take(4)}...${sessionID.takeLast(4)})"
}
return null
}
}
fun displayName(context: ContactContext): String? = nickname ?: when (context) {
ContactContext.REGULAR -> name
// In open groups, where it's more likely that multiple users have the same name,
// we display a bit of the Session ID after a user's display name for added context.
ContactContext.OPEN_GROUP -> name?.let { "$it (${sessionID.take(4)}...${sessionID.takeLast(4)})" }
}
// endregion
enum class ContactContext {
REGULAR, OPEN_GROUP
@@ -75,7 +66,6 @@ class Contact(val sessionID: String) {
}
companion object {
fun contextForRecipient(recipient: Recipient): ContactContext {
return if (recipient.isCommunityRecipient) ContactContext.OPEN_GROUP else ContactContext.REGULAR
}

View File

@@ -383,3 +383,9 @@ fun <T, K: Any, V: Any> Iterable<T>.associateByNotNull(
this[key] = value
}
}
inline fun <T, K> Iterable<T>.groupByNotNull(keySelector: (T) -> K?): Map<K, List<T>> {
val map = mutableMapOf<K, MutableList<T>>()
forEach { e -> keySelector(e)?.let { k -> map.getOrPut(k) { mutableListOf() }.add(e) } }
return map
}