ftfy
This commit is contained in:
parent
11716a7a53
commit
e9c755608f
3 changed files with 17 additions and 36 deletions
11
src/main.js
11
src/main.js
|
@ -10,7 +10,6 @@ import apiModule from './modules/api.js'
|
||||||
import configModule from './modules/config.js'
|
import configModule from './modules/config.js'
|
||||||
import chatModule from './modules/chat.js'
|
import chatModule from './modules/chat.js'
|
||||||
import oauthModule from './modules/oauth.js'
|
import oauthModule from './modules/oauth.js'
|
||||||
import pushNotificationsModule from './modules/pushNotifications.js'
|
|
||||||
|
|
||||||
import VueTimeago from 'vue-timeago'
|
import VueTimeago from 'vue-timeago'
|
||||||
import VueI18n from 'vue-i18n'
|
import VueI18n from 'vue-i18n'
|
||||||
|
@ -61,13 +60,19 @@ createPersistedState(persistedStateOptions).then((persistedState) => {
|
||||||
api: apiModule,
|
api: apiModule,
|
||||||
config: configModule,
|
config: configModule,
|
||||||
chat: chatModule,
|
chat: chatModule,
|
||||||
oauth: oauthModule,
|
oauth: oauthModule
|
||||||
pushNotifications: pushNotificationsModule
|
|
||||||
},
|
},
|
||||||
plugins: [persistedState],
|
plugins: [persistedState],
|
||||||
strict: false // Socket modifies itself, let's ignore this for now.
|
strict: false // Socket modifies itself, let's ignore this for now.
|
||||||
// strict: process.env.NODE_ENV !== 'production'
|
// strict: process.env.NODE_ENV !== 'production'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
store.subscribe((mutation, state) => {
|
||||||
|
if ((mutation.type === 'setCurrentUser' && state.config.vapidPublicKey) || // Login + existing key
|
||||||
|
(mutation.type === 'setInstanceOption' && mutation.payload.name === 'vapidPublicKey' && state.users.currentUser)) { // Logged in, key arrives late
|
||||||
|
store.dispatch('registerPushNotifications')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
afterStoreSetup({ store, i18n })
|
afterStoreSetup({ store, i18n })
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
import registerPushNotifications from '../services/push/push.js'
|
|
||||||
|
|
||||||
const subscribe = {
|
|
||||||
state: {
|
|
||||||
token: null,
|
|
||||||
vapidPublicKey: null
|
|
||||||
},
|
|
||||||
mutations: {
|
|
||||||
setApiToken (state, user) {
|
|
||||||
state.token = user.credentials
|
|
||||||
},
|
|
||||||
setVapidPublicKey (state, vapidPublicKey) {
|
|
||||||
state.vapidPublicKey = vapidPublicKey
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
actions: {
|
|
||||||
setInstanceOption (store, { name, value }) {
|
|
||||||
store.commit('setVapidPublicKey', value)
|
|
||||||
if (store.state.token) registerPushNotifications(this)
|
|
||||||
},
|
|
||||||
setCurrentUser (store, user) {
|
|
||||||
store.commit('setApiToken', user.credentials)
|
|
||||||
if (store.state.vapidPublicKey) registerPushNotifications(this)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default subscribe
|
|
|
@ -1,6 +1,7 @@
|
||||||
import backendInteractorService from '../services/backend_interactor_service/backend_interactor_service.js'
|
import backendInteractorService from '../services/backend_interactor_service/backend_interactor_service.js'
|
||||||
import { compact, map, each, merge } from 'lodash'
|
import { compact, map, each, merge } from 'lodash'
|
||||||
import { set } from 'vue'
|
import { set } from 'vue'
|
||||||
|
import registerPushNotifications from '../services/push/push.js'
|
||||||
|
|
||||||
// TODO: Unify with mergeOrAdd in statuses.js
|
// TODO: Unify with mergeOrAdd in statuses.js
|
||||||
export const mergeOrAdd = (arr, obj, item) => {
|
export const mergeOrAdd = (arr, obj, item) => {
|
||||||
|
@ -65,6 +66,9 @@ const users = {
|
||||||
store.rootState.api.backendInteractor.fetchUser({id})
|
store.rootState.api.backendInteractor.fetchUser({id})
|
||||||
.then((user) => store.commit('addNewUsers', user))
|
.then((user) => store.commit('addNewUsers', user))
|
||||||
},
|
},
|
||||||
|
registerPushNotifications (store) {
|
||||||
|
registerPushNotifications(store)
|
||||||
|
},
|
||||||
addNewStatuses (store, { statuses }) {
|
addNewStatuses (store, { statuses }) {
|
||||||
const users = map(statuses, 'user')
|
const users = map(statuses, 'user')
|
||||||
const retweetedUsers = compact(map(statuses, 'retweeted_status.user'))
|
const retweetedUsers = compact(map(statuses, 'retweeted_status.user'))
|
||||||
|
@ -116,10 +120,11 @@ const users = {
|
||||||
store.dispatch('startFetching', ['own', user.id])
|
store.dispatch('startFetching', ['own', user.id])
|
||||||
|
|
||||||
// Get user mutes and follower info
|
// Get user mutes and follower info
|
||||||
store.rootState.api.backendInteractor.fetchMutes().then((mutedUsers) => {
|
store.rootState.api.backendInteractor.fetchMutes()
|
||||||
each(mutedUsers, (user) => { user.muted = true })
|
.then((mutedUsers) => {
|
||||||
store.commit('addNewUsers', mutedUsers)
|
each(mutedUsers, (user) => { user.muted = true })
|
||||||
})
|
store.commit('addNewUsers', mutedUsers)
|
||||||
|
})
|
||||||
|
|
||||||
// Fetch our friends
|
// Fetch our friends
|
||||||
store.rootState.api.backendInteractor.fetchFriends({id: user.id})
|
store.rootState.api.backendInteractor.fetchFriends({id: user.id})
|
||||||
|
|
Loading…
Reference in a new issue