Skip to content

Commit

Permalink
feat(settings): nsfw filter user setting (#2917)
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmcg authored Apr 21, 2022
1 parent 743dd40 commit 0a8a264
Show file tree
Hide file tree
Showing 16 changed files with 92 additions and 118 deletions.
6 changes: 6 additions & 0 deletions components/views/settings/pages/privacy/Privacy.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
>
<InteractablesSwitch v-model="consentScan" />
</SettingsUnit>
<SettingsUnit
:title="$t('pages.privacy.nsfw.title')"
:text="$t('pages.privacy.nsfw.subtitle')"
>
<InteractablesSwitch v-model="blockNsfw" />
</SettingsUnit>
</div>
<div class="columns is-desktop">
<SettingsUnit
Expand Down
8 changes: 8 additions & 0 deletions components/views/settings/pages/privacy/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ export default Vue.extend({
return this.settings.consentScan
},
},
blockNsfw: {
set(state) {
this.$store.dispatch('settings/setBlockNsfw', state)
},
get() {
return this.settings.blockNsfw
},
},
displayCurrentActivity: {
set(state) {
this.$store.commit('settings/displayCurrentActivity', state)
Expand Down
23 changes: 22 additions & 1 deletion libraries/Textile/UserManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class UserInfoManager {
return record || null
}

async getConsentData(): Promise<UserdataFromThread | null> {
async getUserRecord(): Promise<UserdataFromThread | null> {
return await this._findRecord()
}

Expand Down Expand Up @@ -94,6 +94,27 @@ export class UserInfoManager {
])
}

/**
* @method setBlockNsfw
* @description set whether nsfw content should be blocked
* @param {boolean} blockNsfw true to block, false for show
*/
async setBlockNsfw(blockNsfw: boolean): Promise<void> {
const record = await this._findRecord()
if (record) {
record.block_nsfw = blockNsfw
await this.textile.client.save(this.threadID, CollectionName, [record])
return
}
await this.textile.client.create(this.threadID, CollectionName, [
{
user_address: this.textile.wallet.address,
created_at: Date.now(),
block_nsfw: blockNsfw,
},
])
}

async getThreadName(): Promise<string> {
const crypto = new Crypto()
const name = crypto.signMessageWithKey(
Expand Down
1 change: 1 addition & 0 deletions libraries/Textile/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ export const userinfoSchema = {
user_address: { type: 'string' },
consent_scan: { type: 'boolean' },
consent_date: { type: 'number' },
block_nsfw: { type: 'boolean' },
},
}
7 changes: 5 additions & 2 deletions locales/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,14 @@ export default {
"Choose which signaling server group you want to use. If you use 'Satellite + Public Signaling Servers', you are using public servers and Satellite hosted servers to connect with your friends. We do not track connections. We only track server utilization (memory and cpu usage) to know if we need to turn on more signaling servers. If you opt to use 'Only Public Signaling Servers', those are totally outside of Satellite control, so we can not see or have any insight into their operation, logging, or data sharing practices, and you may experience difficulties connecting with friends if the signaling servers are overloaded.",
},
consentScan: {
title: 'Consents to having files scanned',
title: 'Consent to File Scanning',
subtitle:
'In order to share files/use the encrypted file storage I consent to having my files auto-scanned against the Microsoft PhotoDNA service to help prevent the spread of sexual abuse material',
},
nsfw: {
title: 'Block NSFW content',
subtitle: 'If selected, NSFW content will be obscured.',
},
ownInfo: {
title: 'Set my own Signaling Server',
subtitle:
Expand All @@ -238,7 +242,6 @@ export default {
publicServer: 'Only Public Signaling Servers',
userDefinedServer: 'Set my own',
},
continue: 'Continue',
register: {
title: 'Register Username Publicly',
subtitle:
Expand Down
2 changes: 1 addition & 1 deletion pages/setup/disclaimer/Disclaimer.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
full-width
data-cy="create-account-button"
:text="$t('pages.disclaimer.create')"
:action="() => { goToPrivacySettings() }"
:action="generateWallet"
:loading="isLoading"
/>
<InteractablesButton
Expand Down
5 changes: 3 additions & 2 deletions pages/setup/disclaimer/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ export default Vue.extend({
},
},
methods: {
goToPrivacySettings() {
this.$router.push('privacy')
async generateWallet() {
await this.$store.dispatch('accounts/generateWallet')
this.$router.push('phrase')
},
importAccount() {
this.$router.push('importAccount')
Expand Down
23 changes: 0 additions & 23 deletions pages/setup/privacy/Privacy.html

This file was deleted.

51 changes: 0 additions & 51 deletions pages/setup/privacy/Privacy.less

This file was deleted.

25 changes: 0 additions & 25 deletions pages/setup/privacy/index.vue

This file was deleted.

34 changes: 27 additions & 7 deletions store/settings/actions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Vue from 'vue'
import { TextileError } from '../textile/types'
import { db } from '~/libraries/SatelliteDB/SatelliteDB'
import TextileManager from '~/libraries/Textile/TextileManager'
import { UserInfoManager } from '~/libraries/Textile/UserManager'
import { SettingsError, SettingsState } from '~/store/settings/types'
import { ActionsArguments } from '~/types/store/store'
Expand All @@ -22,18 +21,39 @@ export default {
consentScan: boolean,
) {
try {
commit('setConsentScan', consentScan)

const $TextileManager: TextileManager = Vue.prototype.$TextileManager
const $UserInfoManager: UserInfoManager =
Vue.prototype.$TextileManager.userInfoManager

if (!$TextileManager.userInfoManager) {
if (!$UserInfoManager) {
throw new Error(TextileError.USERINFO_MANAGER_NOT_FOUND)
}
const $UserInfoManager: UserInfoManager = $TextileManager.userInfoManager

$UserInfoManager.setConsent({
consentScan,
consentDate: Date.now(),
})
} catch (e) {}
commit('setConsentScan', consentScan)
} catch (e) {
console.log(e)
}
},

async setBlockNsfw(
{ commit }: ActionsArguments<SettingsState>,
blockNsfw: boolean,
) {
try {
const $UserInfoManager: UserInfoManager =
Vue.prototype.$TextileManager.userInfoManager

if (!$UserInfoManager) {
throw new Error(TextileError.USERINFO_MANAGER_NOT_FOUND)
}

$UserInfoManager.setBlockNsfw(blockNsfw)
commit('setBlockNsfw', blockNsfw)
} catch (e) {
console.log(e)
}
},
}
3 changes: 3 additions & 0 deletions store/settings/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ const mutations = {
setConsentScan(state: SettingsState, value: boolean) {
state.consentScan = value
},
setBlockNsfw(state: SettingsState, value: boolean) {
state.blockNsfw = value
},
displayCurrentActivity(state: SettingsState, value: boolean) {
state.displayCurrentActivity = value
},
Expand Down
1 change: 1 addition & 0 deletions store/settings/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const InitialSettingsState = (): SettingsState => ({
keybinds: KeybindTypes,
embeddedLinks: true,
consentScan: false,
blockNsfw: true,
displayCurrentActivity: true,
removeState: false,
serverType: 'satellite',
Expand Down
1 change: 1 addition & 0 deletions store/settings/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface SettingsState {
keybinds: object
embeddedLinks: boolean
consentScan: boolean
blockNsfw: boolean
displayCurrentActivity: boolean
timezone: string
removeState: boolean
Expand Down
19 changes: 13 additions & 6 deletions store/textile/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,20 @@ export default {
const $FileSystem: FilSystem = Vue.prototype.$FileSystem
await $FileSystem.import(fsExport)
}
const consentData = await $TextileManager.userInfoManager?.getConsentData()
if (consentData) {
const record = await $TextileManager.userInfoManager?.getUserRecord()
if (record) {
/* Log CSAM Consent Data for future ticket as Hogan requested */
Vue.prototype.$Logger.log('CSAM Consent Data', 'CSAM', consentData)
commit('settings/setConsentScan', consentData.consent_scan, {
root: true,
})
Vue.prototype.$Logger.log('CSAM Consent Data', 'CSAM', record)
if (record.consent_scan !== undefined) {
commit('settings/setConsentScan', record.consent_scan, {
root: true,
})
}
if (record.block_nsfw !== undefined) {
commit('settings/setBlockNsfw', record.block_nsfw, {
root: true,
})
}
}
return textilePublicKey
},
Expand Down
1 change: 1 addition & 0 deletions types/textile/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export interface UserdataFromThread {
user_address: string
consent_scan: boolean
consent_date: number
block_nsfw: boolean
}

0 comments on commit 0a8a264

Please sign in to comment.