Merge pull request #1396 from h3poteto/iss-1390

refs #1390 Fix list memberships parser when add or remove list member
This commit is contained in:
AkiraFukushima 2020-04-25 21:56:07 +09:00 committed by GitHub
commit 28c7df13b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 7 deletions

View File

@ -73,10 +73,16 @@ const actions: ActionTree<ListMembershipState, RootState> = {
commit(MUTATION_TYPES.CHANGE_LISTS, res.data)
return res.data
},
changeBelongToLists: async ({ rootState, commit, state }, belongToLists: Array<Entity.List>) => {
changeBelongToLists: async ({ rootState, commit, state }, belongToLists: Array<string>) => {
// Calcurate diff
const removedLists = lodash.difference(state.belongToLists, belongToLists)
const addedLists = lodash.difference(belongToLists, state.belongToLists)
const removedLists = lodash.difference(
state.belongToLists.map(l => l.id),
belongToLists
)
const addedLists = lodash.difference(
belongToLists,
state.belongToLists.map(l => l.id)
)
commit(MUTATION_TYPES.CHANGE_BELONG_TO_LISTS, belongToLists)
const client = generator(
rootState.TimelineSpace.sns,
@ -85,11 +91,11 @@ const actions: ActionTree<ListMembershipState, RootState> = {
rootState.App.userAgent,
rootState.App.proxyConfiguration
)
const removedPromise = removedLists.map(list => {
return client.deleteAccountsFromList(list.id, [state.account!.id])
const removedPromise = removedLists.map(id => {
return client.deleteAccountsFromList(id, [state.account!.id])
})
const addedPromise = addedLists.map(list => {
return client.addAccountsToList(list.id, [state.account!.id])
const addedPromise = addedLists.map(id => {
return client.addAccountsToList(id, [state.account!.id])
})
const res = await Promise.all(removedPromise.concat(addedPromise))
return res