status-lib/status/types/profile.nim

62 lines
1.9 KiB
Nim
Raw Normal View History

2021-09-08 18:05:39 +00:00
{.used.}
import json, strformat
import identity_image
export identity_image
const contactAdded* = ":contact/added"
const contactBlocked* = ":contact/blocked"
const contactRequest* = ":contact/request-received"
2021-09-08 18:05:39 +00:00
type Profile* = ref object
id*, alias*, username*, identicon*, address*, ensName*, localNickname*: string
ensVerified*: bool
messagesFromContactsOnly*: bool
sendUserStatus*: bool
currentUserStatus*: int
identityImage*: IdentityImage
appearance*: int
added*: bool
blocked*: bool
hasAddedUs*: bool
2021-09-08 18:05:39 +00:00
proc `$`*(self: Profile): string =
return fmt"Profile(id:{self.id}, username:{self.username}, added: {self.added}, blocked: {self.blocked}, hasAddedUs: {self.hasAddedUs}, ensName: {self.ensName})"
2021-09-08 18:05:39 +00:00
proc toProfile*(jsonNode: JsonNode): Profile =
2021-09-08 18:05:39 +00:00
result = Profile(
id: jsonNode["id"].str,
username: jsonNode["alias"].str,
identicon: jsonNode["identicon"].str,
2021-09-08 18:05:39 +00:00
identityImage: IdentityImage(),
address: jsonNode["id"].str,
alias: jsonNode["alias"].str,
2021-09-08 18:05:39 +00:00
ensName: "",
ensVerified: jsonNode["ensVerified"].getBool,
2021-09-08 18:05:39 +00:00
appearance: 0,
added: jsonNode["added"].getBool,
blocked: jsonNode["blocked"].getBool,
hasAddedUs: jsonNode["hasAddedUs"].getBool,
2021-09-08 18:05:39 +00:00
)
if jsonNode.hasKey("name"):
result.ensName = jsonNode["name"].str
2021-09-08 18:05:39 +00:00
if jsonNode.hasKey("localNickname"):
result.localNickname = jsonNode["localNickname"].str
if jsonNode.hasKey("images") and jsonNode["images"].kind != JNull:
if jsonNode["images"].hasKey("thumbnail"):
result.identityImage.thumbnail = jsonNode["images"]["thumbnail"]["uri"].str
if jsonNode["images"].hasKey("large"):
result.identityImage.large = jsonNode["images"]["large"]["uri"].str
proc isContact*(self: Profile): bool =
result = self.added
proc isBlocked*(self: Profile): bool =
result = self.blocked
proc requestReceived*(self: Profile): bool =
result = self.hasAddedUs