[FIX] Use RealName when necessary (#1758)
Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
parent
aeb5ec7c6e
commit
9e4cef5742
|
@ -7,7 +7,7 @@ import { themes } from '../../constants/colors';
|
|||
import styles from './styles';
|
||||
|
||||
const AtMention = React.memo(({
|
||||
mention, mentions, username, navToRoomInfo, preview, style = [], theme
|
||||
mention, mentions, username, navToRoomInfo, preview, style = [], useRealName, theme
|
||||
}) => {
|
||||
let mentionStyle = { ...styles.mention, color: themes[theme].buttonText };
|
||||
if (mention === 'all' || mention === 'here') {
|
||||
|
@ -27,22 +27,23 @@ const AtMention = React.memo(({
|
|||
};
|
||||
}
|
||||
|
||||
const user = mentions && mentions.length && mentions.find(m => m.username === mention);
|
||||
|
||||
const handlePress = () => {
|
||||
const index = mentions.findIndex(m => m.username === mention);
|
||||
const navParam = {
|
||||
t: 'd',
|
||||
rid: mentions[index]._id
|
||||
rid: user && user._id
|
||||
};
|
||||
navToRoomInfo(navParam);
|
||||
};
|
||||
|
||||
if (mentions && mentions.length && mentions.findIndex(m => m.username === mention) !== -1) {
|
||||
if (user) {
|
||||
return (
|
||||
<Text
|
||||
style={[preview ? { ...styles.text, color: themes[theme].bodyText } : mentionStyle, ...style]}
|
||||
onPress={preview ? undefined : handlePress}
|
||||
>
|
||||
{mention}
|
||||
{useRealName ? user.name : user.username}
|
||||
</Text>
|
||||
);
|
||||
}
|
||||
|
@ -60,6 +61,7 @@ AtMention.propTypes = {
|
|||
navToRoomInfo: PropTypes.func,
|
||||
style: PropTypes.array,
|
||||
preview: PropTypes.bool,
|
||||
useRealName: PropTypes.bool,
|
||||
theme: PropTypes.string,
|
||||
mentions: PropTypes.oneOfType([PropTypes.array, PropTypes.object])
|
||||
};
|
||||
|
|
|
@ -73,6 +73,7 @@ class Markdown extends PureComponent {
|
|||
numberOfLines: PropTypes.number,
|
||||
useMarkdown: PropTypes.bool,
|
||||
customEmojis: PropTypes.bool,
|
||||
useRealName: PropTypes.bool,
|
||||
channels: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
|
||||
mentions: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
|
||||
navToRoomInfo: PropTypes.func,
|
||||
|
@ -251,12 +252,13 @@ class Markdown extends PureComponent {
|
|||
|
||||
renderAtMention = ({ mentionName }) => {
|
||||
const {
|
||||
username, mentions, navToRoomInfo, preview, style, theme
|
||||
username, mentions, navToRoomInfo, useRealName, preview, style, theme
|
||||
} = this.props;
|
||||
return (
|
||||
<MarkdownAtMention
|
||||
mentions={mentions}
|
||||
mention={mentionName}
|
||||
useRealName={useRealName}
|
||||
username={username}
|
||||
navToRoomInfo={navToRoomInfo}
|
||||
preview={preview}
|
||||
|
|
|
@ -32,6 +32,7 @@ const Content = React.memo((props) => {
|
|||
useMarkdown={props.useMarkdown && (!props.tmid || props.isThreadRoom)}
|
||||
navToRoomInfo={props.navToRoomInfo}
|
||||
tmid={props.tmid}
|
||||
useRealName={props.useRealName}
|
||||
theme={props.theme}
|
||||
/>
|
||||
);
|
||||
|
@ -58,7 +59,8 @@ Content.propTypes = {
|
|||
getCustomEmoji: PropTypes.func,
|
||||
channels: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
|
||||
mentions: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
|
||||
navToRoomInfo: PropTypes.func
|
||||
navToRoomInfo: PropTypes.func,
|
||||
useRealName: PropTypes.bool
|
||||
};
|
||||
Content.displayName = 'MessageContent';
|
||||
|
||||
|
|
|
@ -283,10 +283,9 @@ export default function subscribeRooms() {
|
|||
const [notification] = ddpMessage.fields.args;
|
||||
try {
|
||||
const { payload: { rid } } = notification;
|
||||
const subCollection = db.collections.get('subscriptions');
|
||||
const sub = await subCollection.find(rid);
|
||||
notification.title = RocketChat.getRoomTitle(sub);
|
||||
notification.avatar = RocketChat.getRoomAvatar(sub);
|
||||
const room = await RocketChat.getRoom(rid);
|
||||
notification.title = RocketChat.getRoomTitle(room);
|
||||
notification.avatar = RocketChat.getRoomAvatar(room);
|
||||
} catch (e) {
|
||||
// do nothing
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import { themes } from '../../constants/colors';
|
|||
import shortnameToUnicode from '../../utils/shortnameToUnicode';
|
||||
|
||||
const formatMsg = ({
|
||||
lastMessage, type, showLastMessage, username
|
||||
lastMessage, type, showLastMessage, username, useRealName
|
||||
}) => {
|
||||
if (!showLastMessage) {
|
||||
return '';
|
||||
|
@ -33,7 +33,8 @@ const formatMsg = ({
|
|||
if (isLastMessageSentByMe) {
|
||||
prefix = I18n.t('You_colon');
|
||||
} else if (type !== 'd') {
|
||||
prefix = `${ lastMessage.u.username }: `;
|
||||
const { u: { name } } = lastMessage;
|
||||
prefix = `${ useRealName ? name : lastMessage.u.username }: `;
|
||||
}
|
||||
|
||||
let msg = `${ prefix }${ lastMessage.msg.replace(/[\n\t\r]/igm, '') }`;
|
||||
|
@ -46,14 +47,15 @@ const formatMsg = ({
|
|||
const arePropsEqual = (oldProps, newProps) => _.isEqual(oldProps, newProps);
|
||||
|
||||
const LastMessage = React.memo(({
|
||||
lastMessage, type, showLastMessage, username, alert, theme
|
||||
lastMessage, type, showLastMessage, username, alert, useRealName, theme
|
||||
}) => (
|
||||
<Markdown
|
||||
msg={formatMsg({
|
||||
lastMessage, type, showLastMessage, username
|
||||
lastMessage, type, showLastMessage, username, useRealName
|
||||
})}
|
||||
style={[styles.markdownText, { color: alert ? themes[theme].bodyText : themes[theme].auxiliaryText }]}
|
||||
customEmojis={false}
|
||||
useRealName={useRealName}
|
||||
numberOfLines={2}
|
||||
preview
|
||||
theme={theme}
|
||||
|
@ -66,6 +68,7 @@ LastMessage.propTypes = {
|
|||
type: PropTypes.string,
|
||||
showLastMessage: PropTypes.bool,
|
||||
username: PropTypes.string,
|
||||
useRealName: PropTypes.bool,
|
||||
alert: PropTypes.bool
|
||||
};
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ const attrs = [
|
|||
'unread',
|
||||
'userMentions',
|
||||
'showLastMessage',
|
||||
'useRealName',
|
||||
'alert',
|
||||
'type',
|
||||
'width',
|
||||
|
@ -39,7 +40,7 @@ const arePropsEqual = (oldProps, newProps) => {
|
|||
};
|
||||
|
||||
const RoomItem = React.memo(({
|
||||
onPress, width, favorite, toggleFav, isRead, rid, toggleRead, hideChannel, testID, unread, userMentions, name, _updatedAt, alert, type, avatarSize, baseUrl, userId, username, token, id, prid, showLastMessage, hideUnreadStatus, lastMessage, status, avatar, theme
|
||||
onPress, width, favorite, toggleFav, isRead, rid, toggleRead, hideChannel, testID, unread, userMentions, name, _updatedAt, alert, type, avatarSize, baseUrl, userId, username, token, id, prid, showLastMessage, hideUnreadStatus, lastMessage, status, avatar, useRealName, theme
|
||||
}) => {
|
||||
const date = formatDate(_updatedAt);
|
||||
|
||||
|
@ -144,6 +145,7 @@ const RoomItem = React.memo(({
|
|||
showLastMessage={showLastMessage}
|
||||
username={username}
|
||||
alert={alert && !hideUnreadStatus}
|
||||
useRealName={useRealName}
|
||||
theme={theme}
|
||||
/>
|
||||
<UnreadBadge
|
||||
|
@ -187,6 +189,7 @@ RoomItem.propTypes = {
|
|||
hideChannel: PropTypes.func,
|
||||
avatar: PropTypes.bool,
|
||||
hideUnreadStatus: PropTypes.bool,
|
||||
useRealName: PropTypes.bool,
|
||||
theme: PropTypes.string
|
||||
};
|
||||
|
||||
|
|
|
@ -151,14 +151,14 @@ class RoomInfoView extends React.Component {
|
|||
|
||||
goRoom = async() => {
|
||||
const { roomUser } = this.state;
|
||||
const { username: name } = roomUser;
|
||||
const { username } = roomUser;
|
||||
const { navigation } = this.props;
|
||||
try {
|
||||
const result = await RocketChat.createDirectMessage(name);
|
||||
const result = await RocketChat.createDirectMessage(username);
|
||||
if (result.success) {
|
||||
await navigation.navigate('RoomsListView');
|
||||
const rid = result.room._id;
|
||||
navigation.navigate('RoomView', { rid, name, t: 'd' });
|
||||
navigation.navigate('RoomView', { rid, name: RocketChat.getRoomTitle(roomUser), t: 'd' });
|
||||
}
|
||||
} catch (e) {
|
||||
// do nothing
|
||||
|
|
|
@ -366,7 +366,11 @@ class RoomView extends React.Component {
|
|||
const subCollection = await db.collections.get('subscriptions');
|
||||
const room = await subCollection.find(rid);
|
||||
this.setState({ room });
|
||||
navigation.setParams({ room });
|
||||
navigation.setParams({
|
||||
name: this.getRoomTitle(room),
|
||||
avatar: room.name,
|
||||
t: room.t
|
||||
});
|
||||
this.observeRoom(room);
|
||||
} catch (error) {
|
||||
if (this.t !== 'd') {
|
||||
|
|
|
@ -173,6 +173,7 @@ class RoomsListView extends React.Component {
|
|||
appStart: PropTypes.func,
|
||||
roomsRequest: PropTypes.func,
|
||||
closeServerDropdown: PropTypes.func,
|
||||
useRealName: PropTypes.bool,
|
||||
split: PropTypes.bool
|
||||
};
|
||||
|
||||
|
@ -757,6 +758,7 @@ class RoomsListView extends React.Component {
|
|||
},
|
||||
server,
|
||||
StoreLastMessage,
|
||||
useRealName,
|
||||
theme,
|
||||
split
|
||||
} = this.props;
|
||||
|
@ -791,6 +793,7 @@ class RoomsListView extends React.Component {
|
|||
toggleFav={this.toggleFav}
|
||||
toggleRead={this.toggleRead}
|
||||
hideChannel={this.hideChannel}
|
||||
useRealName={useRealName}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -47,6 +47,7 @@ class Sidebar extends Component {
|
|||
activeItemKey: PropTypes.string,
|
||||
theme: PropTypes.string,
|
||||
loadingServer: PropTypes.bool,
|
||||
useRealName: PropTypes.bool,
|
||||
split: PropTypes.bool
|
||||
}
|
||||
|
||||
|
@ -77,7 +78,7 @@ class Sidebar extends Component {
|
|||
shouldComponentUpdate(nextProps, nextState) {
|
||||
const { status, showStatus, isAdmin } = this.state;
|
||||
const {
|
||||
Site_Name, user, baseUrl, activeItemKey, split, theme
|
||||
Site_Name, user, baseUrl, activeItemKey, split, useRealName, theme
|
||||
} = this.props;
|
||||
if (nextState.showStatus !== showStatus) {
|
||||
return true;
|
||||
|
@ -111,6 +112,9 @@ class Sidebar extends Component {
|
|||
if (nextProps.split !== split) {
|
||||
return true;
|
||||
}
|
||||
if (nextProps.useRealName !== useRealName) {
|
||||
return true;
|
||||
}
|
||||
if (!equal(nextState.status, status)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -242,7 +246,7 @@ class Sidebar extends Component {
|
|||
render() {
|
||||
const { showStatus } = this.state;
|
||||
const {
|
||||
user, Site_Name, baseUrl, split, theme
|
||||
user, Site_Name, baseUrl, useRealName, split, theme
|
||||
} = this.props;
|
||||
|
||||
if (!user) {
|
||||
|
@ -278,7 +282,7 @@ class Sidebar extends Component {
|
|||
<View style={styles.headerTextContainer}>
|
||||
<View style={styles.headerUsername}>
|
||||
<Status style={styles.status} size={12} status={user && user.status} theme={theme} />
|
||||
<Text numberOfLines={1} style={[styles.username, { color: themes[theme].titleText }]}>{user.username}</Text>
|
||||
<Text numberOfLines={1} style={[styles.username, { color: themes[theme].titleText }]}>{useRealName ? user.name : user.username}</Text>
|
||||
</View>
|
||||
<Text style={[styles.currentServerText, { color: themes[theme].titleText }]} numberOfLines={1}>{Site_Name}</Text>
|
||||
</View>
|
||||
|
@ -300,7 +304,8 @@ const mapStateToProps = state => ({
|
|||
Site_Name: state.settings.Site_Name,
|
||||
user: getUserSelector(state),
|
||||
baseUrl: state.server.server,
|
||||
loadingServer: state.server.loading
|
||||
loadingServer: state.server.loading,
|
||||
useRealName: state.settings.UI_Use_Real_Name
|
||||
});
|
||||
|
||||
export default connect(mapStateToProps)(withTheme(withSplit(Sidebar)));
|
||||
|
|
Loading…
Reference in New Issue