-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPubkyProfile.kt
More file actions
55 lines (48 loc) · 1.64 KB
/
PubkyProfile.kt
File metadata and controls
55 lines (48 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package to.bitkit.models
import to.bitkit.ext.ellipsisMiddle
import com.synonym.bitkitcore.PubkyProfile as CorePubkyProfile
data class PubkyProfileLink(val label: String, val url: String)
data class PubkyProfile(
val publicKey: String,
val name: String,
val bio: String,
val imageUrl: String?,
val links: List<PubkyProfileLink>,
val status: String?,
) {
companion object {
private const val TRUNCATED_PK_LENGTH = 11
fun fromFfi(publicKey: String, ffiProfile: CorePubkyProfile): PubkyProfile {
return PubkyProfile(
publicKey = publicKey,
name = ffiProfile.name,
bio = ffiProfile.bio ?: "",
imageUrl = ffiProfile.image,
links = ffiProfile.links.orEmpty().map { PubkyProfileLink(label = it.title, url = it.url) },
status = ffiProfile.status,
)
}
fun placeholder(publicKey: String) = PubkyProfile(
publicKey = publicKey,
name = publicKey.ellipsisMiddle(TRUNCATED_PK_LENGTH),
bio = "",
imageUrl = null,
links = emptyList(),
status = null,
)
fun forDisplay(
publicKey: String,
name: String?,
imageUrl: String?,
) = PubkyProfile(
publicKey = publicKey,
name = name ?: publicKey.ellipsisMiddle(TRUNCATED_PK_LENGTH),
bio = "",
imageUrl = imageUrl,
links = emptyList(),
status = null,
)
}
val truncatedPublicKey: String
get() = publicKey.ellipsisMiddle(TRUNCATED_PK_LENGTH)
}