Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/issue 8118 #8150

Merged
merged 4 commits into from
Nov 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 68 additions & 45 deletions ui/app/AppLayouts/Profile/views/MessagingView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -136,43 +169,19 @@ SettingsContentBase {
components: [
StatusSwitch {
id: showMessageLinksSwitch
checked: false
onCheckedChanged: {
if (checked === false) {
// Switch all the whitelists to false
imageSwitch.checked = false
for (let i = 0; i < sitesListView.count; i++) {
let item = sitesListView.itemAt(i)
item.whitelistSwitch.checked = false
}
checked: previewableSites.anyWhitelisted || localAccountSensitiveSettings.displayChatImages
onToggled: {
if (!checked) {
generalColumn.switchOffPreviewableSites()
}
}
}
]
onClicked: {
showMessageLinksSwitch.checked = !showMessageLinksSwitch.checked
}
}

function populatePreviewableSites() {
let whitelistAsString = root.messagingStore.getLinkPreviewWhitelist()
if(whitelistAsString == "")
return
let whitelist = JSON.parse(whitelistAsString)
if (!localAccountSensitiveSettings.whitelistedUnfurlingSites) {
localAccountSensitiveSettings.whitelistedUnfurlingSites = {}
}
previewableSites.clear()
var oneEntryIsActive = false
whitelist.forEach(entry => {
entry.isWhitelisted = !!localAccountSensitiveSettings.whitelistedUnfurlingSites[entry.address]
if (entry.isWhitelisted) {
oneEntryIsActive = true
}
previewableSites.append(entry)
})
if (oneEntryIsActive) {
showMessageLinksSwitch.checked = true
showMessageLinksSwitch.toggle()
if (!showMessageLinksSwitch.checked) {
generalColumn.switchOffPreviewableSites()
}
}
}

Expand All @@ -196,6 +205,26 @@ SettingsContentBase {

ListModel {
id: previewableSites
function populateModel(jsonModel) {
// add/update rows
Object.entries(jsonModel)
.forEach(([index, newRow]) => {
var existingRow = previewableSites.get(index)
let isRowIdentical = existingRow != undefined && Object.entries(newRow)
.every(([key, value]) => value == existingRow[key])
if(!isRowIdentical) {
previewableSites.set(index, newRow)
}
})

// remove rows that are not in the new model
if(previewableSites.count > jsonModel.length) {
let rowsToDelete = previewableSites.count - jsonModel.length
previewableSites.remove(jsonModel.length - 1, rowsToDelete)
}
}

property bool anyWhitelisted: false
}

Connections {
Expand All @@ -220,24 +249,17 @@ SettingsContentBase {
// TODO find a better icon for this
asset.name: Style.svg('globe')
asset.isImage: true
Component.onCompleted: {
if (localAccountSensitiveSettings.displayChatImages) {
showMessageLinksSwitch.checked = true
}
}
components: [
StatusSwitch {
id: imageSwitch
checked: localAccountSensitiveSettings.displayChatImages
onCheckedChanged: {
if (localAccountSensitiveSettings.displayChatImages !== checked) {
localAccountSensitiveSettings.displayChatImages = checked
}
onToggled: {
localAccountSensitiveSettings.displayChatImages = !localAccountSensitiveSettings.displayChatImages
}
}
]
onClicked: {
imageSwitch.checked = !imageSwitch.checked
localAccountSensitiveSettings.displayChatImages = !localAccountSensitiveSettings.displayChatImages
caybro marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand All @@ -248,7 +270,6 @@ SettingsContentBase {
delegate: Component {
StatusListItem {
objectName: "MessagingView_sitesListView_StatusListItem_" + model.title.replace(/ /g, "_").toLowerCase()
property alias whitelistSwitch: siteSwitch
width: parent.width
implicitHeight: 64
title: model.title
Expand Down Expand Up @@ -283,11 +304,13 @@ SettingsContentBase {
StatusSwitch {
id: siteSwitch
checked: !!model.isWhitelisted
onCheckedChanged: RootStore.updateWhitelistedUnfurlingSites(model.address, checked)
onToggled: {
RootStore.updateWhitelistedUnfurlingSites(model.address, checked)
}
}
]
onClicked: {
siteSwitch.checked = !siteSwitch.checked
RootStore.updateWhitelistedUnfurlingSites(model.address, !model.isWhitelisted)
caybro marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down