merge develop, add mobile nav component
This commit is contained in:
commit
7ce8fe9214
67 changed files with 2219 additions and 697 deletions
|
@ -1,12 +1,16 @@
|
|||
const chat = {
|
||||
state: {
|
||||
messages: [],
|
||||
channel: {state: ''}
|
||||
channel: {state: ''},
|
||||
socket: null
|
||||
},
|
||||
mutations: {
|
||||
setChannel (state, channel) {
|
||||
state.channel = channel
|
||||
},
|
||||
setSocket (state, socket) {
|
||||
state.socket = socket
|
||||
},
|
||||
addMessage (state, message) {
|
||||
state.messages.push(message)
|
||||
state.messages = state.messages.slice(-19, 20)
|
||||
|
@ -16,8 +20,12 @@ const chat = {
|
|||
}
|
||||
},
|
||||
actions: {
|
||||
disconnectFromChat (store) {
|
||||
store.state.socket.disconnect()
|
||||
},
|
||||
initializeChat (store, socket) {
|
||||
const channel = socket.channel('chat:public')
|
||||
store.commit('setSocket', socket)
|
||||
channel.on('new_msg', (msg) => {
|
||||
store.commit('addMessage', msg)
|
||||
})
|
||||
|
|
|
@ -37,6 +37,7 @@ const defaultState = {
|
|||
emoji: [],
|
||||
customEmoji: [],
|
||||
restrictedNicknames: [],
|
||||
postFormats: [],
|
||||
|
||||
// Feature-set, apparently, not everything here is reported...
|
||||
mediaProxyAvailable: false,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { remove, slice, each, find, maxBy, minBy, merge, last, isArray } from 'lodash'
|
||||
import { remove, slice, each, find, maxBy, minBy, merge, first, last, isArray } from 'lodash'
|
||||
import apiService from '../services/api/api.service.js'
|
||||
// import parse from '../services/status_parser/status_parser.js'
|
||||
|
||||
|
@ -10,6 +10,7 @@ const emptyTl = (userId = 0) => ({
|
|||
visibleStatusesObject: {},
|
||||
newStatusCount: 0,
|
||||
maxId: 0,
|
||||
minId: 0,
|
||||
minVisibleId: 0,
|
||||
loading: false,
|
||||
followers: [],
|
||||
|
@ -18,7 +19,7 @@ const emptyTl = (userId = 0) => ({
|
|||
flushMarker: 0
|
||||
})
|
||||
|
||||
export const defaultState = {
|
||||
export const defaultState = () => ({
|
||||
allStatuses: [],
|
||||
allStatusesObject: {},
|
||||
maxId: 0,
|
||||
|
@ -29,7 +30,8 @@ export const defaultState = {
|
|||
data: [],
|
||||
idStore: {},
|
||||
loading: false,
|
||||
error: false
|
||||
error: false,
|
||||
fetcherId: null
|
||||
},
|
||||
favorites: new Set(),
|
||||
error: false,
|
||||
|
@ -44,7 +46,7 @@ export const defaultState = {
|
|||
tag: emptyTl(),
|
||||
dms: emptyTl()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export const prepareStatus = (status) => {
|
||||
// Set deleted flag
|
||||
|
@ -117,11 +119,16 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
|
|||
const timelineObject = state.timelines[timeline]
|
||||
|
||||
const maxNew = statuses.length > 0 ? maxBy(statuses, 'id').id : 0
|
||||
const older = timeline && maxNew < timelineObject.maxId
|
||||
const minNew = statuses.length > 0 ? minBy(statuses, 'id').id : 0
|
||||
const newer = timeline && maxNew > timelineObject.maxId && statuses.length > 0
|
||||
const older = timeline && (minNew < timelineObject.minId || timelineObject.minId === 0) && statuses.length > 0
|
||||
|
||||
if (timeline && !noIdUpdate && statuses.length > 0 && !older) {
|
||||
if (!noIdUpdate && newer) {
|
||||
timelineObject.maxId = maxNew
|
||||
}
|
||||
if (!noIdUpdate && older) {
|
||||
timelineObject.minId = minNew
|
||||
}
|
||||
|
||||
// This makes sure that user timeline won't get data meant for other
|
||||
// user. I.e. opening different user profiles makes request which could
|
||||
|
@ -255,12 +262,9 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
|
|||
processor(status)
|
||||
})
|
||||
|
||||
// Keep the visible statuses sorted
|
||||
// Keep the visible statuses sorted
|
||||
if (timeline) {
|
||||
sortTimeline(timelineObject)
|
||||
if ((older || timelineObject.minVisibleId <= 0) && statuses.length > 0) {
|
||||
timelineObject.minVisibleId = minBy(statuses, 'id').id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -309,18 +313,39 @@ const addNewNotifications = (state, { dispatch, notifications, older, visibleNot
|
|||
})
|
||||
}
|
||||
|
||||
const removeStatus = (state, { timeline, userId }) => {
|
||||
const timelineObject = state.timelines[timeline]
|
||||
if (userId) {
|
||||
remove(timelineObject.statuses, { user: { id: userId } })
|
||||
remove(timelineObject.visibleStatuses, { user: { id: userId } })
|
||||
timelineObject.minVisibleId = timelineObject.visibleStatuses.length > 0 ? last(timelineObject.visibleStatuses).id : 0
|
||||
timelineObject.maxId = timelineObject.statuses.length > 0 ? first(timelineObject.statuses).id : 0
|
||||
}
|
||||
}
|
||||
|
||||
export const mutations = {
|
||||
addNewStatuses,
|
||||
addNewNotifications,
|
||||
removeStatus,
|
||||
showNewStatuses (state, { timeline }) {
|
||||
const oldTimeline = (state.timelines[timeline])
|
||||
|
||||
oldTimeline.newStatusCount = 0
|
||||
oldTimeline.visibleStatuses = slice(oldTimeline.statuses, 0, 50)
|
||||
oldTimeline.minVisibleId = last(oldTimeline.visibleStatuses).id
|
||||
oldTimeline.minId = oldTimeline.minVisibleId
|
||||
oldTimeline.visibleStatusesObject = {}
|
||||
each(oldTimeline.visibleStatuses, (status) => { oldTimeline.visibleStatusesObject[status.id] = status })
|
||||
},
|
||||
setNotificationFetcher (state, { fetcherId }) {
|
||||
state.notifications.fetcherId = fetcherId
|
||||
},
|
||||
resetStatuses (state) {
|
||||
const emptyState = defaultState()
|
||||
Object.entries(emptyState).forEach(([key, value]) => {
|
||||
state[key] = value
|
||||
})
|
||||
},
|
||||
clearTimeline (state, { timeline }) {
|
||||
state.timelines[timeline] = emptyTl(state.timelines[timeline].userId)
|
||||
},
|
||||
|
@ -371,7 +396,7 @@ export const mutations = {
|
|||
}
|
||||
|
||||
const statuses = {
|
||||
state: defaultState,
|
||||
state: defaultState(),
|
||||
actions: {
|
||||
addNewStatuses ({ rootState, commit }, { statuses, showImmediately = false, timeline = false, noIdUpdate = false, userId }) {
|
||||
commit('addNewStatuses', { statuses, showImmediately, timeline, noIdUpdate, user: rootState.users.currentUser, userId })
|
||||
|
@ -391,6 +416,12 @@ const statuses = {
|
|||
setNotificationsSilence ({ rootState, commit }, { value }) {
|
||||
commit('setNotificationsSilence', { value })
|
||||
},
|
||||
stopFetchingNotifications ({ rootState, commit }) {
|
||||
if (rootState.statuses.notifications.fetcherId) {
|
||||
window.clearInterval(rootState.statuses.notifications.fetcherId)
|
||||
}
|
||||
commit('setNotificationFetcher', { fetcherId: null })
|
||||
},
|
||||
deleteStatus ({ rootState, commit }, status) {
|
||||
commit('setDeleted', { status })
|
||||
apiService.deleteStatus({ id: status.id, credentials: rootState.users.currentUser.credentials })
|
||||
|
|
|
@ -292,9 +292,12 @@ const users = {
|
|||
|
||||
logout (store) {
|
||||
store.commit('clearCurrentUser')
|
||||
store.dispatch('disconnectFromChat')
|
||||
store.commit('setToken', false)
|
||||
store.dispatch('stopFetching', 'friends')
|
||||
store.commit('setBackendInteractor', backendInteractorService())
|
||||
store.dispatch('stopFetchingNotifications')
|
||||
store.commit('resetStatuses')
|
||||
},
|
||||
loginUser (store, accessToken) {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
@ -319,6 +322,9 @@ const users = {
|
|||
|
||||
if (user.token) {
|
||||
store.dispatch('setWsToken', user.token)
|
||||
|
||||
// Initialize the chat socket.
|
||||
store.dispatch('initializeSocket')
|
||||
}
|
||||
|
||||
// Start getting fresh posts.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue