[MM-54933] Add the ability to @ mention custom groups in group constrained teams and channels (#24987)

* add the ability to @ mention custom groups in group constrained teams
---------
Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Ben Cooke
2023-11-16 11:24:20 -05:00
коммит произвёл GitHub
родитель bd1c0b7a20
Коммит 2a896f8420
4 изменённых файлов: 95 добавлений и 13 удалений

Просмотреть файл

@@ -121,7 +121,7 @@ describe('Selectors.Groups', () => {
},
teams: {
teams: {
[teamID]: {group_constrained: false},
[teamID]: {group_constrained: true, id: teamID},
},
groupsAssociatedToTeam: {
[teamID]: {ids: teamAssociatedGroupIDs},
@@ -129,7 +129,7 @@ describe('Selectors.Groups', () => {
},
channels: {
channels: {
[channelID]: {team_id: teamID, id: channelID},
[channelID]: {team_id: teamID, id: channelID, group_constrained: true},
},
groupsAssociatedToChannel: {
[channelID]: {ids: channelAssociatedGroupIDs},
@@ -242,4 +242,38 @@ describe('Selectors.Groups', () => {
];
expect(Selectors.getMyGroupMentionKeysForChannel(testState, teamID, channelID)).toEqual(expected);
});
it('getAssociatedGroupsForReference team constrained', () => {
const expected = [
group5,
group1,
];
expect(Selectors.getAssociatedGroupsForReference(testState, teamID, '')).toEqual(expected);
});
it('getAssociatedGroupsForReference channel constrained', () => {
const expected = [
group5,
group4,
];
expect(Selectors.getAssociatedGroupsForReference(testState, '', channelID)).toEqual(expected);
});
it('getAssociatedGroupsForReference team and channel constrained', () => {
const expected = [
group4,
group1,
group5,
];
expect(Selectors.getAssociatedGroupsForReference(testState, teamID, channelID)).toEqual(expected);
});
it('getAssociatedGroupsForReference no constraints', () => {
const expected = [
group1,
group4,
group5,
];
expect(Selectors.getAssociatedGroupsForReference(testState, '', '')).toEqual(expected);
});
});

Просмотреть файл

@@ -125,11 +125,16 @@ export function getAssociatedGroupsForReference(state: GlobalState, teamId: stri
if (team && team.group_constrained && channel && channel.group_constrained) {
const groupsFromChannel = getGroupsAssociatedToChannelForReference(state, channelId);
const groupsFromTeam = getGroupsAssociatedToTeamForReference(state, teamId);
groupsForReference = groupsFromChannel.concat(groupsFromTeam.filter((item) => groupsFromChannel.indexOf(item) < 0));
const customGroups = getAllCustomGroups(state);
groupsForReference = groupsFromChannel.concat(groupsFromTeam.filter((item) => groupsFromChannel.indexOf(item) < 0), customGroups);
} else if (team && team.group_constrained) {
groupsForReference = getGroupsAssociatedToTeamForReference(state, teamId);
const customGroups = getAllCustomGroups(state);
const groupsFromTeam = getGroupsAssociatedToTeamForReference(state, teamId);
groupsForReference = [...customGroups, ...groupsFromTeam];
} else if (channel && channel.group_constrained) {
groupsForReference = getGroupsAssociatedToChannelForReference(state, channelId);
const customGroups = getAllCustomGroups(state);
const groupsFromChannel = getGroupsAssociatedToChannelForReference(state, channelId);
groupsForReference = [...customGroups, ...groupsFromChannel];
} else {
groupsForReference = getAllAssociatedGroupsForReference(state, false);
}
@@ -259,6 +264,14 @@ export const getAllGroupsForReferenceByName: (state: GlobalState) => Record<stri
},
);
export const getAllCustomGroups: (state: GlobalState) => Group[] = createSelector(
'getAllCustomGroups',
getAllGroups,
(groups) => {
return Object.entries(groups).filter((entry) => (entry[1].allow_reference && entry[1].delete_at === 0 && entry[1].source === GroupSource.Custom)).map((entry) => entry[1]);
},
);
export const makeGetMyAllowReferencedGroups = () => {
return createSelector(
'makeGetMyAllowReferencedGroups',