This repository has been archived by the owner on Jul 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use ui-avatars.com to generate user avatars
- Loading branch information
Showing
6 changed files
with
135 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import kotlinx.uuid.UUID; | ||
|
||
DROP TABLE Contacts; | ||
CREATE TABLE Contacts ( | ||
id TEXT AS UUID NOT NULL PRIMARY KEY, | ||
userId TEXT AS UUID NOT NULL, | ||
contactUserId TEXT AS UUID NOT NULL, | ||
avatarUrl TEXT NOT NULL, | ||
firstName TEXT NOT NULL, | ||
lastName TEXT NOT NULL, | ||
username TEXT NOT NULL | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
server/src/main/kotlin/io/github/mklkj/kommunicator/utils/AvatarHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package io.github.mklkj.kommunicator.utils | ||
|
||
import org.koin.core.annotation.Singleton | ||
import kotlin.math.abs | ||
|
||
@Singleton | ||
class AvatarHelper { | ||
|
||
private val backgroundColors = listOf( | ||
"000033", | ||
"003333", | ||
"0099cc", | ||
"00cc33", | ||
"3300ff", | ||
"666600", | ||
"669933", | ||
"990099", | ||
"996666", | ||
"cc0000", | ||
"cc6633", | ||
) | ||
|
||
private val color = "fff" | ||
|
||
fun getUserAvatar(firstName: String, lastName: String, customName: String? = null): String { | ||
return getAvatar(customName ?: "$firstName $lastName") | ||
} | ||
|
||
fun getGroupAvatar(name: String): String = getAvatar(name) | ||
|
||
private fun getAvatar(name: String): String { | ||
return "https://ui-avatars.com/api/?background=${getColor(name)}&color=$color&name=$name" | ||
} | ||
|
||
// fun getGravatarAvatar(email: String): String { | ||
// return "https://gravatar.com/avatar/${md5(email)}" | ||
// } | ||
|
||
private fun getColor(name: String): String { | ||
return backgroundColors[abs(name.hashCode() % backgroundColors.size)] | ||
} | ||
} |