[IMPROVEMENT] Make username clickable on message (#1618)
Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
parent
1a3551169f
commit
d11277e691
File diff suppressed because it is too large
Load Diff
|
@ -1,6 +1,8 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { View, Text, StyleSheet } from 'react-native';
|
import {
|
||||||
|
View, Text, StyleSheet, TouchableOpacity
|
||||||
|
} from 'react-native';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
|
||||||
import { themes } from '../../constants/colors';
|
import { themes } from '../../constants/colors';
|
||||||
|
@ -33,21 +35,30 @@ const styles = StyleSheet.create({
|
||||||
});
|
});
|
||||||
|
|
||||||
const User = React.memo(({
|
const User = React.memo(({
|
||||||
isHeader, useRealName, author, alias, ts, timeFormat, hasError, theme, ...props
|
isHeader, useRealName, author, alias, ts, timeFormat, hasError, theme, navToRoomInfo, user, ...props
|
||||||
}) => {
|
}) => {
|
||||||
if (isHeader || hasError) {
|
if (isHeader || hasError) {
|
||||||
|
const navParam = {
|
||||||
|
t: 'd',
|
||||||
|
rid: author._id
|
||||||
|
};
|
||||||
const username = (useRealName && author.name) || author.username;
|
const username = (useRealName && author.name) || author.username;
|
||||||
const aliasUsername = alias ? (<Text style={[styles.alias, { color: themes[theme].auxiliaryText }]}> @{username}</Text>) : null;
|
const aliasUsername = alias ? (<Text style={[styles.alias, { color: themes[theme].auxiliaryText }]}> @{username}</Text>) : null;
|
||||||
const time = moment(ts).format(timeFormat);
|
const time = moment(ts).format(timeFormat);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<View style={styles.titleContainer}>
|
<TouchableOpacity
|
||||||
<Text style={[styles.username, { color: themes[theme].titleText }]} numberOfLines={1}>
|
onPress={() => navToRoomInfo(navParam)}
|
||||||
{alias || username}
|
disabled={author._id === user.id}
|
||||||
{aliasUsername}
|
>
|
||||||
</Text>
|
<View style={styles.titleContainer}>
|
||||||
</View>
|
<Text style={[styles.username, { color: themes[theme].titleText }]} numberOfLines={1}>
|
||||||
|
{alias || username}
|
||||||
|
{aliasUsername}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
</TouchableOpacity>
|
||||||
<Text style={[messageStyles.time, { color: themes[theme].auxiliaryText }]}>{time}</Text>
|
<Text style={[messageStyles.time, { color: themes[theme].auxiliaryText }]}>{time}</Text>
|
||||||
{ hasError && <MessageError hasError={hasError} theme={theme} {...props} /> }
|
{ hasError && <MessageError hasError={hasError} theme={theme} {...props} /> }
|
||||||
</View>
|
</View>
|
||||||
|
@ -64,7 +75,9 @@ User.propTypes = {
|
||||||
alias: PropTypes.string,
|
alias: PropTypes.string,
|
||||||
ts: PropTypes.instanceOf(Date),
|
ts: PropTypes.instanceOf(Date),
|
||||||
timeFormat: PropTypes.string,
|
timeFormat: PropTypes.string,
|
||||||
theme: PropTypes.string
|
theme: PropTypes.string,
|
||||||
|
user: PropTypes.obj,
|
||||||
|
navToRoomInfo: PropTypes.func
|
||||||
};
|
};
|
||||||
User.displayName = 'MessageUser';
|
User.displayName = 'MessageUser';
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue