feat: introduce advanced option to enable/disable community archive

protocol
This commit is contained in:
Pascal Precht 2022-04-08 12:41:35 +02:00 committed by r4bbit.eth
parent 1ee631c04e
commit 1d934c7b26
11 changed files with 143 additions and 1 deletions

View File

@ -79,6 +79,25 @@ proc setBloomLevel*(self: Controller, bloomLevel: string) =
self.delegate.onBloomLevelSet()
method toggleCommunityHistoryArchiveSupport*(self: Controller) =
let enabled = self.nodeConfigurationService.isCommunityHistoryArchiveSupportEnabled()
if enabled:
if (not self.nodeConfigurationService.disableCommunityHistoryArchiveSupport()):
# in the future we may do a call from here to show a popup about this error
error "an error occurred, we couldn't enable community history archive support"
return
else:
if (not self.nodeConfigurationService.enableCommunityHistoryArchiveSupport()):
# in the future we may do a call from here to show a popup about this error
error "an error occurred, we couldn't disable community history archive support"
return
self.delegate.onCommunityHistoryArchiveSupportToggled()
method isCommunityHistoryArchiveSupportEnabled*(self: Controller): bool =
return self.nodeConfigurationService.isCommunityHistoryArchiveSupportEnabled()
proc getWakuV2LightClientEnabled*(self: Controller): bool =
return self.nodeConfigurationService.getV2LightMode()

View File

@ -26,6 +26,9 @@ method onFleetSet*(self: AccessInterface) {.base.} =
method onBloomLevelSet*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method onCommunityHistoryArchiveSupportToggled*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method onWakuV2LightClientSet*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
@ -110,3 +113,9 @@ method toggleNodeManagementSection*(self: AccessInterface) {.base.} =
method enableDeveloperFeatures*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method isCommunityHistoryArchiveSupportEnabled*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")
method toggleCommunityHistoryArchiveSupport*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -158,3 +158,12 @@ method toggleCommunitySection*(self: Module) =
method toggleNodeManagementSection*(self: Module) =
self.controller.toggleNodeManagementSection()
method onCommunityHistoryArchiveSupportToggled*(self: Module) =
self.view.emitCommunityHistoryArchiveSupportEnabledSignal()
method toggleCommunityHistoryArchiveSupport*(self: Module) =
self.controller.toggleCommunityHistoryArchiveSupport()
method isCommunityHistoryArchiveSupportEnabled*(self: Module): bool =
self.controller.isCommunityHistoryArchiveSupportEnabled()

View File

@ -115,6 +115,19 @@ QtObject:
proc toggleAutoMessage*(self: View) {.slot.} =
self.delegate.toggleAutoMessage()
proc isCommunityHistoryArchiveSupportEnabledChanged*(self: View) {.signal.}
proc getIsCommunityHistoryArchiveSupportEnabled*(self: View): bool {.slot.} =
return self.delegate.isCommunityHistoryArchiveSupportEnabled()
QtProperty[bool] isCommunityHistoryArchiveSupportEnabled:
read = getIsCommunityHistoryArchiveSupportEnabled
notify = isCommunityHistoryArchiveSupportEnabledChanged
proc emitCommunityHistoryArchiveSupportEnabledSignal*(self: View) =
self.isCommunityHistoryArchiveSupportEnabledChanged()
proc toggleCommunityHistoryArchiveSupport*(self: View) {.slot.} =
self.delegate.toggleCommunityHistoryArchiveSupport()
proc isDebugEnabledChanged*(self: View) {.signal.}
proc getIsDebugEnabled*(self: View): bool {.slot.} =
return self.delegate.isDebugEnabled()

View File

