Commit bc3df042 authored by Jesús Espino's avatar Jesús Espino Committed by Harrison Healey

MM-14386: Get the membership if the group channel is not new (#794)

* MM-14386: Get the membership if the group channel is not new

* Addressing PR review comments

* Addressing PR review comments

* Changing the approach to detect old group channels
parent 6969aa7a
......@@ -9,6 +9,7 @@ import {General, Preferences} from 'constants';
import {ChannelTypes, PreferenceTypes, UserTypes} from 'action_types';
import {savePreferences, deletePreferences} from 'actions/preferences';
import {getChannelsIdForTeam} from 'utils/channel_utils';
import {getMyChannelMember as getMyChannelMemberSelector} from 'selectors/entities/channels';
import {logError} from './errors';
import {bindClientFunc, forceLogoutIfNecessary} from './helpers';
......@@ -170,7 +171,7 @@ export function createGroupChannel(userIds: Array<string>): ActionFunc {
return {error};
}
const member = {
let member = {
channel_id: created.id,
user_id: currentUserId,
roles: `${General.CHANNEL_USER_ROLE}`,
......@@ -181,6 +182,22 @@ export function createGroupChannel(userIds: Array<string>): ActionFunc {
last_update_at: created.create_at,
};
// Check the channel previous existency: if the channel already have
// posts is because it existed before.
if (created.total_msg_count > 0) {
const storeMember = getMyChannelMemberSelector(getState(), created.id);
if (storeMember === null) {
try {
member = await Client4.getMyChannelMember(created.id);
} catch (error) {
// Log the error and keep going with the generated membership.
dispatch(logError(error));
}
} else {
member = storeMember;
}
}
dispatch(markGroupChannelOpen(created.id));
const profilesInChannel = userIds.map((id) => {
......@@ -206,7 +223,7 @@ export function createGroupChannel(userIds: Array<string>): ActionFunc {
data: profilesInChannel,
},
]), getState);
dispatch(loadRolesIfNeeded(member.roles.split(' ')));
dispatch(loadRolesIfNeeded((member && member.roles.split(' ')) || []));
return {data: created};
};
......
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