Remove unnecessary moreChannels from store (#104)
* Remove unnecessary moreChannels from store * Remove profile fetching on DM creation
This commit is contained in:
parent
f487bb4014
commit
4b636bfefc
4 changed files with 22 additions and 66 deletions
|
|
@ -65,20 +65,9 @@ export function createChannel(channel, userId) {
|
|||
export function createDirectChannel(userId, otherUserId) {
|
||||
return async (dispatch, getState) => {
|
||||
try {
|
||||
dispatch(batchActions([
|
||||
{
|
||||
type: ChannelTypes.CREATE_CHANNEL_REQUEST
|
||||
},
|
||||
{
|
||||
type: ChannelTypes.CHANNEL_MEMBERS_REQUEST
|
||||
},
|
||||
{
|
||||
type: UsersTypes.PROFILES_REQUEST
|
||||
}
|
||||
]), getState);
|
||||
dispatch({type: ChannelTypes.CREATE_CHANNEL_REQUEST}, getState);
|
||||
|
||||
const created = await Client.createDirectChannel(otherUserId);
|
||||
const profile = await Client.getUser(otherUserId);
|
||||
const member = {
|
||||
channel_id: created.id,
|
||||
user_id: userId,
|
||||
|
|
@ -95,26 +84,16 @@ export function createDirectChannel(userId, otherUserId) {
|
|||
type: ChannelTypes.RECEIVED_CHANNEL,
|
||||
data: created
|
||||
},
|
||||
{
|
||||
type: ChannelTypes.CREATE_CHANNEL_SUCCESS
|
||||
},
|
||||
{
|
||||
type: ChannelTypes.RECEIVED_MY_CHANNEL_MEMBER,
|
||||
data: member
|
||||
},
|
||||
{
|
||||
type: ChannelTypes.CHANNEL_MEMBERS_SUCCESS
|
||||
},
|
||||
{
|
||||
type: UsersTypes.RECEIVED_PROFILES,
|
||||
data: {[profile.id]: profile}
|
||||
},
|
||||
{
|
||||
type: UsersTypes.PROFILES_SUCCESS
|
||||
},
|
||||
{
|
||||
type: UsersTypes.RECEIVED_PREFERENCE,
|
||||
data: {category: Constants.CATEGORY_DIRECT_CHANNEL_SHOW, name: otherUserId, value: 'true'}
|
||||
},
|
||||
{
|
||||
type: ChannelTypes.CREATE_CHANNEL_SUCCESS
|
||||
}
|
||||
]), getState);
|
||||
} catch (error) {
|
||||
|
|
@ -127,9 +106,6 @@ export function createDirectChannel(userId, otherUserId) {
|
|||
{
|
||||
type: ChannelTypes.CHANNEL_MEMBERS_FAILURE,
|
||||
error
|
||||
},
|
||||
{
|
||||
type: UsersTypes.PROFILES_FAILURE
|
||||
}
|
||||
]), getState);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,17 +23,13 @@ function channels(state = {}, action) {
|
|||
[action.data.id]: action.data
|
||||
};
|
||||
|
||||
case ChannelTypes.RECEIVED_CHANNELS: {
|
||||
case ChannelTypes.RECEIVED_CHANNELS:
|
||||
case ChannelTypes.RECEIVED_MORE_CHANNELS: {
|
||||
for (const channel of action.data) {
|
||||
nextState[channel.id] = channel;
|
||||
}
|
||||
return nextState;
|
||||
}
|
||||
case ChannelTypes.LEAVE_CHANNEL:
|
||||
case ChannelTypes.RECEIVED_CHANNEL_DELETED: {
|
||||
Reflect.deleteProperty(nextState, action.channel_id);
|
||||
return nextState;
|
||||
}
|
||||
case UsersTypes.LOGOUT_SUCCESS:
|
||||
return {};
|
||||
|
||||
|
|
@ -89,28 +85,6 @@ function myMembers(state = {}, action) {
|
|||
}
|
||||
}
|
||||
|
||||
function moreChannels(state = {}, action) {
|
||||
const nextState = {...state};
|
||||
|
||||
switch (action.type) {
|
||||
case ChannelTypes.RECEIVED_MORE_CHANNELS: {
|
||||
for (const channel of action.data) {
|
||||
nextState[channel.id] = channel;
|
||||
}
|
||||
return nextState;
|
||||
}
|
||||
case ChannelTypes.RECEIVED_MY_CHANNEL_MEMBER: {
|
||||
const channelMember = action.data;
|
||||
Reflect.deleteProperty(nextState, channelMember.channel_id);
|
||||
return nextState;
|
||||
}
|
||||
case UsersTypes.LOGOUT_SUCCESS:
|
||||
return {};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
function stats(state = {}, action) {
|
||||
switch (action.type) {
|
||||
case ChannelTypes.RECEIVED_CHANNEL_STATS: {
|
||||
|
|
@ -138,9 +112,6 @@ export default combineReducers({
|
|||
//object where every key is the channel id and has and object with the channel members detail
|
||||
myMembers,
|
||||
|
||||
// object where every key is the channel id and has a object with the channel detail where the user is not a current member
|
||||
moreChannels,
|
||||
|
||||
// object where every key is the team id and has an object with the team stats
|
||||
stats
|
||||
});
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
import assert from 'assert';
|
||||
|
||||
import * as Actions from 'actions/channels';
|
||||
import {getProfiles} from 'actions/users';
|
||||
import Client from 'client';
|
||||
import configureStore from 'store/configureStore';
|
||||
import {RequestStatus} from 'constants';
|
||||
|
|
@ -54,7 +55,12 @@ describe('Actions.Channels', () => {
|
|||
it('createDirectChannel', (done) => {
|
||||
TestHelper.initBasic(Client).then(async () => {
|
||||
const store = configureStore();
|
||||
const user = await TestHelper.basicClient.createUser(TestHelper.fakeUser());
|
||||
const user = await TestHelper.basicClient.createUserWithInvite(
|
||||
TestHelper.fakeUser(),
|
||||
null,
|
||||
null,
|
||||
TestHelper.basicTeam.invite_id
|
||||
);
|
||||
|
||||
store.subscribe(() => {
|
||||
const channels = store.getState().entities.channels.channels;
|
||||
|
|
@ -63,9 +69,12 @@ describe('Actions.Channels', () => {
|
|||
const preferences = store.getState().entities.users.myPreferences;
|
||||
|
||||
const createRequest = store.getState().requests.channels.createChannel;
|
||||
const membersRequest = store.getState().requests.channels.myMembers;
|
||||
|
||||
if (createRequest.status === RequestStatus.SUCCESS && membersRequest.status === RequestStatus.SUCCESS) {
|
||||
if (createRequest.status === RequestStatus.SUCCESS || createRequest.status === RequestStatus.FAILURE) {
|
||||
if (createRequest.error) {
|
||||
done(new Error(JSON.stringify(createRequest.error)));
|
||||
}
|
||||
|
||||
const channelsCount = Object.keys(channels).length;
|
||||
const membersCount = Object.keys(members).length;
|
||||
assert.ok(channels);
|
||||
|
|
@ -80,11 +89,10 @@ describe('Actions.Channels', () => {
|
|||
assert.equal(channelsCount, 1);
|
||||
assert.equal(membersCount, 1);
|
||||
done();
|
||||
} else if (createRequest.status === RequestStatus.FAILURE && membersRequest.status === RequestStatus.FAILURE) {
|
||||
done(new Error(JSON.stringify(createRequest.error)));
|
||||
}
|
||||
});
|
||||
|
||||
await getProfiles(0)(store.dispatch, store.getState);
|
||||
Actions.createDirectChannel(TestHelper.basicUser.id, user.id)(store.dispatch, store.getState);
|
||||
});
|
||||
});
|
||||
|
|
@ -382,13 +390,15 @@ describe('Actions.Channels', () => {
|
|||
TestHelper.fakeChannel(TestHelper.basicTeam.id));
|
||||
|
||||
store.subscribe(() => {
|
||||
const channels = store.getState().entities.channels.moreChannels;
|
||||
const channels = store.getState().entities.channels.channels;
|
||||
const members = store.getState().entities.channels.myMembers;
|
||||
const moreRequest = store.getState().requests.channels.getMoreChannels;
|
||||
|
||||
if (moreRequest.status === RequestStatus.SUCCESS) {
|
||||
const channel = channels[secondChannel.id];
|
||||
|
||||
assert.ok(channel);
|
||||
assert.ifError(members[channel.id]);
|
||||
done();
|
||||
} else if (moreRequest.status === RequestStatus.FAILURE) {
|
||||
done(new Error(JSON.stringify(moreRequest.error)));
|
||||
|
|
|
|||
|
|
@ -92,7 +92,6 @@ describe('Actions.Users', () => {
|
|||
assert.strictEqual(channels.currentId, '', 'current channel id is not empty');
|
||||
assert.deepStrictEqual(channels.channels, {}, 'channels is not empty');
|
||||
assert.deepStrictEqual(channels.myMembers, {}, 'channel members is not empty');
|
||||
assert.deepStrictEqual(channels.moreChannels, {}, 'more channels is not empty');
|
||||
assert.deepStrictEqual(channels.stats, {}, 'channel stats is not empty');
|
||||
assert.strictEqual(posts.selectedPostId, '', 'selected post id is not empty');
|
||||
assert.strictEqual(posts.currentFocusedPostId, '', 'current focused post id is not empty');
|
||||
|
|
|
|||
Loading…
Reference in a new issue