fixes #1557: Filter out emojis when creating short names (#1578)

* Filter out emojis from text when finding initials

* Confirm non-English non-emoji unicde isn't filtered

* Remove unused example unit test

---------

Co-authored-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
Joshua Soberg 2025-02-15 23:25:35 -05:00 committed by GitHub
parent e11d726e27
commit 24abd1ac4a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 50 deletions

View file

@ -86,13 +86,13 @@ import javax.inject.Inject
import kotlin.math.roundToInt
// Given a human name, strip out the first letter of the first three words and return that as the initials for
// that user. If the original name is only one word, strip vowels from the original name and if the result is
// 3 or more characters, use the first three characters. If not, just take the first 3 characters of the
// original name.
// that user, ignoring emojis. If the original name is only one word, strip vowels from the original
// name and if the result is 3 or more characters, use the first three characters. If not, just take
// the first 3 characters of the original name.
fun getInitials(nameIn: String): String {
val nchars = 4
val minchars = 2
val name = nameIn.trim()
val name = nameIn.trim().withoutEmojis()
val words = name.split(Regex("\\s+")).filter { it.isNotEmpty() }
val initials = when (words.size) {
@ -109,6 +109,8 @@ fun getInitials(nameIn: String): String {
return initials.take(nchars)
}
private fun String.withoutEmojis(): String = filterNot { char -> char.isSurrogate() }
/**
* Builds a [Channel] list from the difference between two [ChannelSettings] lists.
* Only changes are included in the resulting list.