[FIX] Use RealName when necessary (#1758)

Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
Djorkaeff Alexandre 2020-02-21 13:13:05 -03:00 committed by GitHub
parent aeb5ec7c6e
commit 9e4cef5742
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 47 additions and 24 deletions

View File

@ -7,7 +7,7 @@ import { themes } from '../../constants/colors';
import styles from './styles'; import styles from './styles';
const AtMention = React.memo(({ 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 }; let mentionStyle = { ...styles.mention, color: themes[theme].buttonText };
if (mention === 'all' || mention === 'here') { 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 handlePress = () => {
const index = mentions.findIndex(m => m.username === mention);
const navParam = { const navParam = {
t: 'd', t: 'd',
rid: mentions[index]._id rid: user && user._id
}; };
navToRoomInfo(navParam); navToRoomInfo(navParam);
}; };
if (mentions && mentions.length && mentions.findIndex(m => m.username === mention) !== -1) { if (user) {
return ( return (
<Text <Text
style={[preview ? { ...styles.text, color: themes[theme].bodyText } : mentionStyle, ...style]} style={[preview ? { ...styles.text, color: themes[theme].bodyText } : mentionStyle, ...style]}
onPress={preview ? undefined : handlePress} onPress={preview ? undefined : handlePress}
> >
{mention} {useRealName ? user.name : user.username}
</Text> </Text>
); );
} }
@ -60,6 +61,7 @@ AtMention.propTypes = {
navToRoomInfo: PropTypes.func, navToRoomInfo: PropTypes.func,
style: PropTypes.array, style: PropTypes.array,
preview: PropTypes.bool, preview: PropTypes.bool,
useRealName: PropTypes.bool,
theme: PropTypes.string, theme: PropTypes.string,
mentions: PropTypes.oneOfType([PropTypes.array, PropTypes.object]) mentions: PropTypes.oneOfType([PropTypes.array, PropTypes.object])
}; };

View File

@ -73,6 +73,7 @@ class Markdown extends PureComponent {
numberOfLines: PropTypes.number, numberOfLines: PropTypes.number,
useMarkdown: PropTypes.bool, useMarkdown: PropTypes.bool,
customEmojis: PropTypes.bool, customEmojis: PropTypes.bool,
useRealName: PropTypes.bool,
channels: PropTypes.oneOfType([PropTypes.array, PropTypes.object]), channels: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
mentions: PropTypes.oneOfType([PropTypes.array, PropTypes.object]), mentions: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
navToRoomInfo: PropTypes.func, navToRoomInfo: PropTypes.func,
@ -251,12 +252,13 @@ class Markdown extends PureComponent {
renderAtMention = ({ mentionName }) => { renderAtMention = ({ mentionName }) => {
const { const {
username, mentions, navToRoomInfo, preview, style, theme username, mentions, navToRoomInfo, useRealName, preview, style, theme
} = this.props; } = this.props;
return ( return (
<MarkdownAtMention <MarkdownAtMention
mentions={mentions} mentions={mentions}
mention={mentionName} mention={mentionName}
useRealName={useRealName}
username={username} username={username}
navToRoomInfo={navToRoomInfo} navToRoomInfo={navToRoomInfo}
preview={preview} preview={preview}

View File

@ -32,6 +32,7 @@ const Content = React.memo((props) => {
useMarkdown={props.useMarkdown && (!props.tmid || props.isThreadRoom)} useMarkdown={props.useMarkdown && (!props.tmid || props.isThreadRoom)}
navToRoomInfo={props.navToRoomInfo} navToRoomInfo={props.navToRoomInfo}
tmid={props.tmid} tmid={props.tmid}
useRealName={props.useRealName}
theme={props.theme} theme={props.theme}
/> />
); );
@ -58,7 +59,8 @@ Content.propTypes = {
getCustomEmoji: PropTypes.func, getCustomEmoji: PropTypes.func,
channels: PropTypes.oneOfType([PropTypes.array, PropTypes.object]), channels: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
mentions: 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'; Content.displayName = 'MessageContent';

View File

@ -283,10 +283,9 @@ export default function subscribeRooms() {
const [notification] = ddpMessage.fields.args; const [notification] = ddpMessage.fields.args;
try { try {
const { payload: { rid } } = notification; const { payload: { rid } } = notification;
const subCollection = db.collections.get('subscriptions'); const room = await RocketChat.getRoom(rid);
const sub = await subCollection.find(rid); notification.title = RocketChat.getRoomTitle(room);
notification.title = RocketChat.getRoomTitle(sub); notification.avatar = RocketChat.getRoomAvatar(room);
notification.avatar = RocketChat.getRoomAvatar(sub);
} catch (e) { } catch (e) {
// do nothing // do nothing
} }

View File

@ -9,7 +9,7 @@ import { themes } from '../../constants/colors';
import shortnameToUnicode from '../../utils/shortnameToUnicode'; import shortnameToUnicode from '../../utils/shortnameToUnicode';
const formatMsg = ({ const formatMsg = ({
lastMessage, type, showLastMessage, username lastMessage, type, showLastMessage, username, useRealName
}) => { }) => {
if (!showLastMessage) { if (!showLastMessage) {
return ''; return '';
@ -33,7 +33,8 @@ const formatMsg = ({
if (isLastMessageSentByMe) { if (isLastMessageSentByMe) {
prefix = I18n.t('You_colon'); prefix = I18n.t('You_colon');
} else if (type !== 'd') { } 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, '') }`; let msg = `${ prefix }${ lastMessage.msg.replace(/[\n\t\r]/igm, '') }`;
@ -46,14 +47,15 @@ const formatMsg = ({
const arePropsEqual = (oldProps, newProps) => _.isEqual(oldProps, newProps); const arePropsEqual = (oldProps, newProps) => _.isEqual(oldProps, newProps);
const LastMessage = React.memo(({ const LastMessage = React.memo(({
lastMessage, type, showLastMessage, username, alert, theme lastMessage, type, showLastMessage, username, alert, useRealName, theme
}) => ( }) => (
<Markdown <Markdown
msg={formatMsg({ msg={formatMsg({
lastMessage, type, showLastMessage, username lastMessage, type, showLastMessage, username, useRealName
})} })}
style={[styles.markdownText, { color: alert ? themes[theme].bodyText : themes[theme].auxiliaryText }]} style={[styles.markdownText, { color: alert ? themes[theme].bodyText : themes[theme].auxiliaryText }]}
customEmojis={false} customEmojis={false}
useRealName={useRealName}
numberOfLines={2} numberOfLines={2}
preview preview
theme={theme} theme={theme}
@ -66,6 +68,7 @@ LastMessage.propTypes = {
type: PropTypes.string, type: PropTypes.string,
showLastMessage: PropTypes.bool, showLastMessage: PropTypes.bool,
username: PropTypes.string, username: PropTypes.string,
useRealName: PropTypes.bool,
alert: PropTypes.bool alert: PropTypes.bool
}; };

View File

@ -20,6 +20,7 @@ const attrs = [
'unread', 'unread',
'userMentions', 'userMentions',
'showLastMessage', 'showLastMessage',
'useRealName',
'alert', 'alert',
'type', 'type',
'width', 'width',
@ -39,7 +40,7 @@ const arePropsEqual = (oldProps, newProps) => {
}; };
const RoomItem = React.memo(({ 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); const date = formatDate(_updatedAt);
@ -144,6 +145,7 @@ const RoomItem = React.memo(({
showLastMessage={showLastMessage} showLastMessage={showLastMessage}
username={username} username={username}
alert={alert && !hideUnreadStatus} alert={alert && !hideUnreadStatus}
useRealName={useRealName}
theme={theme} theme={theme}
/> />
<UnreadBadge <UnreadBadge
@ -187,6 +189,7 @@ RoomItem.propTypes = {
hideChannel: PropTypes.func, hideChannel: PropTypes.func,
avatar: PropTypes.bool, avatar: PropTypes.bool,
hideUnreadStatus: PropTypes.bool, hideUnreadStatus: PropTypes.bool,
useRealName: PropTypes.bool,
theme: PropTypes.string theme: PropTypes.string
}; };

View File

@ -151,14 +151,14 @@ class RoomInfoView extends React.Component {
goRoom = async() => { goRoom = async() => {
const { roomUser } = this.state; const { roomUser } = this.state;
const { username: name } = roomUser; const { username } = roomUser;
const { navigation } = this.props; const { navigation } = this.props;
try { try {
const result = await RocketChat.createDirectMessage(name); const result = await RocketChat.createDirectMessage(username);
if (result.success) { if (result.success) {
await navigation.navigate('RoomsListView'); await navigation.navigate('RoomsListView');
const rid = result.room._id; const rid = result.room._id;
navigation.navigate('RoomView', { rid, name, t: 'd' }); navigation.navigate('RoomView', { rid, name: RocketChat.getRoomTitle(roomUser), t: 'd' });
} }
} catch (e) { } catch (e) {
// do nothing // do nothing

View File

@ -366,7 +366,11 @@ class RoomView extends React.Component {
const subCollection = await db.collections.get('subscriptions'); const subCollection = await db.collections.get('subscriptions');
const room = await subCollection.find(rid); const room = await subCollection.find(rid);
this.setState({ room }); this.setState({ room });
navigation.setParams({ room }); navigation.setParams({
name: this.getRoomTitle(room),
avatar: room.name,
t: room.t
});
this.observeRoom(room); this.observeRoom(room);
} catch (error) { } catch (error) {
if (this.t !== 'd') { if (this.t !== 'd') {

View File

@ -173,6 +173,7 @@ class RoomsListView extends React.Component {
appStart: PropTypes.func, appStart: PropTypes.func,
roomsRequest: PropTypes.func, roomsRequest: PropTypes.func,
closeServerDropdown: PropTypes.func, closeServerDropdown: PropTypes.func,
useRealName: PropTypes.bool,
split: PropTypes.bool split: PropTypes.bool
}; };
@ -757,6 +758,7 @@ class RoomsListView extends React.Component {
}, },
server, server,
StoreLastMessage, StoreLastMessage,
useRealName,
theme, theme,
split split
} = this.props; } = this.props;
@ -791,6 +793,7 @@ class RoomsListView extends React.Component {
toggleFav={this.toggleFav} toggleFav={this.toggleFav}
toggleRead={this.toggleRead} toggleRead={this.toggleRead}
hideChannel={this.hideChannel} hideChannel={this.hideChannel}
useRealName={useRealName}
/> />
); );
}; };

View File

@ -47,6 +47,7 @@ class Sidebar extends Component {
activeItemKey: PropTypes.string, activeItemKey: PropTypes.string,
theme: PropTypes.string, theme: PropTypes.string,
loadingServer: PropTypes.bool, loadingServer: PropTypes.bool,
useRealName: PropTypes.bool,
split: PropTypes.bool split: PropTypes.bool
} }
@ -77,7 +78,7 @@ class Sidebar extends Component {
shouldComponentUpdate(nextProps, nextState) { shouldComponentUpdate(nextProps, nextState) {
const { status, showStatus, isAdmin } = this.state; const { status, showStatus, isAdmin } = this.state;
const { const {
Site_Name, user, baseUrl, activeItemKey, split, theme Site_Name, user, baseUrl, activeItemKey, split, useRealName, theme
} = this.props; } = this.props;
if (nextState.showStatus !== showStatus) { if (nextState.showStatus !== showStatus) {
return true; return true;
@ -111,6 +112,9 @@ class Sidebar extends Component {
if (nextProps.split !== split) { if (nextProps.split !== split) {
return true; return true;
} }
if (nextProps.useRealName !== useRealName) {
return true;
}
if (!equal(nextState.status, status)) { if (!equal(nextState.status, status)) {
return true; return true;
} }
@ -242,7 +246,7 @@ class Sidebar extends Component {
render() { render() {
const { showStatus } = this.state; const { showStatus } = this.state;
const { const {
user, Site_Name, baseUrl, split, theme user, Site_Name, baseUrl, useRealName, split, theme
} = this.props; } = this.props;
if (!user) { if (!user) {
@ -278,7 +282,7 @@ class Sidebar extends Component {
<View style={styles.headerTextContainer}> <View style={styles.headerTextContainer}>
<View style={styles.headerUsername}> <View style={styles.headerUsername}>
<Status style={styles.status} size={12} status={user && user.status} theme={theme} /> <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> </View>
<Text style={[styles.currentServerText, { color: themes[theme].titleText }]} numberOfLines={1}>{Site_Name}</Text> <Text style={[styles.currentServerText, { color: themes[theme].titleText }]} numberOfLines={1}>{Site_Name}</Text>
</View> </View>
@ -300,7 +304,8 @@ const mapStateToProps = state => ({
Site_Name: state.settings.Site_Name, Site_Name: state.settings.Site_Name,
user: getUserSelector(state), user: getUserSelector(state),
baseUrl: state.server.server, 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))); export default connect(mapStateToProps)(withTheme(withSplit(Sidebar)));