diff options
| author | Henry Jameson <me@hjkos.com> | 2018-12-13 17:50:36 +0300 |
|---|---|---|
| committer | Henry Jameson <me@hjkos.com> | 2018-12-13 17:50:36 +0300 |
| commit | 610724ffcd6bd22f496f45a955e80f7f2a051e1a (patch) | |
| tree | 0f48b0844429eae0bb6283c9df9c6d609bd7b828 /src/modules | |
| parent | 403c86e4d1b0067634d1f0f6bd3d6908f8b4481b (diff) | |
| parent | dbe79a3c2673b9a14bd8f3b037eca5999dd6a018 (diff) | |
Merge remote-tracking branch 'upstream/develop' into mobile-back
* upstream/develop: (142 commits)
fix timeago font
added hide_network option, fixed properties naming
Fix fetching new users, add storing local users in usersObjects with their screen_name as well as id, so that they could be fetched zero-state with screen-name link.
improve notification subscription
Fix typo that prevented scope copy from working.
added check for activatePanel is function or not
addressed PR comments
activate panel on user screen click
added not preload check so hidden toggles asap
removed counters from left panel
added router-links to all relavent links
added activatePanel onclick for timeago button
added PR comments
add checkbox to disable web push
removed brackets from condition
resolved lint issue
renamed config to preload images and add ident to config
added config for preload and made attachment responsive to it
preload nsfw image
fix
...
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/config.js | 8 | ||||
| -rw-r--r-- | src/modules/errors.js | 12 | ||||
| -rw-r--r-- | src/modules/instance.js | 4 | ||||
| -rw-r--r-- | src/modules/interface.js | 17 | ||||
| -rw-r--r-- | src/modules/users.js | 87 |
5 files changed, 108 insertions, 20 deletions
diff --git a/src/modules/config.js b/src/modules/config.js index f23cacb7..ccfd0190 100644 --- a/src/modules/config.js +++ b/src/modules/config.js @@ -1,5 +1,5 @@ import { set, delete as del } from 'vue' -import StyleSetter from '../services/style_setter/style_setter.js' +import { setPreset, applyTheme } from '../services/style_setter/style_setter.js' const browserLocale = (window.navigator.language || 'en').split('-')[0] @@ -9,6 +9,7 @@ const defaultState = { hideAttachments: false, hideAttachmentsInConv: false, hideNsfw: true, + preloadImage: true, loopVideo: true, loopVideoSilentOnly: true, autoLoad: true, @@ -23,6 +24,7 @@ const defaultState = { likes: true, repeats: true }, + webPushNotifications: true, muteWords: [], highlight: {}, interfaceLanguage: browserLocale, @@ -54,10 +56,10 @@ const config = { commit('setOption', {name, value}) switch (name) { case 'theme': - StyleSetter.setPreset(value, commit) + setPreset(value, commit) break case 'customTheme': - StyleSetter.setColors(value, commit) + applyTheme(value, commit) } } } diff --git a/src/modules/errors.js b/src/modules/errors.js new file mode 100644 index 00000000..c809e1b5 --- /dev/null +++ b/src/modules/errors.js @@ -0,0 +1,12 @@ +import { capitalize } from 'lodash' + +export function humanizeErrors (errors) { + return Object.entries(errors).reduce((errs, [k, val]) => { + let message = val.reduce((acc, message) => { + let key = capitalize(k.replace(/_/g, ' ')) + return acc + [key, message].join(' ') + '. ' + }, '') + return [...errs, message] + }, []) +} + diff --git a/src/modules/instance.js b/src/modules/instance.js index 641424b6..7c27d52a 100644 --- a/src/modules/instance.js +++ b/src/modules/instance.js @@ -1,5 +1,5 @@ import { set } from 'vue' -import StyleSetter from '../services/style_setter/style_setter.js' +import { setPreset } from '../services/style_setter/style_setter.js' const defaultState = { // Stuff from static/config.json and apiConfig @@ -60,7 +60,7 @@ const instance = { dispatch('setPageTitle') break case 'theme': - StyleSetter.setPreset(value, commit) + setPreset(value, commit) } } } diff --git a/src/modules/interface.js b/src/modules/interface.js index 07489685..956c9cb3 100644 --- a/src/modules/interface.js +++ b/src/modules/interface.js @@ -3,7 +3,14 @@ import { set, delete as del } from 'vue' const defaultState = { settings: { currentSaveStateNotice: null, - noticeClearTimeout: null + noticeClearTimeout: null, + notificationPermission: null + }, + browserSupport: { + cssFilter: window.CSS && window.CSS.supports && ( + window.CSS.supports('filter', 'drop-shadow(0 0)') || + window.CSS.supports('-webkit-filter', 'drop-shadow(0 0)') + ) } } @@ -17,10 +24,13 @@ const interfaceMod = { } set(state.settings, 'currentSaveStateNotice', { error: false, data: success }) set(state.settings, 'noticeClearTimeout', - setTimeout(() => del(state.settings, 'currentSaveStateNotice'), 2000)) + setTimeout(() => del(state.settings, 'currentSaveStateNotice'), 2000)) } else { set(state.settings, 'currentSaveStateNotice', { error: true, errorData: error }) } + }, + setNotificationPermission (state, permission) { + state.notificationPermission = permission } }, actions: { @@ -29,6 +39,9 @@ const interfaceMod = { }, settingsSaved ({ commit, dispatch }, { success, error }) { commit('settingsSaved', { success, error }) + }, + setNotificationPermission ({ commit }, permission) { + commit('setNotificationPermission', permission) } } } diff --git a/src/modules/users.js b/src/modules/users.js index 8630ee0d..25d1c81f 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -1,6 +1,9 @@ import backendInteractorService from '../services/backend_interactor_service/backend_interactor_service.js' import { compact, map, each, merge } from 'lodash' import { set } from 'vue' +import registerPushNotifications from '../services/push/push.js' +import oauthApi from '../services/new_api/oauth' +import { humanizeErrors } from './errors' // TODO: Unify with mergeOrAdd in statuses.js export const mergeOrAdd = (arr, obj, item) => { @@ -9,17 +12,28 @@ export const mergeOrAdd = (arr, obj, item) => { if (oldItem) { // We already have this, so only merge the new info. merge(oldItem, item) - return {item: oldItem, new: false} + return { item: oldItem, new: false } } else { // This is a new item, prepare it arr.push(item) obj[item.id] = item - return {item, new: true} + if (item.screen_name && !item.screen_name.includes('@')) { + obj[item.screen_name] = item + } + return { item, new: true } } } +const getNotificationPermission = () => { + const Notification = window.Notification + + if (!Notification) return Promise.resolve(null) + if (Notification.permission === 'default') return Notification.requestPermission() + return Promise.resolve(Notification.permission) +} + export const mutations = { - setMuted (state, { user: {id}, muted }) { + setMuted (state, { user: { id }, muted }) { const user = state.usersObject[id] set(user, 'muted', muted) }, @@ -43,18 +57,31 @@ export const mutations = { setUserForStatus (state, status) { status.user = state.usersObject[status.user.id] }, - setColor (state, { user: {id}, highlighted }) { + setColor (state, { user: { id }, highlighted }) { const user = state.usersObject[id] set(user, 'highlight', highlighted) + }, + signUpPending (state) { + state.signUpPending = true + state.signUpErrors = [] + }, + signUpSuccess (state) { + state.signUpPending = false + }, + signUpFailure (state, errors) { + state.signUpPending = false + state.signUpErrors = errors } } export const defaultState = { + loggingIn: false, lastLoginName: false, currentUser: false, - loggingIn: false, users: [], - usersObject: {} + usersObject: {}, + signUpPending: false, + signUpErrors: [] } const users = { @@ -62,8 +89,15 @@ const users = { mutations, actions: { fetchUser (store, id) { - store.rootState.api.backendInteractor.fetchUser({id}) - .then((user) => store.commit('addNewUsers', user)) + store.rootState.api.backendInteractor.fetchUser({ id }) + .then((user) => store.commit('addNewUsers', [user])) + }, + registerPushNotifications (store) { + const token = store.state.currentUser.credentials + const vapidPublicKey = store.rootState.instance.vapidPublicKey + const isEnabled = store.rootState.config.webPushNotifications + + registerPushNotifications(isEnabled, vapidPublicKey, token) }, addNewStatuses (store, { statuses }) { const users = map(statuses, 'user') @@ -80,6 +114,34 @@ const users = { store.commit('setUserForStatus', status) }) }, + async signUp (store, userInfo) { + store.commit('signUpPending') + + let rootState = store.rootState + + let response = await rootState.api.backendInteractor.register(userInfo) + if (response.ok) { + const data = { + oauth: rootState.oauth, + instance: rootState.instance.server + } + let app = await oauthApi.getOrCreateApp(data) + let result = await oauthApi.getTokenWithCredentials({ + app, + instance: data.instance, + username: userInfo.username, + password: userInfo.password + }) + store.commit('signUpSuccess') + store.commit('setToken', result.access_token) + store.dispatch('loginUser', result.access_token) + } else { + let data = await response.json() + let errors = humanizeErrors(JSON.parse(data.error)) + store.commit('signUpFailure', errors) + throw Error(errors) + } + }, logout (store) { store.commit('clearCurrentUser') store.commit('setToken', false) @@ -100,6 +162,9 @@ const users = { commit('setCurrentUser', user) commit('addNewUsers', [user]) + getNotificationPermission() + .then(permission => commit('setNotificationPermission', permission)) + // Set our new backend interactor commit('setBackendInteractor', backendInteractorService(accessToken)) @@ -118,12 +183,8 @@ const users = { store.commit('addNewUsers', mutedUsers) }) - if ('Notification' in window && window.Notification.permission === 'default') { - window.Notification.requestPermission() - } - // Fetch our friends - store.rootState.api.backendInteractor.fetchFriends({id: user.id}) + store.rootState.api.backendInteractor.fetchFriends({ id: user.id }) .then((friends) => commit('addNewUsers', friends)) }) } else { |