@ -157,6 +157,9 @@ type
SwarmConfig* = object
Enabled*: bool
TorrentConfig* = object
Enabled*: bool
Whisper* = object
Min*: int
Max*: int
@ -210,6 +213,7 @@ type
LightEthConfig*: LightEthConfig
WakuConfig*: WakuConfig
WakuV2Config*: Waku2Config
TorrentConfig*: TorrentConfig
BridgeConfig*: BridgeConfig
ShhextConfig*: ShhextConfig
WalletConfig*: WalletConfig
@ -322,6 +326,9 @@ proc toDatabaseConfig*(jsonObj: JsonNode): DatabaseConfig =
if(jsonObj.getProp("PGConfig", pgConfigObj)):
result.PGConfig = toPGConfig(pgConfigObj)
proc toTorrentConfig*(jsonObj: JsonNode): TorrentConfig =
discard jsonObj.getProp("Enabled", result.Enabled)
proc toWaku2Config*(jsonObj: JsonNode): Waku2Config =
discard jsonObj.getProp("Enabled", result.Enabled)
discard jsonObj.getProp("Rendezvous", result.Rendezvous)
@ -511,6 +518,10 @@ proc toNodeConfigDto*(jsonObj: JsonNode): NodeConfigDto =
if(jsonObj.getProp("WakuConfig", wakuConfigObj)):
result.WakuConfig = toWakuConfig(wakuConfigObj)
var torrentConfigObj: JsonNode
if(jsonObj.getProp("TorrentConfig", torrentConfigObj)):
result.TorrentConfig = toTorrentConfig(torrentConfigObj)
var wakuV2ConfigObj: JsonNode
if(jsonObj.getProp("WakuV2Config", wakuV2ConfigObj)):
result.WakuV2Config = toWaku2Config(wakuV2ConfigObj)

View File

@ -51,6 +51,16 @@ proc init*(self: Service) =
error "error: ", errDesription
return
proc fetchNodeConfig(self: Service) =
try:
let response = status_node_config.getNodeConfig()
self.configuration = response.result.toNodeConfigDto()
except Exception as e:
let errDesription = e.msg
error "error: ", errDesription
return
proc saveConfiguration(self: Service, configuration: NodeConfigDto): bool =
if(not self.settingsService.saveNodeConfiguration(configuration.toJsonNode())):
error "error saving node configuration "
@ -58,6 +68,24 @@ proc saveConfiguration(self: Service, configuration: NodeConfigDto): bool =
self.configuration = configuration
return true
method enableCommunityHistoryArchiveSupport*(self: Service): bool =
let response = status_node_config.enableCommunityHistoryArchiveSupport()
if(not response.error.isNil):
error "error enabling community history archive support: ", errDescription = response.error.message
return false
self.fetchNodeConfig()
return true
method disableCommunityHistoryArchiveSupport*(self: Service): bool =
let response = status_node_config.disableCommunityHistoryArchiveSupport()
if(not response.error.isNil):
error "error disabling community history archive support: ", errDescription = response.error.message
return false
self.fetchNodeConfig()
return true
proc getWakuVersion*(self: Service): int =
if self.configuration.WakuConfig.Enabled:
return WAKU_VERSION_1
@ -102,6 +130,9 @@ proc setWakuVersion*(self: Service, wakuVersion: int): bool =
newConfiguration.WakuV2Config.Rendezvous = true
return self.saveConfiguration(newConfiguration)
method isCommunityHistoryArchiveSupportEnabled*(self: Service): bool =
return self.configuration.TorrentConfig.Enabled
proc setNetwork*(self: Service, network: string): bool =
if(not self.settingsService.saveCurrentNetwork(network)):
error "error saving network ", network, procName="setNetwork"

View File

@ -54,3 +54,11 @@ proc getPasswordStrengthScore*(password: string, userInputs: seq[string]): RpcRe
except RpcException as e:
error "error", methodName = "getPasswordStrengthScore", exception=e.msg
raise newException(RpcException, e.msg)
proc enableCommunityHistoryArchiveSupport*(): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %* []
result = core.callPrivateRPC("enableCommunityHistoryArchiveProtocol", payload)
proc disableCommunityHistoryArchiveSupport*(): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %* []
result = core.callPrivateRPC("disableCommunityHistoryArchiveProtocol", payload)

View File

@ -1,6 +1,7 @@
import json, json_serialization, chronicles
import ./core
import ./response_type
import utils
import status_go
@ -25,4 +26,20 @@ proc switchFleet*(fleet: string, nodeConfig: JsonNode): RpcResponse[JsonNode] {.
result.result = Json.decode(response, JsonNode)
except RpcException as e:
error "error doing rpc request", methodName = "saveAccountAndLogin", exception=e.msg
raise newException(RpcException, e.msg)
raise newException(RpcException, e.msg)
proc enableCommunityHistoryArchiveSupport*(): RpcResponse[JsonNode] {.raises: [Exception].} =
try:
let payload = %* []
result = core.callPrivateRPC("enableCommunityHistoryArchiveProtocol".prefix)
except RpcException as e:
error "error doing rpc request", methodName = "enableCommunityHistoryArchiveProtocol", exception=e.msg
raise newException(RpcException, e.msg)
proc disableCommunityHistoryArchiveSupport*(): RpcResponse[JsonNode] {.raises: [Exception].} =
try:
let payload = %* []
result = core.callPrivateRPC("disableCommunityHistoryArchiveProtocol".prefix)
except RpcException as e:
error "error doing rpc request", methodName = "disableCommunityHistoryArchiveProtocol", exception=e.msg
raise newException(RpcException, e.msg)

View File

@ -40,6 +40,8 @@ QtObject {
property var loadingHistoryMessagesInProgress: chatCommunitySectionModule.loadingHistoryMessagesInProgress
property var advancedModule: profileSectionModule.advancedModule
function setActiveCommunity(communityId) {
mainModule.setActiveSectionById(communityId);
}
@ -136,6 +138,8 @@ QtObject {
property var walletSectionTransactionsInst: walletSectionTransactions
property bool isCommunityHistoryArchiveSupportEnabled: advancedModule? advancedModule.isCommunityHistoryArchiveSupportEnabled : false
function reCalculateAddToGroupContacts(channel) {
const contacts = getContactListObject()

View File

@ -15,6 +15,7 @@ QtObject {
property bool isTelemetryEnabled: advancedModule? advancedModule.isTelemetryEnabled : false
property bool isAutoMessageEnabled: advancedModule? advancedModule.isAutoMessageEnabled : false
property bool isDebugEnabled: advancedModule? advancedModule.isDebugEnabled : false
property bool isCommunityHistoryArchiveSupportEnabled: advancedModule? advancedModule.isCommunityHistoryArchiveSupportEnabled : false
property var customNetworksModel: advancedModule? advancedModule.customNetworksModel : []
@ -33,6 +34,7 @@ QtObject {
readonly property string gifWidget: "gifWidget"
readonly property string keycard: "keycard"
readonly property string multiNetwork: "multiNetwork"
readonly property string communityHistoryArchiveSupport: "communityHistoryArchiveSupport"
}
function setGlobalNetworkId() {
@ -128,6 +130,10 @@ QtObject {
else if (feature === experimentalFeatures.communities) {
advancedModule.toggleCommunitySection()
}
else if (feature === experimentalFeatures.communityHistoryArchiveSupport) {
// toggle history archive support
advancedModule.toggleCommunityHistoryArchiveSupport()
}
else if (feature === experimentalFeatures.activityCenter) {
localAccountSensitiveSettings.isActivityCenterEnabled = !localAccountSensitiveSettings.isActivityCenterEnabled
}

View File

@ -156,6 +156,21 @@ ScrollView {
}
}
StatusSettingsLineButton {
//% "Communities"
text: qsTrId("Community History Archive Protocol")
isSwitch: true
switchChecked: root.advancedStore.isCommunityHistoryArchiveSupportEnabled
onClicked: {
if (!root.advancedStore.isCommunityHistoryArchiveSupportEnabled) {
confirmationPopup.experimentalFeature = root.advancedStore.experimentalFeatures.communityHistoryArchiveSupport
confirmationPopup.open()
} else {
root.advancedStore.toggleExperimentalFeature(root.advancedStore.experimentalFeatures.communityHistoryArchiveSupport)
}
}
}
// TODO: replace with StatusQ component
StatusSettingsLineButton {
//% "Activity Center"