feat(settings/profile): integrate social links and bio endpoints
closes: #6796
This commit is contained in:
parent
268560934a
commit
61a55db156
|
@ -0,0 +1,25 @@
|
||||||
|
import json, sequtils, sugar
|
||||||
|
|
||||||
|
const SOCIAL_LINK_TWITTER_ID* = "__twitter"
|
||||||
|
const SOCIAL_LINK_PERSONAL_SITE_ID* = "__personal_site"
|
||||||
|
const SOCIAL_LINK_GITHUB_ID* = "__github"
|
||||||
|
const SOCIAL_LINK_YOUTUBE_ID* = "__youtube"
|
||||||
|
const SOCIAL_LINK_DISCORD_ID* = "__discord"
|
||||||
|
const SOCIAL_LINK_TELEGRAM_ID* = "__telegram"
|
||||||
|
|
||||||
|
type
|
||||||
|
SocialLink* = object
|
||||||
|
text*: string
|
||||||
|
url*: string
|
||||||
|
|
||||||
|
SocialLinks* = seq[SocialLink]
|
||||||
|
|
||||||
|
proc toSocialLinks*(jsonObj: JsonNode): SocialLinks =
|
||||||
|
result = map(jsonObj.getElems(),
|
||||||
|
node => SocialLink(text: node["text"].getStr(),
|
||||||
|
url: node["url"].getStr())
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
proc toJsonNode*(links: SocialLinks): JsonNode =
|
||||||
|
%*links
|
|
@ -1,6 +1,7 @@
|
||||||
{.used.}
|
{.used.}
|
||||||
|
|
||||||
import json, strformat, strutils
|
import json, strformat, strutils
|
||||||
|
import ../../../common/social_links
|
||||||
|
|
||||||
include ../../../common/json_utils
|
include ../../../common/json_utils
|
||||||
include ../../../common/utils
|
include ../../../common/utils
|
||||||
|
@ -41,6 +42,8 @@ type ContactsDto* = object
|
||||||
lastUpdated*: int64
|
lastUpdated*: int64
|
||||||
lastUpdatedLocally*: int64
|
lastUpdatedLocally*: int64
|
||||||
localNickname*: string
|
localNickname*: string
|
||||||
|
bio*: string
|
||||||
|
socialLinks*: SocialLinks
|
||||||
image*: Images
|
image*: Images
|
||||||
added*: bool
|
added*: bool
|
||||||
blocked*: bool
|
blocked*: bool
|
||||||
|
@ -121,6 +124,7 @@ proc toContactsDto*(jsonObj: JsonNode): ContactsDto =
|
||||||
discard jsonObj.getProp("lastUpdated", result.lastUpdated)
|
discard jsonObj.getProp("lastUpdated", result.lastUpdated)
|
||||||
discard jsonObj.getProp("lastUpdatedLocally", result.lastUpdatedLocally)
|
discard jsonObj.getProp("lastUpdatedLocally", result.lastUpdatedLocally)
|
||||||
discard jsonObj.getProp("localNickname", result.localNickname)
|
discard jsonObj.getProp("localNickname", result.localNickname)
|
||||||
|
discard jsonObj.getProp("bio", result.bio)
|
||||||
|
|
||||||
result.trustStatus = TrustStatus.Unknown
|
result.trustStatus = TrustStatus.Unknown
|
||||||
var trustStatusInt: int
|
var trustStatusInt: int
|
||||||
|
@ -135,6 +139,10 @@ proc toContactsDto*(jsonObj: JsonNode): ContactsDto =
|
||||||
if(jsonObj.getProp("images", imageObj)):
|
if(jsonObj.getProp("images", imageObj)):
|
||||||
result.image = toImages(imageObj)
|
result.image = toImages(imageObj)
|
||||||
|
|
||||||
|
var socialLinksObj: JsonNode
|
||||||
|
if(jsonObj.getProp("socialLinks", socialLinksObj)):
|
||||||
|
result.socialLinks = toSocialLinks(socialLinksObj)
|
||||||
|
|
||||||
discard jsonObj.getProp("added", result.added)
|
discard jsonObj.getProp("added", result.added)
|
||||||
discard jsonObj.getProp("blocked", result.blocked)
|
discard jsonObj.getProp("blocked", result.blocked)
|
||||||
discard jsonObj.getProp("hasAddedUs", result.hasAddedUs)
|
discard jsonObj.getProp("hasAddedUs", result.hasAddedUs)
|
||||||
|
|
|
@ -299,7 +299,9 @@ QtObject:
|
||||||
thumbnail: singletonInstance.userProfile.getThumbnailImage(),
|
thumbnail: singletonInstance.userProfile.getThumbnailImage(),
|
||||||
large: singletonInstance.userProfile.getLargeImage()
|
large: singletonInstance.userProfile.getLargeImage()
|
||||||
),
|
),
|
||||||
trustStatus: TrustStatus.Trusted
|
trustStatus: TrustStatus.Trusted,
|
||||||
|
bio: self.settingsService.getBio(),
|
||||||
|
socialLinks: self.settingsService.getSocialLinks()
|
||||||
)
|
)
|
||||||
|
|
||||||
## Returns contact details based on passed id (public key)
|
## Returns contact details based on passed id (public key)
|
||||||
|
|
|
@ -44,6 +44,7 @@ const KEY_GIF_FAVORITES* = "gifs/favorite-gifs"
|
||||||
const KEY_GIF_RECENTS* = "gifs/recent-gifs"
|
const KEY_GIF_RECENTS* = "gifs/recent-gifs"
|
||||||
const KEY_GIF_API_KEY* = "gifs/api-key"
|
const KEY_GIF_API_KEY* = "gifs/api-key"
|
||||||
const KEY_DISPLAY_NAME* = "display-name"
|
const KEY_DISPLAY_NAME* = "display-name"
|
||||||
|
const KEY_BIO* = "bio"
|
||||||
const KEY_TEST_NETWORKS_ENABLED* = "test-networks-enabled?"
|
const KEY_TEST_NETWORKS_ENABLED* = "test-networks-enabled?"
|
||||||
|
|
||||||
# Notifications Settings Values
|
# Notifications Settings Values
|
||||||
|
@ -93,6 +94,7 @@ type
|
||||||
eip1581Address*: string
|
eip1581Address*: string
|
||||||
installationId*: string
|
installationId*: string
|
||||||
displayName*: string
|
displayName*: string
|
||||||
|
bio*: string
|
||||||
preferredName*: string
|
preferredName*: string
|
||||||
ensUsernames*: seq[string]
|
ensUsernames*: seq[string]
|
||||||
keyUid*: string
|
keyUid*: string
|
||||||
|
@ -161,6 +163,7 @@ proc toSettingsDto*(jsonObj: JsonNode): SettingsDto =
|
||||||
discard jsonObj.getProp(KEY_INSTALLATION_ID, result.installationId)
|
discard jsonObj.getProp(KEY_INSTALLATION_ID, result.installationId)
|
||||||
discard jsonObj.getProp(KEY_PREFERRED_NAME, result.preferredName)
|
discard jsonObj.getProp(KEY_PREFERRED_NAME, result.preferredName)
|
||||||
discard jsonObj.getProp(KEY_DISPLAY_NAME, result.displayName)
|
discard jsonObj.getProp(KEY_DISPLAY_NAME, result.displayName)
|
||||||
|
discard jsonObj.getProp(KEY_BIO, result.bio)
|
||||||
discard jsonObj.getProp(KEY_KEY_UID, result.keyUid)
|
discard jsonObj.getProp(KEY_KEY_UID, result.keyUid)
|
||||||
discard jsonObj.getProp(KEY_LATEST_DERIVED_PATH, result.latestDerivedPath)
|
discard jsonObj.getProp(KEY_LATEST_DERIVED_PATH, result.latestDerivedPath)
|
||||||
discard jsonObj.getProp(KEY_LINK_PREVIEW_REQUEST_ENABLED, result.linkPreviewRequestEnabled)
|
discard jsonObj.getProp(KEY_LINK_PREVIEW_REQUEST_ENABLED, result.linkPreviewRequestEnabled)
|
||||||
|
|
|
@ -2,6 +2,7 @@ import NimQml, chronicles, json, strutils, sequtils, tables, sugar
|
||||||
|
|
||||||
import ../../common/[network_constants]
|
import ../../common/[network_constants]
|
||||||
import ../../common/types as common_types
|
import ../../common/types as common_types
|
||||||
|
import ../../common/social_links
|
||||||
import ../../../app/core/eventemitter
|
import ../../../app/core/eventemitter
|
||||||
import ../../../app/core/fleets/fleet_configuration
|
import ../../../app/core/fleets/fleet_configuration
|
||||||
import ../../../app/core/signals/types
|
import ../../../app/core/signals/types
|
||||||
|
@ -826,3 +827,42 @@ QtObject:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
let errDesription = e.msg
|
let errDesription = e.msg
|
||||||
error "reading exemptions setting error: ", id = id, errDesription
|
error "reading exemptions setting error: ", id = id, errDesription
|
||||||
|
|
||||||
|
proc getBio*(self: Service): string =
|
||||||
|
self.settings.bio
|
||||||
|
|
||||||
|
proc setBio*(self: Service, bio: string): bool =
|
||||||
|
result = false
|
||||||
|
try:
|
||||||
|
let response = status_settings.setBio(bio)
|
||||||
|
|
||||||
|
if(not response.error.isNil):
|
||||||
|
error "error setting bio", errDescription = response.error.message
|
||||||
|
|
||||||
|
self.settings.bio = bio
|
||||||
|
result = true
|
||||||
|
except Exception as e:
|
||||||
|
error "error setting bio", errDesription = e.msg
|
||||||
|
|
||||||
|
proc getSocialLinks*(self: Service): SocialLinks =
|
||||||
|
try:
|
||||||
|
let response = status_settings.getSocialLinks()
|
||||||
|
|
||||||
|
if(not response.error.isNil):
|
||||||
|
error "error getting social links", errDescription = response.error.message
|
||||||
|
|
||||||
|
result = toSocialLinks(response.result)
|
||||||
|
except Exception as e:
|
||||||
|
error "error getting social links", errDesription = e.msg
|
||||||
|
|
||||||
|
proc setSocialLinks*(self: Service, links: SocialLinks): bool =
|
||||||
|
result = false
|
||||||
|
try:
|
||||||
|
let response = status_settings.setSocialLinks(%*links)
|
||||||
|
|
||||||
|
if(not response.error.isNil):
|
||||||
|
error "error setting social links", errDescription = response.error.message
|
||||||
|
|
||||||
|
result = true
|
||||||
|
except Exception as e:
|
||||||
|
error "error setting social links", errDesription = e.msg
|
||||||
|
|
|
@ -95,3 +95,12 @@ proc setExemptions*(id: string, muteAllMessages: bool, personalMentions: string,
|
||||||
|
|
||||||
proc deleteExemptions*(id: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
proc deleteExemptions*(id: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||||
return core.callPrivateRPC("settings_deleteExemptions", %* [id])
|
return core.callPrivateRPC("settings_deleteExemptions", %* [id])
|
||||||
|
|
||||||
|
proc setBio*(value: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||||
|
return core.callPrivateRPC("settings_setBio", %* [value])
|
||||||
|
|
||||||
|
proc setSocialLinks*(value: JsonNode): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||||
|
return core.callPrivateRPC("settings_setSocialLinks", %* [value])
|
||||||
|
|
||||||
|
proc getSocialLinks*(): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||||
|
return core.callPrivateRPC("settings_getSocialLinks")
|
||||||
|
|
Loading…
Reference in New Issue