RoomInfoView
This commit is contained in:
parent
97ae9bce13
commit
15e1897fb3
|
@ -49,28 +49,6 @@ const getRoomTitle = (room, type, name, username, statusText, theme) => (type ==
|
||||||
);
|
);
|
||||||
|
|
||||||
class RoomInfoView extends React.Component {
|
class RoomInfoView extends React.Component {
|
||||||
static navigationOptions = ({ navigation, route }) => {
|
|
||||||
const t = route.params?.t;
|
|
||||||
const rid = route.params?.rid;
|
|
||||||
const room = route.params?.room;
|
|
||||||
const roomUser = route.params?.roomUser;
|
|
||||||
const showEdit = route.params?.showEdit;
|
|
||||||
return {
|
|
||||||
title: t === 'd' ? I18n.t('User_Info') : I18n.t('Room_Info'),
|
|
||||||
headerRight: showEdit
|
|
||||||
? (
|
|
||||||
<CustomHeaderButtons>
|
|
||||||
<Item
|
|
||||||
iconName='edit'
|
|
||||||
onPress={() => navigation.navigate(t === 'l' ? 'LivechatEditView' : 'RoomInfoEditView', { rid, room, roomUser })}
|
|
||||||
testID='room-info-view-edit-button'
|
|
||||||
/>
|
|
||||||
</CustomHeaderButtons>
|
|
||||||
)
|
|
||||||
: null
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
navigation: PropTypes.object,
|
navigation: PropTypes.object,
|
||||||
route: PropTypes.object,
|
route: PropTypes.object,
|
||||||
|
@ -92,7 +70,8 @@ class RoomInfoView extends React.Component {
|
||||||
this.t = props.route.params?.t;
|
this.t = props.route.params?.t;
|
||||||
this.state = {
|
this.state = {
|
||||||
room: room || { rid: this.rid, t: this.t },
|
room: room || { rid: this.rid, t: this.t },
|
||||||
roomUser: roomUser || {}
|
roomUser: roomUser || {},
|
||||||
|
showEdit: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,6 +99,27 @@ class RoomInfoView extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setHeader = () => {
|
||||||
|
const { roomUser, room, showEdit } = this.state;
|
||||||
|
const { navigation, route } = this.props;
|
||||||
|
const t = route.params?.t;
|
||||||
|
const rid = route.params?.rid;
|
||||||
|
navigation.setOptions({
|
||||||
|
title: t === 'd' ? I18n.t('User_Info') : I18n.t('Room_Info'),
|
||||||
|
headerRight: showEdit
|
||||||
|
? () => (
|
||||||
|
<CustomHeaderButtons>
|
||||||
|
<Item
|
||||||
|
iconName='edit'
|
||||||
|
onPress={() => navigation.navigate(t === 'l' ? 'LivechatEditView' : 'RoomInfoEditView', { rid, room, roomUser })}
|
||||||
|
testID='room-info-view-edit-button'
|
||||||
|
/>
|
||||||
|
</CustomHeaderButtons>
|
||||||
|
)
|
||||||
|
: null
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
get isDirect() {
|
get isDirect() {
|
||||||
const { room } = this.state;
|
const { room } = this.state;
|
||||||
return room.t === 'd';
|
return room.t === 'd';
|
||||||
|
@ -146,8 +146,6 @@ class RoomInfoView extends React.Component {
|
||||||
|
|
||||||
loadVisitor = async() => {
|
loadVisitor = async() => {
|
||||||
const { room } = this.state;
|
const { room } = this.state;
|
||||||
const { navigation } = this.props;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await RocketChat.getVisitorInfo(room?.visitor?._id);
|
const result = await RocketChat.getVisitorInfo(room?.visitor?._id);
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
|
@ -159,7 +157,7 @@ class RoomInfoView extends React.Component {
|
||||||
visitor.browser = `${ ua.getBrowser().name } ${ ua.getBrowser().version }`;
|
visitor.browser = `${ ua.getBrowser().name } ${ ua.getBrowser().version }`;
|
||||||
}
|
}
|
||||||
this.setState({ roomUser: visitor });
|
this.setState({ roomUser: visitor });
|
||||||
navigation.setParams({ roomUser: visitor });
|
this.setHeader();
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
|
@ -194,14 +192,14 @@ class RoomInfoView extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
loadRoom = async() => {
|
loadRoom = async() => {
|
||||||
const { navigation } = this.props;
|
const { route } = this.props;
|
||||||
let room = navigation.getParam('room');
|
let room = route.params?.room;
|
||||||
if (room && room.observe) {
|
if (room && room.observe) {
|
||||||
this.roomObservable = room.observe();
|
this.roomObservable = room.observe();
|
||||||
this.subscription = this.roomObservable
|
this.subscription = this.roomObservable
|
||||||
.subscribe((changes) => {
|
.subscribe((changes) => {
|
||||||
this.setState({ room: changes });
|
this.setState({ room: changes });
|
||||||
navigation.setParams({ room: changes });
|
this.setHeader();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
|
@ -217,7 +215,8 @@ class RoomInfoView extends React.Component {
|
||||||
|
|
||||||
const permissions = await RocketChat.hasPermission([PERMISSION_EDIT_ROOM], room.rid);
|
const permissions = await RocketChat.hasPermission([PERMISSION_EDIT_ROOM], room.rid);
|
||||||
if (permissions[PERMISSION_EDIT_ROOM] && !room.prid) {
|
if (permissions[PERMISSION_EDIT_ROOM] && !room.prid) {
|
||||||
navigation.setParams({ showEdit: true });
|
this.setState({ showEdit: true });
|
||||||
|
this.setHeader();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue