Remove guest tags based on config (#7425)

This commit is contained in:
Daniel Espino García 2023-06-30 11:05:54 +02:00 committed by GitHub
parent 0a3f5e5914
commit 0a8eb836f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 50 additions and 25 deletions

View file

@ -42,6 +42,7 @@ type HeaderProps = {
showPostPriority: boolean;
shouldRenderReplyButton?: boolean;
teammateNameDisplay: string;
hideGuestTags: boolean;
}
const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => {
@ -74,7 +75,7 @@ const Header = (props: HeaderProps) => {
const {
author, commentCount = 0, currentUser, enablePostUsernameOverride, isAutoResponse, isCRTEnabled, isCustomStatusEnabled,
isEphemeral, isMilitaryTime, isPendingOrFailed, isSystemPost, isTimezoneEnabled, isWebHook,
location, post, rootPostAuthor, showPostPriority, shouldRenderReplyButton, teammateNameDisplay,
location, post, rootPostAuthor, showPostPriority, shouldRenderReplyButton, teammateNameDisplay, hideGuestTags,
} = props;
const theme = useTheme();
const style = getStyleSheet(theme);
@ -111,7 +112,7 @@ const Header = (props: HeaderProps) => {
<HeaderTag
isAutoResponder={isAutoResponse}
isAutomation={isWebHook || author?.isBot}
isGuest={author?.isGuest}
showGuestTag={author?.isGuest && !hideGuestTags}
/>
}
<FormattedTime

View file

@ -51,6 +51,7 @@ const withHeaderProps = withObservables(
isTimezoneEnabled,
rootPostAuthor,
teammateNameDisplay,
hideGuestTags: observeConfigBooleanValue(database, 'HideGuestTags'),
};
});

View file

@ -10,7 +10,7 @@ import {t} from '@i18n';
type HeaderTagProps = {
isAutomation?: boolean;
isAutoResponder?: boolean;
isGuest?: boolean;
showGuestTag?: boolean;
}
const style = StyleSheet.create({
@ -22,7 +22,7 @@ const style = StyleSheet.create({
});
const HeaderTag = ({
isAutomation, isAutoResponder, isGuest,
isAutomation, isAutoResponder, showGuestTag,
}: HeaderTagProps) => {
if (isAutomation) {
return (
@ -31,7 +31,7 @@ const HeaderTag = ({
testID='post_header.bot.tag'
/>
);
} else if (isGuest) {
} else if (showGuestTag) {
return (
<GuestTag
style={style.tag}

View file

@ -4,6 +4,7 @@
import {withDatabase} from '@nozbe/watermelondb/DatabaseProvider';
import withObservables from '@nozbe/with-observables';
import {observeConfigBooleanValue} from '@queries/servers/system';
import {observeUser} from '@queries/servers/user';
import SystemMessage from './system_message';
@ -13,6 +14,7 @@ import type PostModel from '@typings/database/models/servers/post';
const enhance = withObservables(['post'], ({post, database}: {post: PostModel} & WithDatabaseArgs) => ({
author: observeUser(database, post.userId),
hideGuestTags: observeConfigBooleanValue(database, 'HideGuestTags'),
}));
export default withDatabase(enhance(SystemMessage));

View file

@ -6,6 +6,7 @@ import {type IntlShape, useIntl} from 'react-intl';
import {type StyleProp, Text, type TextStyle, View, type ViewStyle} from 'react-native';
import Markdown from '@components/markdown';
import {postTypeMessages} from '@components/post_list/combined_user_activity/messages';
import {Post} from '@constants';
import {useTheme} from '@context/theme';
import {t} from '@i18n';
@ -221,7 +222,7 @@ const renderUnarchivedMessage = ({post, author, location, styles, intl, theme}:
return renderMessage({post, styles, intl, location, localeHolder, values, theme});
};
const renderAddGuestToChannelMessage = ({post, location, styles, intl, theme}: RenderersProps) => {
const renderAddGuestToChannelMessage = ({post, location, styles, intl, theme}: RenderersProps, hideGuestTags: boolean) => {
if (!post.props.username || !post.props.addedUsername) {
return null;
}
@ -229,27 +230,27 @@ const renderAddGuestToChannelMessage = ({post, location, styles, intl, theme}: R
const username = renderUsername(post.props.username);
const addedUsername = renderUsername(post.props.addedUsername);
const localeHolder = {
const localeHolder = hideGuestTags ? postTypeMessages[Post.POST_TYPES.ADD_TO_CHANNEL].one : {
id: t('api.channel.add_guest.added'),
defaultMessage: '{addedUsername} added to the channel as a guest by {username}.',
};
const values = {username, addedUsername};
const values = hideGuestTags ? {firstUser: addedUsername, actor: username} : {username, addedUsername};
return renderMessage({post, styles, intl, location, localeHolder, values, theme});
};
const renderGuestJoinChannelMessage = ({post, styles, location, intl, theme}: RenderersProps) => {
const renderGuestJoinChannelMessage = ({post, styles, location, intl, theme}: RenderersProps, hideGuestTags: boolean) => {
if (!post.props.username) {
return null;
}
const username = renderUsername(post.props.username);
const localeHolder = {
const localeHolder = hideGuestTags ? postTypeMessages[Post.POST_TYPES.JOIN_CHANNEL].one : {
id: t('api.channel.guest_join_channel.post_and_forget'),
defaultMessage: '{username} joined the channel as a guest.',
};
const values = {username};
const values = hideGuestTags ? {firstUser: username} : {username};
return renderMessage({post, styles, intl, location, localeHolder, values, theme});
};
@ -259,17 +260,22 @@ const systemMessageRenderers = {
[Post.POST_TYPES.PURPOSE_CHANGE]: renderPurposeChangeMessage,
[Post.POST_TYPES.CHANNEL_DELETED]: renderArchivedMessage,
[Post.POST_TYPES.CHANNEL_UNARCHIVED]: renderUnarchivedMessage,
[Post.POST_TYPES.GUEST_JOIN_CHANNEL]: renderGuestJoinChannelMessage,
[Post.POST_TYPES.ADD_GUEST_TO_CHANNEL]: renderAddGuestToChannelMessage,
};
export const SystemMessage = ({post, location, author}: SystemMessageProps) => {
export const SystemMessage = ({post, location, author, hideGuestTags}: SystemMessageProps & { hideGuestTags: boolean}) => {
const intl = useIntl();
const theme = useTheme();
const style = getStyleSheet(theme);
const textStyles = getMarkdownTextStyles(theme);
const styles = {messageStyle: style.systemMessage, textStyles, containerStyle: style.container};
if (post.type === Post.POST_TYPES.GUEST_JOIN_CHANNEL) {
return renderGuestJoinChannelMessage({post, author, location, styles, intl, theme}, hideGuestTags);
}
if (post.type === Post.POST_TYPES.ADD_GUEST_TO_CHANNEL) {
return renderAddGuestToChannelMessage({post, author, location, styles, intl, theme}, hideGuestTags);
}
const renderer = systemMessageRenderers[post.type];
if (!renderer) {
return (

View file

@ -26,6 +26,7 @@ const enhanced = withObservables([], ({database}: WithDatabaseArgs) => {
currentUserId,
locale,
teammateNameDisplay,
hideGuestTags: observeConfigBooleanValue(database, 'HideGuestTags'),
};
});

View file

@ -17,7 +17,7 @@ import {displayUsername, getUserCustomStatus, isBot, isCustomStatusExpired, isGu
import type UserModel from '@typings/database/models/servers/user';
type AtMentionItemProps = {
type Props = {
FooterComponent?: ReactNode;
user: UserProfile | UserModel;
containerStyle?: StyleProp<ViewStyle>;
@ -35,6 +35,7 @@ type AtMentionItemProps = {
disabled?: boolean;
viewRef?: React.LegacyRef<View>;
padding?: number;
hideGuestTags: boolean;
}
const getThemedStyles = makeStyleSheetFromTheme((theme: Theme) => {
@ -107,7 +108,8 @@ const UserItem = ({
viewRef,
padding,
includeMargin,
}: AtMentionItemProps) => {
hideGuestTags,
}: Props) => {
const theme = useTheme();
const style = getThemedStyles(theme);
const intl = useIntl();
@ -198,7 +200,7 @@ const UserItem = ({
style={nonThemedStyles.tag}
/>
)}
{showBadges && guest && (
{showBadges && guest && !hideGuestTags && (
<GuestTag
testID={`${userItemTestId}.guest.tag`}
style={nonThemedStyles.tag}

View file

@ -15,6 +15,7 @@ import type UserModel from '@typings/database/models/servers/user';
type Props = {
displayName?: string;
user?: UserModel;
hideGuestTags: boolean;
}
const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => ({
@ -47,7 +48,11 @@ const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => ({
},
}));
const DirectMessage = ({displayName, user}: Props) => {
const DirectMessage = ({
displayName,
user,
hideGuestTags,
}: Props) => {
const theme = useTheme();
const styles = getStyleSheet(theme);
const directMessageUserTestId = `channel_info.title.direct_message.${user?.id}`;
@ -74,7 +79,7 @@ const DirectMessage = ({displayName, user}: Props) => {
>
{displayName}
</Text>
{user?.isGuest &&
{user?.isGuest && !hideGuestTags &&
<GuestTag
textStyle={styles.tag}
style={styles.tagContainer}

View file

@ -7,7 +7,7 @@ import {of as of$} from 'rxjs';
import {combineLatestWith, switchMap} from 'rxjs/operators';
import {observeChannel} from '@queries/servers/channel';
import {observeCurrentUserId} from '@queries/servers/system';
import {observeConfigBooleanValue, observeCurrentUserId} from '@queries/servers/system';
import {observeUser} from '@queries/servers/user';
import {getUserIdFromChannelName} from '@utils/user';
@ -36,6 +36,7 @@ const enhanced = withObservables(['channelId'], ({channelId, database}: Props) =
return {
currentUserId,
user,
hideGuestTags: observeConfigBooleanValue(database, 'HideGuestTags'),
};
});

View file

@ -70,6 +70,7 @@ const enhanced = withObservables([], ({channelId, database, userId}: EnhancedPro
teammateDisplayName,
user,
canChangeMemberRoles,
hideGuestTags: observeConfigBooleanValue(database, 'HideGuestTags'),
};
});

View file

@ -34,6 +34,7 @@ type Props = {
user: UserModel;
userIconOverride?: string;
usernameOverride?: string;
hideGuestTags: boolean;
}
export const HEADER_TEXT_HEIGHT = 30;
@ -70,7 +71,7 @@ const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => ({
const UserProfileTitle = ({
enablePostIconOverride, enablePostUsernameOverride, headerText,
imageSize, isChannelAdmin, isSystemAdmin, isTeamAdmin,
teammateDisplayName, user, userIconOverride, usernameOverride,
teammateDisplayName, user, userIconOverride, usernameOverride, hideGuestTags,
}: Props) => {
const galleryIdentifier = `${user.id}-avatarPreview`;
const intl = useIntl();
@ -155,7 +156,7 @@ const UserProfileTitle = ({
<UserProfileTag
isBot={user.isBot || Boolean(userIconOverride || usernameOverride)}
isChannelAdmin={isChannelAdmin}
isGuest={user.isGuest}
showGuestTag={user.isGuest && !hideGuestTags}
isSystemAdmin={isSystemAdmin}
isTeamAdmin={isTeamAdmin}
/>

View file

@ -9,7 +9,7 @@ import Tag, {BotTag, GuestTag} from '@components/tag';
type Props = {
isBot: boolean;
isChannelAdmin: boolean;
isGuest: boolean;
showGuestTag: boolean;
isSystemAdmin: boolean;
isTeamAdmin: boolean;
}
@ -22,7 +22,7 @@ const styles = StyleSheet.create({
},
});
const UserProfileTag = ({isBot, isChannelAdmin, isGuest, isSystemAdmin, isTeamAdmin}: Props) => {
const UserProfileTag = ({isBot, isChannelAdmin, showGuestTag, isSystemAdmin, isTeamAdmin}: Props) => {
if (isBot) {
return (
<BotTag
@ -31,7 +31,7 @@ const UserProfileTag = ({isBot, isChannelAdmin, isGuest, isSystemAdmin, isTeamAd
/>);
}
if (isGuest) {
if (showGuestTag) {
return (
<GuestTag
style={styles.tag}

View file

@ -45,6 +45,7 @@ type Props = {
user: UserModel;
userIconOverride?: string;
usernameOverride?: string;
hideGuestTags: boolean;
}
const TITLE_HEIGHT = 118;
@ -84,6 +85,7 @@ const UserProfile = ({
user,
userIconOverride,
usernameOverride,
hideGuestTags,
}: Props) => {
const {formatMessage, locale} = useIntl();
const serverUrl = useServerUrl();
@ -175,6 +177,7 @@ const UserProfile = ({
user={user}
userIconOverride={userIconOverride}
usernameOverride={usernameOverride}
hideGuestTags={hideGuestTags}
/>
{showUserProfileOptions &&
<UserProfileOptions

View file

@ -127,6 +127,7 @@ interface ClientConfig {
GuestAccountsEnforceMultifactorAuthentication: string;
HasImageProxy: string;
HelpLink: string;
HideGuestTags: string;
IosAppDownloadLink: string;
IosLatestVersion: string;
IosMinVersion: string;