[IMPROVEMENT] Room announcements (#1726)

Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
Prateek Jain 2020-02-21 01:14:33 +05:30 committed by GitHub
parent d271e56b2b
commit 2ed8abb223
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 81 additions and 4 deletions

View File

@ -1,8 +1,10 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { Text, View, InteractionManager } from 'react-native'; import { Text, View, InteractionManager } from 'react-native';
import { ScrollView, BorderlessButton } from 'react-native-gesture-handler';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { SafeAreaView } from 'react-navigation'; import { SafeAreaView } from 'react-navigation';
import Modal from 'react-native-modal';
import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord'; import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';
import moment from 'moment'; import moment from 'moment';
@ -51,6 +53,7 @@ import { Review } from '../../utils/review';
import RoomClass from '../../lib/methods/subscriptions/room'; import RoomClass from '../../lib/methods/subscriptions/room';
import { getUserSelector } from '../../selectors/login'; import { getUserSelector } from '../../selectors/login';
import { CONTAINER_TYPES } from '../../lib/methods/actions'; import { CONTAINER_TYPES } from '../../lib/methods/actions';
import Markdown from '../../containers/markdown';
const stateAttrsUpdate = [ const stateAttrsUpdate = [
'joined', 'joined',
@ -62,9 +65,10 @@ const stateAttrsUpdate = [
'loading', 'loading',
'editing', 'editing',
'replying', 'replying',
'reacting' 'reacting',
'showAnnouncementModal'
]; ];
const roomAttrsUpdate = ['f', 'ro', 'blocked', 'blocker', 'archived', 'muted', 'jitsiTimeout']; const roomAttrsUpdate = ['f', 'ro', 'blocked', 'blocker', 'archived', 'muted', 'jitsiTimeout', 'announcement'];
class RoomView extends React.Component { class RoomView extends React.Component {
static navigationOptions = ({ navigation, screenProps }) => { static navigationOptions = ({ navigation, screenProps }) => {
@ -173,7 +177,9 @@ class RoomView extends React.Component {
editing: false, editing: false,
replying: !!selectedMessage, replying: !!selectedMessage,
replyWithMention: false, replyWithMention: false,
reacting: false reacting: false,
showAnnouncementModal: false,
announcement: null
}; };
if (room && room.observe) { if (room && room.observe) {
@ -184,7 +190,6 @@ class RoomView extends React.Component {
this.messagebox = React.createRef(); this.messagebox = React.createRef();
this.list = React.createRef(); this.list = React.createRef();
this.willBlurListener = props.navigation.addListener('willBlur', () => this.mounted = false);
this.mounted = false; this.mounted = false;
this.sub = new RoomClass(this.rid); this.sub = new RoomClass(this.rid);
console.timeEnd(`${ this.constructor.name } init`); console.timeEnd(`${ this.constructor.name } init`);
@ -783,6 +788,56 @@ class RoomView extends React.Component {
return message; return message;
} }
toggleAnnouncementModal = (showModal) => {
this.setState({ showAnnouncementModal: showModal });
}
renderAnnouncement = () => {
const { theme } = this.props;
const { room } = this.state;
if (room.announcement) {
return (
<BorderlessButton style={[styles.announcementTextContainer, { backgroundColor: themes[theme].bannerBackground }]} key='room-user-status' testID='room-user-status' onPress={() => this.toggleAnnouncementModal(true)}>
<Markdown
useMarkdown
msg={room.announcement}
theme={theme}
numberOfLines={1}
preview
/>
</BorderlessButton>
);
} else {
return null;
}
}
renderAnnouncementModal = () => {
const { room, showAnnouncementModal } = this.state;
const { theme } = this.props;
return (
<Modal
onBackdropPress={() => this.toggleAnnouncementModal(false)}
onBackButtonPress={() => this.toggleAnnouncementModal(false)}
useNativeDriver
isVisible={showAnnouncementModal}
animationIn='fadeIn'
animationOut='fadeOut'
>
<View style={[styles.modalView, { backgroundColor: themes[theme].bannerBackground }]}>
<Text style={[styles.announcementTitle, { color: themes[theme].auxiliaryText }]}>{I18n.t('Announcement')}</Text>
<ScrollView style={styles.modalScrollView}>
<Markdown
useMarkdown
msg={room.announcement}
theme={theme}
/>
</ScrollView>
</View>
</Modal>
);
}
renderFooter = () => { renderFooter = () => {
const { const {
joined, room, selectedMessage, editing, replying, replyWithMention joined, room, selectedMessage, editing, replying, replyWithMention
@ -902,6 +957,7 @@ class RoomView extends React.Component {
forceInset={{ vertical: 'never' }} forceInset={{ vertical: 'never' }}
> >
<StatusBar theme={theme} /> <StatusBar theme={theme} />
{this.renderAnnouncement()}
<List <List
ref={this.list} ref={this.list}
listRef={this.setListRef} listRef={this.setListRef}
@ -914,6 +970,7 @@ class RoomView extends React.Component {
loading={loading} loading={loading}
navigation={navigation} navigation={navigation}
/> />
{this.renderAnnouncementModal()}
{this.renderFooter()} {this.renderFooter()}
{this.renderActions()} {this.renderActions()}
<ReactionPicker <ReactionPicker

View File

@ -25,6 +25,26 @@ export default StyleSheet.create({
flexDirection: 'column', flexDirection: 'column',
overflow: 'hidden' overflow: 'hidden'
}, },
announcementTextContainer: {
paddingVertical: 12,
paddingHorizontal: 15,
alignItems: 'center'
},
announcementTitle: {
fontSize: 16,
...sharedStyles.textMedium
},
modalView: {
padding: 20,
justifyContent: 'center'
},
modalScrollView: {
maxHeight: 100,
marginVertical: 20
},
modalCloseButton: {
alignSelf: 'flex-end'
},
joinRoomContainer: { joinRoomContainer: {
justifyContent: 'flex-end', justifyContent: 'flex-end',
alignItems: 'center', alignItems: 'center',