logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe

settings.js (4479B)


      1 /* eslint-env browser */
      2 import { filter, trim } from 'lodash'
      3 
      4 import TabSwitcher from '../tab_switcher/tab_switcher.js'
      5 import StyleSwitcher from '../style_switcher/style_switcher.vue'
      6 import InterfaceLanguageSwitcher from '../interface_language_switcher/interface_language_switcher.vue'
      7 import { extractCommit } from '../../services/version/version.service'
      8 import { instanceDefaultProperties, defaultState as configDefaultState } from '../../modules/config.js'
      9 import Checkbox from '../checkbox/checkbox.vue'
     10 
     11 const pleromaFeCommitUrl = 'https://git.pleroma.social/pleroma/pleroma-fe/commit/'
     12 const pleromaBeCommitUrl = 'https://git.pleroma.social/pleroma/pleroma/commit/'
     13 
     14 const multiChoiceProperties = [
     15   'postContentType',
     16   'subjectLineBehavior'
     17 ]
     18 
     19 const settings = {
     20   data () {
     21     const instance = this.$store.state.instance
     22 
     23     return {
     24       loopSilentAvailable:
     25         // Firefox
     26         Object.getOwnPropertyDescriptor(HTMLVideoElement.prototype, 'mozHasAudio') ||
     27         // Chrome-likes
     28         Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype, 'webkitAudioDecodedByteCount') ||
     29         // Future spec, still not supported in Nightly 63 as of 08/2018
     30         Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype, 'audioTracks'),
     31 
     32       backendVersion: instance.backendVersion,
     33       frontendVersion: instance.frontendVersion
     34     }
     35   },
     36   components: {
     37     TabSwitcher,
     38     StyleSwitcher,
     39     InterfaceLanguageSwitcher,
     40     Checkbox
     41   },
     42   computed: {
     43     user () {
     44       return this.$store.state.users.currentUser
     45     },
     46     currentSaveStateNotice () {
     47       return this.$store.state.interface.settings.currentSaveStateNotice
     48     },
     49     postFormats () {
     50       return this.$store.state.instance.postFormats || []
     51     },
     52     instanceSpecificPanelPresent () { return this.$store.state.instance.showInstanceSpecificPanel },
     53     frontendVersionLink () {
     54       return pleromaFeCommitUrl + this.frontendVersion
     55     },
     56     backendVersionLink () {
     57       return pleromaBeCommitUrl + extractCommit(this.backendVersion)
     58     },
     59     // Getting localized values for instance-default properties
     60     ...instanceDefaultProperties
     61       .filter(key => multiChoiceProperties.includes(key))
     62       .map(key => [
     63         key + 'DefaultValue',
     64         function () {
     65           return this.$store.getters.instanceDefaultConfig[key]
     66         }
     67       ])
     68       .reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {}),
     69     ...instanceDefaultProperties
     70       .filter(key => !multiChoiceProperties.includes(key))
     71       .map(key => [
     72         key + 'LocalizedValue',
     73         function () {
     74           return this.$t('settings.values.' + this.$store.getters.instanceDefaultConfig[key])
     75         }
     76       ])
     77       .reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {}),
     78     // Generating computed values for vuex properties
     79     ...Object.keys(configDefaultState)
     80       .map(key => [key, {
     81         get () { return this.$store.getters.mergedConfig[key] },
     82         set (value) {
     83           this.$store.dispatch('setOption', { name: key, value })
     84         }
     85       }])
     86       .reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {}),
     87     // Special cases (need to transform values or perform actions first)
     88     muteWordsString: {
     89       get () { return this.$store.getters.mergedConfig.muteWords.join('\n') },
     90       set (value) {
     91         this.$store.dispatch('setOption', {
     92           name: 'muteWords',
     93           value: filter(value.split('\n'), (word) => trim(word).length > 0)
     94         })
     95       }
     96     },
     97     useStreamingApi: {
     98       get () { return this.$store.getters.mergedConfig.useStreamingApi },
     99       set (value) {
    100         const promise = value
    101           ? this.$store.dispatch('enableMastoSockets')
    102           : this.$store.dispatch('disableMastoSockets')
    103 
    104         promise.then(() => {
    105           this.$store.dispatch('setOption', { name: 'useStreamingApi', value })
    106         }).catch((e) => {
    107           console.error('Failed starting MastoAPI Streaming socket', e)
    108           this.$store.dispatch('disableMastoSockets')
    109           this.$store.dispatch('setOption', { name: 'useStreamingApi', value: false })
    110         })
    111       }
    112     }
    113   },
    114   // Updating nested properties
    115   watch: {
    116     notificationVisibility: {
    117       handler (value) {
    118         this.$store.dispatch('setOption', {
    119           name: 'notificationVisibility',
    120           value: this.$store.getters.mergedConfig.notificationVisibility
    121         })
    122       },
    123       deep: true
    124     }
    125   }
    126 }
    127 
    128 export default settings