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 (11869B)


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