[NEW] Direct message from user info (#1516)

This commit is contained in:
Prateek Jain 2020-02-14 05:55:42 +05:30 committed by GitHub
parent 400d33250d
commit f1bf2bb26f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 87 additions and 16 deletions

View File

@ -245,6 +245,7 @@ export default {
Message_removed: 'Message removed', Message_removed: 'Message removed',
message: 'message', message: 'message',
messages: 'messages', messages: 'messages',
Message: 'Message',
Messages: 'Messages', Messages: 'Messages',
Message_Reported: 'Message reported', Message_Reported: 'Message reported',
Microphone_Permission_Message: 'Rocket Chat needs access to your microphone so you can send audio message.', Microphone_Permission_Message: 'Rocket Chat needs access to your microphone so you can send audio message.',

View File

@ -1,10 +1,11 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { View, Text, ScrollView } from 'react-native'; import { View, Text, ScrollView } from 'react-native';
import { BorderlessButton } from 'react-native-gesture-handler';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import moment from 'moment'; import moment from 'moment';
import { SafeAreaView } from 'react-navigation'; import { SafeAreaView } from 'react-navigation';
import { CustomIcon } from '../../lib/Icons';
import Status from '../../containers/Status'; import Status from '../../containers/Status';
import Avatar from '../../containers/Avatar'; import Avatar from '../../containers/Avatar';
import styles from './styles'; import styles from './styles';
@ -22,10 +23,14 @@ import { themedHeader } from '../../utils/navigation';
import { getUserSelector } from '../../selectors/login'; import { getUserSelector } from '../../selectors/login';
const PERMISSION_EDIT_ROOM = 'edit-room'; const PERMISSION_EDIT_ROOM = 'edit-room';
const camelize = str => str.replace(/^(.)/, (match, chr) => chr.toUpperCase()); const camelize = str => str.replace(/^(.)/, (match, chr) => chr.toUpperCase());
const getRoomTitle = (room, type, name, theme) => (type === 'd' const getRoomTitle = (room, type, name, username, theme) => (type === 'd'
? <Text testID='room-info-view-name' style={[styles.roomTitle, { color: themes[theme].titleText }]}>{name}</Text> ? (
<>
<Text testID='room-info-view-name' style={[styles.roomTitle, { color: themes[theme].titleText }]}>{ name }</Text>
{username && <Text testID='room-info-view-username' style={[styles.roomUsername, { color: themes[theme].auxiliaryText }]}>{`@${ username }`}</Text>}
</>
)
: ( : (
<View style={styles.roomTitleRow}> <View style={styles.roomTitleRow}>
<RoomTypeIcon type={room.prid ? 'discussion' : room.t} key='room-info-type' theme={theme} /> <RoomTypeIcon type={room.prid ? 'discussion' : room.t} key='room-info-type' theme={theme} />
@ -143,6 +148,24 @@ class RoomInfoView extends React.Component {
} }
} }
goRoom = async() => {
const { roomUser } = this.state;
const { username: name } = roomUser;
const { navigation } = this.props;
try {
const result = await RocketChat.createDirectMessage(name);
if (result.success) {
await navigation.navigate('RoomsListView');
const rid = result.room._id;
navigation.navigate('RoomView', { rid, name, t: 'd' });
}
} catch (e) {
// do nothing
}
}
videoCall = () => RocketChat.callJitsi(this.rid)
isDirect = () => this.t === 'd' isDirect = () => this.t === 'd'
renderItem = (key, room) => { renderItem = (key, room) => {
@ -163,7 +186,7 @@ class RoomInfoView extends React.Component {
const { theme } = this.props; const { theme } = this.props;
if (description) { if (description) {
return ( return (
<View style={[styles.roleBadge, { backgroundColor: themes[theme].focusedBackground }]} key={description}> <View style={[styles.roleBadge, { backgroundColor: themes[theme].auxiliaryBackground }]} key={description}>
<Text style={styles.role}>{ description }</Text> <Text style={styles.role}>{ description }</Text>
</View> </View>
); );
@ -173,10 +196,11 @@ class RoomInfoView extends React.Component {
renderRoles = () => { renderRoles = () => {
const { parsedRoles } = this.state; const { parsedRoles } = this.state;
const { theme } = this.props;
if (parsedRoles && parsedRoles.length) { if (parsedRoles && parsedRoles.length) {
return ( return (
<View style={styles.item}> <View style={styles.item}>
<Text style={styles.itemLabel}>{I18n.t('Roles')}</Text> <Text style={[styles.itemLabel, { color: themes[theme].titleText }]}>{I18n.t('Roles')}</Text>
<View style={styles.rolesContainer}> <View style={styles.rolesContainer}>
{parsedRoles.map(role => this.renderRole(role))} {parsedRoles.map(role => this.renderRole(role))}
</View> </View>
@ -261,6 +285,30 @@ class RoomInfoView extends React.Component {
return null; return null;
} }
renderButton = (onPress, iconName, text) => {
const { theme } = this.props;
return (
<BorderlessButton
onPress={onPress}
style={styles.roomButton}
>
<CustomIcon
name={iconName}
size={30}
color={themes[theme].actionTintColor}
/>
<Text style={[styles.roomButtonText, { color: themes[theme].actionTintColor }]}>{text}</Text>
</BorderlessButton>
);
}
renderButtons = () => (
<View style={styles.roomButtonsContainer}>
{this.renderButton(this.goRoom, 'message', I18n.t('Message'))}
{this.renderButton(this.videoCall, 'video', I18n.t('Video_call'))}
</View>
)
renderChannel = () => { renderChannel = () => {
const { room } = this.state; const { room } = this.state;
return ( return (
@ -287,6 +335,7 @@ class RoomInfoView extends React.Component {
render() { render() {
const { room, roomUser } = this.state; const { room, roomUser } = this.state;
const { theme } = this.props; const { theme } = this.props;
const isDirect = this.isDirect();
if (!room) { if (!room) {
return <View />; return <View />;
} }
@ -298,11 +347,12 @@ class RoomInfoView extends React.Component {
forceInset={{ vertical: 'never' }} forceInset={{ vertical: 'never' }}
testID='room-info-view' testID='room-info-view'
> >
<View style={styles.avatarContainer}> <View style={[styles.avatarContainer, isDirect && styles.avatarContainerDirectRoom, { backgroundColor: themes[theme].auxiliaryBackground }]}>
{this.renderAvatar(room, roomUser)} {this.renderAvatar(room, roomUser)}
<View style={styles.roomTitleContainer}>{ getRoomTitle(room, this.t, roomUser && roomUser.name, theme) }</View> <View style={styles.roomTitleContainer}>{ getRoomTitle(room, this.t, roomUser && roomUser.name, roomUser && roomUser.username, theme) }</View>
{isDirect ? this.renderButtons() : null}
</View> </View>
{this.isDirect() ? this.renderDirect() : this.renderChannel()} {isDirect ? this.renderDirect() : this.renderChannel()}
</SafeAreaView> </SafeAreaView>
</ScrollView> </ScrollView>
); );

View File

@ -8,30 +8,38 @@ export default StyleSheet.create({
}, },
scroll: { scroll: {
flex: 1, flex: 1,
flexDirection: 'column', flexDirection: 'column'
padding: 10
}, },
item: { item: {
padding: 10, paddingVertical: 10,
paddingHorizontal: 20,
justifyContent: 'center' justifyContent: 'center'
}, },
avatarContainer: { avatarContainer: {
height: 250, height: 240,
flexDirection: 'column', flexDirection: 'column',
alignItems: 'center', alignItems: 'center',
justifyContent: 'center' justifyContent: 'center',
marginBottom: 20
},
avatarContainerDirectRoom: {
height: 320
}, },
avatar: { avatar: {
marginHorizontal: 10 marginHorizontal: 10
}, },
roomTitleContainer: { roomTitleContainer: {
paddingTop: 20, paddingTop: 20,
flexDirection: 'row' alignItems: 'center'
}, },
roomTitle: { roomTitle: {
fontSize: 18, fontSize: 20,
...sharedStyles.textMedium ...sharedStyles.textMedium
}, },
roomUsername: {
fontSize: 18,
...sharedStyles.textRegular
},
roomTitleRow: { roomTitleRow: {
flexDirection: 'row', flexDirection: 'row',
alignItems: 'center' alignItems: 'center'
@ -66,5 +74,17 @@ export default StyleSheet.create({
role: { role: {
fontSize: 14, fontSize: 14,
...sharedStyles.textRegular ...sharedStyles.textRegular
},
roomButtonsContainer: {
flexDirection: 'row',
paddingTop: 30
},
roomButton: {
alignItems: 'center',
paddingHorizontal: 20,
justifyContent: 'space-between'
},
roomButtonText: {
marginTop: 5
} }
}); });