Add groups module.
This commit is contained in:
parent
b25b993309
commit
9c90b019d1
|
@ -15,6 +15,7 @@ import UserSettings from './components/user_settings/user_settings.vue'
|
|||
|
||||
import statusesModule from './modules/statuses.js'
|
||||
import usersModule from './modules/users.js'
|
||||
import groupsModule from './modules/groups.js'
|
||||
import apiModule from './modules/api.js'
|
||||
import configModule from './modules/config.js'
|
||||
|
||||
|
@ -55,6 +56,7 @@ const store = new Vuex.Store({
|
|||
modules: {
|
||||
statuses: statusesModule,
|
||||
users: usersModule,
|
||||
groups: groupsModule,
|
||||
api: apiModule,
|
||||
config: configModule
|
||||
},
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
import { compact, map, each, merge } from 'lodash'
|
||||
|
||||
export const mergeOrAdd = (arr, obj, item) => {
|
||||
if (!item) { return false }
|
||||
const oldItem = obj[item.nickname]
|
||||
if (oldItem) {
|
||||
// We already have this, so only merge the new info.
|
||||
merge(oldItem, item)
|
||||
return {item: oldItem, new: false}
|
||||
} else {
|
||||
// This is a new item, prepare it
|
||||
arr.push(item)
|
||||
obj[item.nickname] = item
|
||||
return {item, new: true}
|
||||
}
|
||||
}
|
||||
|
||||
export const defaultState = {
|
||||
groups: [],
|
||||
groupsObject: {}
|
||||
}
|
||||
|
||||
const groups = {
|
||||
state: defaultState,
|
||||
mutations: {
|
||||
addNewGroups (state, statuses) {
|
||||
each(statuses, (groups) => {
|
||||
each(groups, (group) => mergeOrAdd(state.groups, state.groupsObject, group))
|
||||
})
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
addNewStatuses (store, { statuses }) {
|
||||
const groups = compact(map(statuses, 'statusnet_in_groups'))
|
||||
store.commit('addNewGroups', groups)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default groups
|
Loading…
Reference in New Issue