Merge remote-tracking branch 'origin/develop' into messages-permissions-some-fixes
This commit is contained in:
commit
4bacf0c42b
|
@ -65,12 +65,13 @@ export default class MessageBox extends React.Component {
|
|||
}
|
||||
|
||||
submit(message) {
|
||||
const { editing } = this.props;
|
||||
this.component.setNativeProps({ text: '' });
|
||||
this.props.typing(false);
|
||||
if (message.trim() === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
// if is editing a message
|
||||
const { editing } = this.props;
|
||||
if (editing) {
|
||||
const { _id, rid } = this.props.message;
|
||||
this.props.editRequest({ _id, msg: message, rid });
|
||||
|
@ -78,7 +79,6 @@ export default class MessageBox extends React.Component {
|
|||
// if is submiting a new message
|
||||
this.props.onSubmit(message);
|
||||
}
|
||||
this.component.setNativeProps({ text: '' });
|
||||
this.props.clearInput();
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
import React from 'react';
|
||||
|
||||
import PropTypes from 'prop-types';
|
||||
import { StyleSheet, Text } from 'react-native';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
typing: {
|
||||
|
||||
transform: [{ scaleY: -1 }],
|
||||
fontWeight: 'bold',
|
||||
paddingHorizontal: 15,
|
||||
height: 25
|
||||
}
|
||||
});
|
||||
|
||||
@connect(state => ({
|
||||
username: state.login.user && state.login.user.username,
|
||||
usersTyping: state.room.usersTyping
|
||||
}))
|
||||
|
||||
export default class Typing extends React.PureComponent {
|
||||
get usersTyping() {
|
||||
const users = this.props.usersTyping.filter(_username => this.props.username !== _username);
|
||||
return users.length ? `${ users.join(' ,') } ${ users.length > 1 ? 'are' : 'is' } typing` : '';
|
||||
}
|
||||
render() {
|
||||
return (<Text style={styles.typing}>{this.usersTyping}</Text>);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Typing.propTypes = {
|
||||
username: PropTypes.string,
|
||||
usersTyping: PropTypes.array
|
||||
};
|
|
@ -80,7 +80,7 @@ const subscriptionSchema = {
|
|||
userMentions: { type: 'int', optional: true },
|
||||
// userMentions: 0,
|
||||
// groupMentions: 0,
|
||||
_updatedAt: { type: 'date', optional: true }
|
||||
roomUpdatedAt: { type: 'date', optional: true }
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -88,27 +88,14 @@ const RocketChat = {
|
|||
if (data.roles) {
|
||||
data.roles = data.roles.map(role => ({ value: role }));
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case 'inserted':
|
||||
data._server = server;
|
||||
realm.write(() => {
|
||||
realm.create('subscriptions', data, true);
|
||||
});
|
||||
break;
|
||||
case 'updated':
|
||||
delete data._updatedAt;
|
||||
realm.write(() => {
|
||||
realm.create('subscriptions', data, true);
|
||||
});
|
||||
break;
|
||||
default:
|
||||
}
|
||||
realm.write(() => {
|
||||
realm.create('subscriptions', data, true);
|
||||
});
|
||||
}
|
||||
if (/rooms/.test(ev) && type === 'updated') {
|
||||
const sub = realm.objects('subscriptions').filtered('rid == $0', data._id)[0];
|
||||
realm.write(() => {
|
||||
sub._updatedAt = data._updatedAt;
|
||||
sub.roomUpdatedAt = data._updatedAt;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -219,6 +206,7 @@ const RocketChat = {
|
|||
},
|
||||
|
||||
loadSubscriptions(cb) {
|
||||
const { server } = reduxStore.getState().server;
|
||||
Meteor.call('subscriptions/get', (err, data) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
|
@ -232,7 +220,7 @@ const RocketChat = {
|
|||
// if (typeof item.value === 'string') {
|
||||
// subscription.value = item.value;
|
||||
// }
|
||||
subscription._server = { id: reduxStore.getState().server.server };
|
||||
subscription._server = { id: server };
|
||||
// write('subscriptions', subscription);
|
||||
realm.create('subscriptions', subscription, true);
|
||||
});
|
||||
|
@ -398,19 +386,19 @@ const RocketChat = {
|
|||
let lastMessage = realm
|
||||
.objects('subscriptions')
|
||||
.filtered('_server.id = $0', server.server)
|
||||
.sorted('_updatedAt', true)[0];
|
||||
lastMessage = lastMessage && new Date(lastMessage._updatedAt);
|
||||
.sorted('roomUpdatedAt', true)[0];
|
||||
lastMessage = lastMessage && new Date(lastMessage.roomUpdatedAt);
|
||||
let [subscriptions, rooms] = await Promise.all([call('subscriptions/get', lastMessage), call('rooms/get', lastMessage)]);
|
||||
|
||||
if (lastMessage) {
|
||||
subscriptions = subscriptions.update;
|
||||
rooms = rooms.update;
|
||||
}
|
||||
|
||||
const data = subscriptions.map((subscription) => {
|
||||
const room = rooms.find(({ _id }) => _id === subscription.rid);
|
||||
delete subscription._updatedAt;
|
||||
if (room) {
|
||||
subscription._updatedAt = room._updatedAt;
|
||||
subscription.roomUpdatedAt = room._updatedAt;
|
||||
}
|
||||
if (subscription.roles) {
|
||||
subscription.roles = subscription.roles.map(role => ({ value: role }));
|
||||
|
@ -418,7 +406,6 @@ const RocketChat = {
|
|||
subscription._server = { id: server.server };
|
||||
return subscription;
|
||||
});
|
||||
|
||||
realm.write(() => {
|
||||
data.forEach(subscription =>
|
||||
realm.create('subscriptions', subscription, true));
|
||||
|
|
|
@ -23,7 +23,7 @@ const cancelTyping = function* cancelTyping(username) {
|
|||
while (true) {
|
||||
const { typing, timeout } = yield race({
|
||||
typing: take(types.ROOM.SOMEONE_TYPING),
|
||||
timeout: yield call(delay, 5000)
|
||||
timeout: call(delay, 5000)
|
||||
});
|
||||
if (timeout || (typing.username === username && !typing.typing)) {
|
||||
return yield put(removeUserTyping(username));
|
||||
|
@ -37,7 +37,7 @@ const usersTyping = function* usersTyping({ rid }) {
|
|||
if (_rid === rid) {
|
||||
yield (typing ? put(addUserTyping(username)) : put(removeUserTyping(username)));
|
||||
if (typing) {
|
||||
fork(cancelTyping, username);
|
||||
yield fork(cancelTyping, username);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Text, View, StyleSheet, Button, SafeAreaView, Dimensions } from 'react-native';
|
||||
import { Text, View, StyleSheet, Button, SafeAreaView } from 'react-native';
|
||||
import { ListView } from 'realm/react-native';
|
||||
import { connect } from 'react-redux';
|
||||
import { bindActionCreators } from 'redux';
|
||||
|
@ -13,6 +13,7 @@ import RocketChat from '../lib/rocketchat';
|
|||
import Message from '../containers/message';
|
||||
import MessageActions from '../containers/MessageActions';
|
||||
import MessageBox from '../containers/MessageBox';
|
||||
import Typing from '../containers/Typing';
|
||||
import KeyboardView from '../presentation/KeyboardView';
|
||||
|
||||
const ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1._id !== r2._id });
|
||||
|
@ -48,11 +49,9 @@ const styles = StyleSheet.create({
|
|||
color: '#ccc'
|
||||
}
|
||||
});
|
||||
|
||||
const typing = () => <Typing />;
|
||||
@connect(
|
||||
state => ({
|
||||
user: state.login.user,
|
||||
usersTyping: state.room.usersTyping,
|
||||
server: state.server.server,
|
||||
Site_Url: state.settings.Site_Url,
|
||||
Message_TimeFormat: state.settings.Message_TimeFormat,
|
||||
|
@ -70,14 +69,12 @@ export default class RoomView extends React.Component {
|
|||
openRoom: PropTypes.func.isRequired,
|
||||
editCancel: PropTypes.func,
|
||||
rid: PropTypes.string,
|
||||
server: PropTypes.string,
|
||||
sid: PropTypes.string,
|
||||
name: PropTypes.string,
|
||||
server: PropTypes.string,
|
||||
Site_Url: PropTypes.string,
|
||||
Message_TimeFormat: PropTypes.string,
|
||||
loading: PropTypes.bool,
|
||||
usersTyping: PropTypes.array,
|
||||
user: PropTypes.object
|
||||
loading: PropTypes.bool
|
||||
};
|
||||
|
||||
constructor(props) {
|
||||
|
@ -147,11 +144,6 @@ export default class RoomView extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
get usersTyping() {
|
||||
const users = this.props.usersTyping.filter(_username => this.props.user.username !== _username);
|
||||
return users.length ? `${ users.join(' ,') } ${ users.length > 1 ? 'are' : 'is' } typing` : null;
|
||||
}
|
||||
|
||||
updateState = () => {
|
||||
this.setState({
|
||||
dataSource: ds.cloneWithRows(this.data)
|
||||
|
@ -207,7 +199,6 @@ export default class RoomView extends React.Component {
|
|||
}
|
||||
}
|
||||
render() {
|
||||
const { height } = Dimensions.get('window');
|
||||
return (
|
||||
<KeyboardView contentContainerStyle={styles.container} keyboardVerticalOffset={64}>
|
||||
{this.renderBanner()}
|
||||
|
@ -215,8 +206,9 @@ export default class RoomView extends React.Component {
|
|||
<ListView
|
||||
enableEmptySections
|
||||
style={styles.list}
|
||||
onEndReachedThreshold={height / 2}
|
||||
onEndReachedThreshold={0.5}
|
||||
renderFooter={this.renderHeader}
|
||||
renderHeader={typing}
|
||||
onEndReached={this.onEndReached}
|
||||
dataSource={this.state.dataSource}
|
||||
renderRow={item => this.renderItem({ item })}
|
||||
|
@ -224,7 +216,6 @@ export default class RoomView extends React.Component {
|
|||
/>
|
||||
</SafeAreaView>
|
||||
{this.renderFooter()}
|
||||
<Text style={styles.typing}>{this.usersTyping}</Text>
|
||||
<MessageActions room={this.room} />
|
||||
</KeyboardView>
|
||||
);
|
||||
|
|
|
@ -103,7 +103,7 @@ export default class RoomsListView extends React.Component {
|
|||
dataSource: ds.cloneWithRows([]),
|
||||
searchText: ''
|
||||
};
|
||||
this.data = realm.objects('subscriptions').filtered('_server.id = $0', this.props.server).sorted('_updatedAt', true);
|
||||
this.data = realm.objects('subscriptions').filtered('_server.id = $0', this.props.server).sorted('roomUpdatedAt', true);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
|
@ -119,7 +119,7 @@ export default class RoomsListView extends React.Component {
|
|||
componentWillReceiveProps(props) {
|
||||
if (this.props.server !== props.server) {
|
||||
this.data.removeListener(this.updateState);
|
||||
this.data = realm.objects('subscriptions').filtered('_server.id = $0', props.server).sorted('_updatedAt', true);
|
||||
this.data = realm.objects('subscriptions').filtered('_server.id = $0', props.server).sorted('roomUpdatedAt', true);
|
||||
this.data.addListener(this.updateState);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue