Update MessagingView.qml

Group all common functions
This commit is contained in:
Alex Jbanca 2022-11-07 18:25:28 +02:00
parent f20c5efe20
commit d23cce99a0
1 changed files with 36 additions and 35 deletions

View File

@ -33,6 +33,39 @@ SettingsContentBase {
spacing: 2 * Constants.settingsSection.itemSpacing
width: root.contentWidth
function switchOffPreviewableSites() {
//update all models
localAccountSensitiveSettings.displayChatImages = false
for (let i = 0; i < previewableSites.count; i++) {
let item = previewableSites.get(i)
RootStore.updateWhitelistedUnfurlingSites(item.address, false)
}
}
function buildPreviewablesSitesJSON() {
let whitelistAsString = root.messagingStore.getLinkPreviewWhitelist()
if(whitelistAsString == "")
return
if (!localAccountSensitiveSettings.whitelistedUnfurlingSites) {
localAccountSensitiveSettings.whitelistedUnfurlingSites = {}
}
let anyWhitelisted = false
let whitelist = JSON.parse(whitelistAsString)
whitelist.forEach(entry => {
entry.isWhitelisted = !!localAccountSensitiveSettings.whitelistedUnfurlingSites[entry.address]
if(entry.isWhitelisted) anyWhitelisted = true
})
return [anyWhitelisted, whitelist]
}
function populatePreviewableSites() {
const [anyWhitelisted, whitelist] = buildPreviewablesSitesJSON()
previewableSites.populateModel(whitelist)
previewableSites.anyWhitelisted = anyWhitelisted
}
ButtonGroup {
id: showProfilePictureToGroup
}
@ -136,18 +169,10 @@ SettingsContentBase {
components: [
StatusSwitch {
id: showMessageLinksSwitch
function switchOffPreviewableSites() {
//update all models
localAccountSensitiveSettings.displayChatImages = false
for (let i = 0; i < previewableSites.count; i++) {
let item = previewableSites.get(i)
RootStore.updateWhitelistedUnfurlingSites(item.address, false)
}
}
checked: previewableSites.anyWhitelisted || localAccountSensitiveSettings.displayChatImages
onToggled: {
if (checked === false) {
switchOffPreviewableSites()
if (!checked) {
generalColumn.switchOffPreviewableSites()
}
}
}
@ -155,35 +180,11 @@ SettingsContentBase {
onClicked: {
showMessageLinksSwitch.toggle()
if (!showMessageLinksSwitch.checked) {
showMessageLinksSwitch.switchOffPreviewableSites()
generalColumn.switchOffPreviewableSites()
}
}
}
function buildPreviewablesSitesJSON() {
let whitelistAsString = root.messagingStore.getLinkPreviewWhitelist()
if(whitelistAsString == "")
return
if (!localAccountSensitiveSettings.whitelistedUnfurlingSites) {
localAccountSensitiveSettings.whitelistedUnfurlingSites = {}
}
let anyWhitelisted = false
let whitelist = JSON.parse(whitelistAsString)
whitelist.forEach(entry => {
entry.isWhitelisted = !!localAccountSensitiveSettings.whitelistedUnfurlingSites[entry.address]
if(entry.isWhitelisted) anyWhitelisted = true
})
return [anyWhitelisted, whitelist]
}
function populatePreviewableSites() {
const [anyWhitelisted, whitelist] = buildPreviewablesSitesJSON()
previewableSites.populateModel(whitelist)
previewableSites.anyWhitelisted = anyWhitelisted
}
Component.onCompleted: {
populatePreviewableSites()
}