feat(libstatus): introduce API to get contact by ID

This commit is contained in:
Pascal Precht 2020-06-09 12:09:44 +02:00 committed by Iuri Matias
parent d5ba992c81
commit b8c5059de7
2 changed files with 36 additions and 2 deletions

View File

@ -43,3 +43,6 @@ proc removePeer*(peer: string) =
proc markTrustedPeer*(peer: string) =
discard callPrivateRPC("markTrustedPeer".prefix(false), %* [peer])
proc getContactByID*(id: string): string =
result = callPrivateRPC("getContactByID".prefix, %* [id])

View File

@ -1,5 +1,7 @@
import json
import eventemitter
import libstatus/types
import libstatus/core as libstatus_core
type
MailServer* = ref object
@ -10,7 +12,36 @@ type
name*, address*: string
type Profile* = ref object
username*, identicon*: string
id*, alias*, username*, identicon*: string
ensVerified*: bool
ensVerifiedAt*: int
ensVerificationEntries*: int
proc toProfileModel*(account: Account): Profile =
result = Profile(username: account.name, identicon: account.photoPath)
result = Profile(
id: "",
username: account.name,
identicon: account.photoPath,
alias: account.name,
ensVerified: false,
ensVerifiedAt: 0,
ensVerificationEntries: 0,
)
proc toProfileModel*(profile: JsonNode): Profile =
result = Profile(
id: profile["id"].str,
username: profile["alias"].str,
identicon: profile["identicon"].str,
alias: profile["alias"].str,
ensVerified: profile["ensVerified"].getBool,
ensVerifiedAt: profile["ensVerifiedAt"].getInt,
ensVerificationEntries: profile["ensVerificationEntries"].getInt
)
proc getContactByID*(id: string): Profile =
let response = libstatus_core.getContactByID(id)
let val = parseJSON($response)
result = toProfileModel(val)