Commit c54a4144 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Update RocketChatUserAvatar.kt

parent ed0f72dc
...@@ -61,15 +61,15 @@ object RocketChatUserAvatar { ...@@ -61,15 +61,15 @@ object RocketChatUserAvatar {
* @return A string with username initials. * @return A string with username initials.
*/ */
fun getUsernameInitials(username: String): String { fun getUsernameInitials(username: String): String {
val name = username if (username.isEmpty()) {
.replace("[^A-Za-z0-9]", ".") return "?"
.replace("\\.+", ".") }
.replace("(^\\.)|(\\.$)", "")
val initials = name.split(".") val splitUsername = username.split(".")
if (initials.size > 1) { if (splitUsername.size > 1) {
return (initials[0].substring(0, 1) + initials[initials.size - 1].substring(0, 1)).toUpperCase() return (splitUsername[0].substring(0, 1) + splitUsername[splitUsername.size - 1].substring(0, 1)).toUpperCase()
} else { } else {
return (name.replace("[^A-Za-z0-9]", "").substring(0, 2)).toUpperCase() return username.toUpperCase()
} }
} }
......
Markdown is supported
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