MM-38065 Render system messages for guest added or joined a channel (#5639)
This commit is contained in:
parent
c90d040b40
commit
8e3044385b
4 changed files with 189 additions and 0 deletions
|
|
@ -112,6 +112,124 @@ exports[`renderSystemMessage uses renderer for Channel Purpose update 1`] = `
|
|||
</Text>
|
||||
`;
|
||||
|
||||
exports[`renderSystemMessage uses renderer for Guest added and join to channel 1`] = `
|
||||
<View
|
||||
style={
|
||||
Array [
|
||||
Object {
|
||||
"alignItems": "flex-start",
|
||||
"flexDirection": "row",
|
||||
"flexWrap": "wrap",
|
||||
},
|
||||
]
|
||||
}
|
||||
>
|
||||
<Text>
|
||||
<Text
|
||||
style={
|
||||
Array [
|
||||
Object {
|
||||
"color": "rgba(61,60,64,0.6)",
|
||||
"fontSize": 15,
|
||||
"lineHeight": 20,
|
||||
},
|
||||
Object {
|
||||
"opacity": 1,
|
||||
},
|
||||
]
|
||||
}
|
||||
>
|
||||
<Text
|
||||
style={Array []}
|
||||
>
|
||||
@username
|
||||
</Text>
|
||||
</Text>
|
||||
<Text
|
||||
style={
|
||||
Object {
|
||||
"color": "rgba(61,60,64,0.6)",
|
||||
"fontSize": 15,
|
||||
"lineHeight": 20,
|
||||
}
|
||||
}
|
||||
testID="markdown_text"
|
||||
>
|
||||
joined the channel as a guest.
|
||||
</Text>
|
||||
</Text>
|
||||
</View>
|
||||
`;
|
||||
|
||||
exports[`renderSystemMessage uses renderer for Guest added and join to channel 2`] = `
|
||||
<View
|
||||
style={
|
||||
Array [
|
||||
Object {
|
||||
"alignItems": "flex-start",
|
||||
"flexDirection": "row",
|
||||
"flexWrap": "wrap",
|
||||
},
|
||||
]
|
||||
}
|
||||
>
|
||||
<Text>
|
||||
<Text
|
||||
style={
|
||||
Array [
|
||||
Object {
|
||||
"color": "rgba(61,60,64,0.6)",
|
||||
"fontSize": 15,
|
||||
"lineHeight": 20,
|
||||
},
|
||||
Object {
|
||||
"opacity": 1,
|
||||
},
|
||||
]
|
||||
}
|
||||
>
|
||||
<Text
|
||||
style={Array []}
|
||||
>
|
||||
@other.user
|
||||
</Text>
|
||||
</Text>
|
||||
<Text
|
||||
style={
|
||||
Object {
|
||||
"color": "rgba(61,60,64,0.6)",
|
||||
"fontSize": 15,
|
||||
"lineHeight": 20,
|
||||
}
|
||||
}
|
||||
testID="markdown_text"
|
||||
>
|
||||
added to the channel as a guest by
|
||||
</Text>
|
||||
<Text
|
||||
style={
|
||||
Array [
|
||||
Object {
|
||||
"color": "rgba(61,60,64,0.6)",
|
||||
"fontSize": 15,
|
||||
"lineHeight": 20,
|
||||
},
|
||||
Object {
|
||||
"opacity": 1,
|
||||
},
|
||||
]
|
||||
}
|
||||
>
|
||||
<Text
|
||||
style={Array []}
|
||||
>
|
||||
@username.
|
||||
</Text>
|
||||
</Text>
|
||||
</Text>
|
||||
</View>
|
||||
`;
|
||||
|
||||
exports[`renderSystemMessage uses renderer for OLD archived channel without a username 1`] = `
|
||||
<View
|
||||
style={
|
||||
|
|
|
|||
|
|
@ -207,12 +207,46 @@ const renderUnarchivedMessage = ({post, ownerUsername, styles, intl}: RenderersP
|
|||
return renderMessage({post, styles, intl, localeHolder, values});
|
||||
};
|
||||
|
||||
const renderAddGuestToChannelMessage = ({post, styles, intl}: RenderersProps) => {
|
||||
if (!post.props.username || !post.props.addedUsername) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const username = renderUsername(post.props.username);
|
||||
const addedUsername = renderUsername(post.props.addedUsername);
|
||||
|
||||
const localeHolder = {
|
||||
id: t('api.channel.add_guest.added'),
|
||||
defaultMessage: '{addedUsername} added to the channel as a guest by {username}.',
|
||||
};
|
||||
|
||||
const values = {username, addedUsername};
|
||||
return renderMessage({post, styles, intl, localeHolder, values});
|
||||
};
|
||||
|
||||
const renderGuestJoinChannelMessage = ({post, styles, intl}: RenderersProps) => {
|
||||
if (!post.props.username) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const username = renderUsername(post.props.username);
|
||||
const localeHolder = {
|
||||
id: t('api.channel.guest_join_channel.post_and_forget'),
|
||||
defaultMessage: '{username} joined the channel as a guest.',
|
||||
};
|
||||
|
||||
const values = {username};
|
||||
return renderMessage({post, styles, intl, localeHolder, values});
|
||||
};
|
||||
|
||||
const systemMessageRenderers = {
|
||||
[Posts.POST_TYPES.HEADER_CHANGE]: renderHeaderChangeMessage,
|
||||
[Posts.POST_TYPES.DISPLAYNAME_CHANGE]: renderDisplayNameChangeMessage,
|
||||
[Posts.POST_TYPES.PURPOSE_CHANGE]: renderPurposeChangeMessage,
|
||||
[Posts.POST_TYPES.CHANNEL_DELETED]: renderArchivedMessage,
|
||||
[Posts.POST_TYPES.CHANNEL_UNARCHIVED]: renderUnarchivedMessage,
|
||||
[Posts.POST_TYPES.GUEST_JOIN_CHANNEL]: renderGuestJoinChannelMessage,
|
||||
[Posts.POST_TYPES.ADD_GUEST_TO_CHANNEL]: renderAddGuestToChannelMessage,
|
||||
};
|
||||
|
||||
const SystemMessage = ({post, ownerUsername, theme, intl}: SystemMessageProps) => {
|
||||
|
|
|
|||
|
|
@ -143,4 +143,39 @@ describe('renderSystemMessage', () => {
|
|||
);
|
||||
expect(renderedMessage.toJSON()).toBeNull();
|
||||
});
|
||||
|
||||
test('uses renderer for Guest added and join to channel', () => {
|
||||
const post = {
|
||||
props: {
|
||||
username: 'username',
|
||||
},
|
||||
type: Posts.POST_TYPES.GUEST_JOIN_CHANNEL,
|
||||
};
|
||||
const joined = renderWithReduxIntl(
|
||||
<SystemMessage
|
||||
post={post}
|
||||
{...baseProps}
|
||||
/>,
|
||||
);
|
||||
expect(joined.toJSON()).toMatchSnapshot();
|
||||
expect(joined.getByText('@username')).toBeTruthy();
|
||||
expect(joined.getByText(' joined the channel as a guest.')).toBeTruthy();
|
||||
|
||||
post.type = Posts.POST_TYPES.ADD_GUEST_TO_CHANNEL;
|
||||
post.props = {
|
||||
username: 'username',
|
||||
addedUsername: 'other.user',
|
||||
};
|
||||
|
||||
const added = renderWithReduxIntl(
|
||||
<SystemMessage
|
||||
post={post}
|
||||
{...baseProps}
|
||||
/>,
|
||||
);
|
||||
expect(added.toJSON()).toMatchSnapshot();
|
||||
expect(added.getByText('@other.user')).toBeTruthy();
|
||||
expect(added.getByText(' added to the channel as a guest by ')).toBeTruthy();
|
||||
expect(added.getByText('@username.')).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -11,7 +11,9 @@
|
|||
"about.teamEditiont1": "Enterprise Edition",
|
||||
"about.title": "About {appTitle}",
|
||||
"announcment_banner.dont_show_again": "Don't show again",
|
||||
"api.channel.add_guest.added": "{addedUsername} added to the channel as a guest by {username}.",
|
||||
"api.channel.add_member.added": "{addedUsername} added to the channel by {username}.",
|
||||
"api.channel.guest_join_channel.post_and_forget": "{username} joined the channel as a guest.",
|
||||
"apps.error": "Error: {error}",
|
||||
"apps.error.command.field_missing": "Required fields missing: `{fieldName}`.",
|
||||
"apps.error.command.unknown_channel": "Unknown channel for field `{fieldName}`: `{option}`.",
|
||||
|
|
|
|||
Loading…
Reference in a new issue