logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://anongit.hacktivis.me/git/pleroma-fe.git/

config.js (11349B)


  1. import Cookies from 'js-cookie'
  2. import { applyConfig } from '../services/style_setter/style_setter.js'
  3. import messages from '../i18n/messages'
  4. import { set } from 'lodash'
  5. import localeService from '../services/locale/locale.service.js'
  6. const BACKEND_LANGUAGE_COOKIE_NAME = 'userLanguage'
  7. const APPEARANCE_SETTINGS_KEYS = new Set([
  8. 'sidebarColumnWidth',
  9. 'contentColumnWidth',
  10. 'notifsColumnWidth',
  11. 'textSize',
  12. 'navbarSize',
  13. 'panelHeaderSize',
  14. 'forcedRoundness',
  15. 'emojiSize',
  16. 'emojiReactionsScale'
  17. ])
  18. const browserLocale = (window.navigator.language || 'en').split('-')[0]
  19. /* TODO this is a bit messy.
  20. * We need to declare settings with their types and also deal with
  21. * instance-default settings in some way, hopefully try to avoid copy-pasta
  22. * in general.
  23. */
  24. export const multiChoiceProperties = [
  25. 'postContentType',
  26. 'subjectLineBehavior',
  27. 'conversationDisplay', // tree | linear
  28. 'conversationOtherRepliesButton', // below | inside
  29. 'mentionLinkDisplay', // short | full_for_remote | full
  30. 'userPopoverAvatarAction' // close | zoom | open
  31. ]
  32. export const defaultState = {
  33. expertLevel: 0, // used to track which settings to show and hide
  34. // Theme stuff
  35. theme: undefined, // Very old theme store, stores preset name, still in use
  36. // V1
  37. colors: {}, // VERY old theme store, just colors of V1, probably not even used anymore
  38. // V2
  39. customTheme: undefined, // "snapshot", previously was used as actual theme store for V2 so it's still used in case of PleromaFE downgrade event.
  40. customThemeSource: undefined, // "source", stores original theme data
  41. // V3
  42. themeDebug: false, // debug mode that uses computed backgrounds instead of real ones to debug contrast functions
  43. forceThemeRecompilation: false, // flag that forces recompilation on boot even if cache exists
  44. theme3hacks: { // Hacks, user overrides that are independent of theme used
  45. underlay: 'none',
  46. fonts: {
  47. interface: undefined,
  48. input: undefined,
  49. post: undefined,
  50. monospace: undefined
  51. }
  52. },
  53. hideISP: false,
  54. hideInstanceWallpaper: false,
  55. hideShoutbox: false,
  56. // bad name: actually hides posts of muted USERS
  57. hideMutedPosts: undefined, // instance default
  58. hideMutedThreads: undefined, // instance default
  59. hideWordFilteredPosts: undefined, // instance default
  60. muteBotStatuses: undefined, // instance default
  61. muteSensitiveStatuses: undefined, // instance default
  62. collapseMessageWithSubject: undefined, // instance default
  63. padEmoji: true,
  64. hideAttachments: false,
  65. hideAttachmentsInConv: false,
  66. hideScrobbles: false,
  67. hideScrobblesAfter: '2d',
  68. maxThumbnails: 16,
  69. hideNsfw: true,
  70. preloadImage: true,
  71. loopVideo: true,
  72. loopVideoSilentOnly: true,
  73. streaming: false,
  74. emojiReactionsOnTimeline: true,
  75. alwaysShowNewPostButton: false,
  76. autohideFloatingPostButton: false,
  77. pauseOnUnfocused: true,
  78. stopGifs: true,
  79. replyVisibility: 'all',
  80. thirdColumnMode: 'notifications',
  81. notificationVisibility: {
  82. follows: true,
  83. mentions: true,
  84. statuses: true,
  85. likes: true,
  86. repeats: true,
  87. moves: true,
  88. emojiReactions: true,
  89. followRequest: true,
  90. reports: true,
  91. chatMention: true,
  92. polls: true
  93. },
  94. notificationNative: {
  95. follows: true,
  96. mentions: true,
  97. statuses: true,
  98. likes: false,
  99. repeats: false,
  100. moves: false,
  101. emojiReactions: false,
  102. followRequest: true,
  103. reports: true,
  104. chatMention: true,
  105. polls: true
  106. },
  107. webPushNotifications: false,
  108. webPushAlwaysShowNotifications: false,
  109. muteWords: [],
  110. highlight: {},
  111. interfaceLanguage: browserLocale,
  112. hideScopeNotice: false,
  113. useStreamingApi: false,
  114. sidebarRight: undefined, // instance default
  115. scopeCopy: undefined, // instance default
  116. subjectLineBehavior: undefined, // instance default
  117. alwaysShowSubjectInput: undefined, // instance default
  118. postContentType: undefined, // instance default
  119. minimalScopesMode: undefined, // instance default
  120. // This hides statuses filtered via a word filter
  121. hideFilteredStatuses: undefined, // instance default
  122. modalOnRepeat: undefined, // instance default
  123. modalOnUnfollow: undefined, // instance default
  124. modalOnBlock: undefined, // instance default
  125. modalOnMute: undefined, // instance default
  126. modalOnDelete: undefined, // instance default
  127. modalOnLogout: undefined, // instance default
  128. modalOnApproveFollow: undefined, // instance default
  129. modalOnDenyFollow: undefined, // instance default
  130. modalOnRemoveUserFromFollowers: undefined, // instance default
  131. playVideosInModal: false,
  132. useOneClickNsfw: false,
  133. useContainFit: true,
  134. disableStickyHeaders: false,
  135. showScrollbars: false,
  136. userPopoverAvatarAction: 'open',
  137. userPopoverOverlay: false,
  138. sidebarColumnWidth: '25rem',
  139. contentColumnWidth: '45rem',
  140. notifsColumnWidth: '25rem',
  141. emojiReactionsScale: undefined,
  142. textSize: undefined, // instance default
  143. emojiSize: undefined, // instance default
  144. navbarSize: undefined, // instance default
  145. panelHeaderSize: undefined, // instance default
  146. forcedRoundness: undefined, // instance default
  147. navbarColumnStretch: false,
  148. greentext: undefined, // instance default
  149. useAtIcon: undefined, // instance default
  150. mentionLinkDisplay: undefined, // instance default
  151. mentionLinkShowTooltip: undefined, // instance default
  152. mentionLinkShowAvatar: undefined, // instance default
  153. mentionLinkFadeDomain: undefined, // instance default
  154. mentionLinkShowYous: undefined, // instance default
  155. mentionLinkBoldenYou: undefined, // instance default
  156. hidePostStats: undefined, // instance default
  157. hideBotIndication: undefined, // instance default
  158. hideUserStats: undefined, // instance default
  159. virtualScrolling: undefined, // instance default
  160. sensitiveByDefault: undefined, // instance default
  161. conversationDisplay: undefined, // instance default
  162. conversationTreeAdvanced: undefined, // instance default
  163. conversationOtherRepliesButton: undefined, // instance default
  164. conversationTreeFadeAncestors: undefined, // instance default
  165. showExtraNotifications: undefined, // instance default
  166. showExtraNotificationsTip: undefined, // instance default
  167. showChatsInExtraNotifications: undefined, // instance default
  168. showAnnouncementsInExtraNotifications: undefined, // instance default
  169. showFollowRequestsInExtraNotifications: undefined, // instance default
  170. maxDepthInThread: undefined, // instance default
  171. autocompleteSelect: undefined, // instance default
  172. closingDrawerMarksAsSeen: undefined, // instance default
  173. unseenAtTop: undefined, // instance default
  174. ignoreInactionableSeen: undefined // instance default
  175. }
  176. // caching the instance default properties
  177. export const instanceDefaultProperties = Object.entries(defaultState)
  178. .filter(([key, value]) => value === undefined)
  179. .map(([key, value]) => key)
  180. const config = {
  181. state: { ...defaultState },
  182. getters: {
  183. defaultConfig (state, getters, rootState, rootGetters) {
  184. const { instance } = rootState
  185. return {
  186. ...defaultState,
  187. ...Object.fromEntries(
  188. instanceDefaultProperties.map(key => [key, instance[key]])
  189. )
  190. }
  191. },
  192. mergedConfig (state, getters, rootState, rootGetters) {
  193. const { defaultConfig } = rootGetters
  194. return {
  195. ...defaultConfig,
  196. // Do not override with undefined
  197. ...Object.fromEntries(Object.entries(state).filter(([k, v]) => v !== undefined))
  198. }
  199. }
  200. },
  201. mutations: {
  202. setOptionTemporarily (state, { name, value }) {
  203. set(state, name, value)
  204. applyConfig(state)
  205. },
  206. setOption (state, { name, value }) {
  207. set(state, name, value)
  208. },
  209. setHighlight (state, { user, color, type }) {
  210. const data = this.state.config.highlight[user]
  211. if (color || type) {
  212. state.highlight[user] = { color: color || data.color, type: type || data.type }
  213. } else {
  214. delete state.highlight[user]
  215. }
  216. }
  217. },
  218. actions: {
  219. loadSettings ({ dispatch }, data) {
  220. const knownKeys = new Set(Object.keys(defaultState))
  221. const presentKeys = new Set(Object.keys(data))
  222. const intersection = new Set()
  223. for (const elem of presentKeys) {
  224. if (knownKeys.has(elem)) {
  225. intersection.add(elem)
  226. }
  227. }
  228. intersection.forEach(
  229. name => dispatch('setOption', { name, value: data[name] })
  230. )
  231. },
  232. setHighlight ({ commit, dispatch }, { user, color, type }) {
  233. commit('setHighlight', { user, color, type })
  234. },
  235. setOptionTemporarily ({ commit, dispatch, state, rootState }, { name, value }) {
  236. if (rootState.interface.temporaryChangesTimeoutId !== null) {
  237. console.warn('Can\'t track more than one temporary change')
  238. return
  239. }
  240. const oldValue = state[name]
  241. commit('setOptionTemporarily', { name, value })
  242. const confirm = () => {
  243. dispatch('setOption', { name, value })
  244. commit('clearTemporaryChanges')
  245. }
  246. const revert = () => {
  247. commit('setOptionTemporarily', { name, value: oldValue })
  248. commit('clearTemporaryChanges')
  249. }
  250. commit('setTemporaryChanges', {
  251. timeoutId: setTimeout(revert, 10000),
  252. confirm,
  253. revert
  254. })
  255. },
  256. setThemeV2 ({ commit, dispatch }, { customTheme, customThemeSource }) {
  257. commit('setOption', { name: 'theme', value: 'custom' })
  258. commit('setOption', { name: 'customTheme', value: customTheme })
  259. commit('setOption', { name: 'customThemeSource', value: customThemeSource })
  260. dispatch('setTheme', { themeData: customThemeSource, recompile: true })
  261. },
  262. setOption ({ commit, dispatch, state }, { name, value }) {
  263. const exceptions = new Set([
  264. 'useStreamingApi'
  265. ])
  266. if (exceptions.has(name)) {
  267. switch (name) {
  268. case 'useStreamingApi': {
  269. const action = value ? 'enableMastoSockets' : 'disableMastoSockets'
  270. dispatch(action).then(() => {
  271. commit('setOption', { name: 'useStreamingApi', value })
  272. }).catch((e) => {
  273. console.error('Failed starting MastoAPI Streaming socket', e)
  274. dispatch('disableMastoSockets')
  275. dispatch('setOption', { name: 'useStreamingApi', value: false })
  276. })
  277. break
  278. }
  279. }
  280. } else {
  281. commit('setOption', { name, value })
  282. if (APPEARANCE_SETTINGS_KEYS.has(name)) {
  283. applyConfig(state)
  284. }
  285. if (name.startsWith('theme3hacks')) {
  286. dispatch('setTheme', { recompile: true })
  287. }
  288. switch (name) {
  289. case 'theme':
  290. if (value === 'custom') break
  291. dispatch('setTheme', { themeName: value, recompile: true, saveData: true })
  292. break
  293. case 'themeDebug': {
  294. dispatch('setTheme', { recompile: true })
  295. break
  296. }
  297. case 'interfaceLanguage':
  298. messages.setLanguage(this.getters.i18n, value)
  299. dispatch('loadUnicodeEmojiData', value)
  300. Cookies.set(
  301. BACKEND_LANGUAGE_COOKIE_NAME,
  302. localeService.internalToBackendLocaleMulti(value)
  303. )
  304. break
  305. case 'thirdColumnMode':
  306. dispatch('setLayoutWidth', undefined)
  307. break
  308. }
  309. }
  310. }
  311. }
  312. }
  313. export default config