Commit dbb9757b authored by Valentijn Nieman's avatar Valentijn Nieman Committed by Christopher Speller

MM-19337 Enable users to view archived channels (#963)

* First pass at search archived channels

* getArchivedChannels action

Rename action to getTeamArchivedChannels

Rename back to getArchivedChannels

Add getArchivedChannels selector back in

* Add unit tests for getArchivedChannels and searchArchivedChannels

* Revert package-lock accidental change

* Use existing /deleted endpoint instead of new /archived

* Update archived channels action test

* Remove old GET_CHANNELS_* actions

* Remove unused getArchivedChannelsRoute and revert package-lock
parent 2289b684
......@@ -1262,6 +1262,57 @@ describe('Actions.Channels', () => {
assert.ifError(myMembers[channel.id]);
});
it('getArchivedChannels', async () => {
const userClient = TestHelper.createClient4();
nock(Client4.getUsersRoute()).
post('').
query(true).
reply(201, TestHelper.fakeUserWithId());
const user = await TestHelper.basicClient4.createUser(
TestHelper.fakeUser(),
null,
null,
TestHelper.basicTeam.invite_id
);
nock(Client4.getUsersRoute()).
post('/login').
reply(200, user);
await userClient.login(user.email, 'password1');
nock(Client4.getChannelsRoute()).
post('').
reply(201, TestHelper.fakeChannelWithId(TestHelper.basicTeam.id));
const userChannel = await userClient.createChannel(
TestHelper.fakeChannel(TestHelper.basicTeam.id)
);
nock(Client4.getTeamsRoute()).
get(`/${TestHelper.basicTeam.id}/channels/deleted`).
query(true).
reply(200, [TestHelper.basicChannel, userChannel]);
await store.dispatch(Actions.getArchivedChannels(TestHelper.basicTeam.id, 0));
const moreRequest = store.getState().requests.channels.getChannels;
if (moreRequest.status === RequestStatus.FAILURE) {
throw new Error(JSON.stringify(moreRequest.error));
}
const {channels, channelsInTeam, myMembers} = store.getState().entities.channels;
const channel = channels[userChannel.id];
const team = channelsInTeam[userChannel.team_id];
assert.ok(channel);
assert.ok(team);
assert.ok(team.has(userChannel.id));
assert.ifError(myMembers[channel.id]);
});
it('getAllChannels', async () => {
const userClient = TestHelper.createClient4();
......@@ -1399,6 +1450,49 @@ describe('Actions.Channels', () => {
assert.ok(data.length === 2);
});
it('searchArchivedChannels', async () => {
const userClient = TestHelper.createClient4();
nock(Client4.getUsersRoute()).
post('').
query(true).
reply(201, TestHelper.fakeUserWithId());
const user = await TestHelper.basicClient4.createUser(
TestHelper.fakeUser(),
null,
null,
TestHelper.basicTeam.invite_id
);
nock(Client4.getUsersRoute()).
post('/login').
reply(200, user);
await userClient.login(user.email, 'password1');
nock(Client4.getChannelsRoute()).
post('').
reply(201, TestHelper.fakeChannelWithId(TestHelper.basicTeam.id));
const userChannel = await userClient.createChannel(
TestHelper.fakeChannel(TestHelper.basicTeam.id)
);
nock(Client4.getTeamsRoute()).
post(`/${TestHelper.basicTeam.id}/channels/search_archived`).
reply(200, [TestHelper.basicChannel, userChannel]);
const {data} = await store.dispatch(Actions.searchChannels(TestHelper.basicTeam.id, 'test', true));
const moreRequest = store.getState().requests.channels.getChannels;
if (moreRequest.status === RequestStatus.FAILURE) {
throw new Error(JSON.stringify(moreRequest.error));
}
assert.ok(data.length === 2);
});
it('getChannelMembers', async () => {
nock(Client4.getChannelsRoute()).
get(`/${TestHelper.basicChannel.id}/members`).
......
......@@ -823,6 +823,26 @@ export function getChannels(teamId: string, page = 0, perPage: number = General.
};
}
export function getArchivedChannels(teamId: string, page = 0, perPage: number = General.CHANNELS_CHUNK_SIZE): ActionFunc {
return async (dispatch: DispatchFunc, getState: GetStateFunc) => {
let channels;
try {
channels = await Client4.getArchivedChannels(teamId, page, perPage);
} catch (error) {
forceLogoutIfNecessary(error, dispatch, getState);
return {error};
}
dispatch({
type: ChannelTypes.RECEIVED_CHANNELS,
teamId,
data: channels,
}, getState);
return {data: channels};
};
}
export function getAllChannelsWithCount(page = 0, perPage: number = General.CHANNELS_CHUNK_SIZE, notAssociatedToGroup = '', excludeDefaultChannels = false): ActionFunc {
return async (dispatch: DispatchFunc, getState: GetStateFunc) => {
dispatch({type: ChannelTypes.GET_ALL_CHANNELS_REQUEST, data: null}, getState);
......@@ -949,13 +969,17 @@ export function autocompleteChannelsForSearch(teamId: string, term: string): Act
};
}
export function searchChannels(teamId: string, term: string): ActionFunc {
export function searchChannels(teamId: string, term: string, archived?: boolean): ActionFunc {
return async (dispatch: DispatchFunc, getState: GetStateFunc) => {
dispatch({type: ChannelTypes.GET_CHANNELS_REQUEST, data: null}, getState);
let channels;
try {
channels = await Client4.searchChannels(teamId, term);
if (archived) {
channels = await Client4.searchArchivedChannels(teamId, term);
} else {
channels = await Client4.searchChannels(teamId, term);
}
} catch (error) {
forceLogoutIfNecessary(error, dispatch, getState);
dispatch(batchActions([
......
......@@ -1403,6 +1403,12 @@ export default class Client4 {
{method: 'get'}
);
};
getArchivedChannels = async (teamId: string, page = 0, perPage = PER_PAGE_DEFAULT) => {
return this.doFetch(
`${this.getTeamRoute(teamId)}/channels/deleted${buildQueryString({page, per_page: perPage})}`,
{method: 'get'}
);
};
getMyChannels = async (teamId: string) => {
return this.doFetch(
......@@ -1515,6 +1521,13 @@ export default class Client4 {
);
};
searchArchivedChannels = async (teamId: string, term: string) => {
return this.doFetch(
`${this.getTeamRoute(teamId)}/channels/search_archived`,
{method: 'post', body: JSON.stringify({term})}
);
};
searchAllChannels = async (term: string, notAssociatedToGroup = '', excludeDefaultChannels = false) => {
const body = {
term,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment