2021-09-08 18:05:39 +00:00
|
|
|
{.used.}
|
|
|
|
|
|
|
|
import json, strformat
|
|
|
|
import identity_image
|
|
|
|
|
|
|
|
export identity_image
|
|
|
|
|
2021-10-01 16:53:38 +00:00
|
|
|
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
|
2021-10-05 20:10:45 +00:00
|
|
|
added*: bool
|
|
|
|
blocked*: bool
|
|
|
|
hasAddedUs*: bool
|
2021-09-08 18:05:39 +00:00
|
|
|
|
|
|
|
proc `$`*(self: Profile): string =
|
2021-10-05 20:10:45 +00:00
|
|
|
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
|
|
|
|
2021-10-01 16:53:38 +00:00
|
|
|
proc toProfile*(jsonNode: JsonNode): Profile =
|
2021-09-08 18:05:39 +00:00
|
|
|
result = Profile(
|
2021-10-01 16:53:38 +00:00
|
|
|
id: jsonNode["id"].str,
|
|
|
|
username: jsonNode["alias"].str,
|
|
|
|
identicon: jsonNode["identicon"].str,
|
2021-09-08 18:05:39 +00:00
|
|
|
identityImage: IdentityImage(),
|
2021-10-01 16:53:38 +00:00
|
|
|
address: jsonNode["id"].str,
|
|
|
|
alias: jsonNode["alias"].str,
|
2021-09-08 18:05:39 +00:00
|
|
|
ensName: "",
|
2021-10-01 16:53:38 +00:00
|
|
|
ensVerified: jsonNode["ensVerified"].getBool,
|
2021-09-08 18:05:39 +00:00
|
|
|
appearance: 0,
|
2021-10-05 20:10:45 +00:00
|
|
|
added: jsonNode["added"].getBool,
|
|
|
|
blocked: jsonNode["blocked"].getBool,
|
|
|
|
hasAddedUs: jsonNode["hasAddedUs"].getBool,
|
2021-09-08 18:05:39 +00:00
|
|
|
)
|
|
|
|
|
2021-10-01 16:53:38 +00:00
|
|
|
if jsonNode.hasKey("name"):
|
|
|
|
result.ensName = jsonNode["name"].str
|
2021-09-08 18:05:39 +00:00
|
|
|
|
2021-10-01 16:53:38 +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 =
|
2021-10-05 20:10:45 +00:00
|
|
|
result = self.added
|
2021-10-01 16:53:38 +00:00
|
|
|
|
|
|
|
proc isBlocked*(self: Profile): bool =
|
2021-10-05 20:10:45 +00:00
|
|
|
result = self.blocked
|
2021-10-01 16:53:38 +00:00
|
|
|
|
|
|
|
proc requestReceived*(self: Profile): bool =
|
2021-10-05 20:10:45 +00:00
|
|
|
result = self.hasAddedUs
|