This commit is contained in:
Guilherme Gazzo 2017-11-21 15:09:22 -02:00
parent f2076ea6c8
commit aafa01c812
No known key found for this signature in database
GPG Key ID: 1F85C9AD922D0829
6 changed files with 18 additions and 15 deletions

View File

@ -27,7 +27,7 @@ export const FORGOT_PASSWORD = createRequestTypes('FORGOT_PASSWORD', [
'INIT'
]);
export const ROOMS = createRequestTypes('ROOMS');
export const ROOM = createRequestTypes('ROOM', ['ADD_USER_TYPING', 'REMOVE_USER_TYPING', 'USER_TYPING', 'OPEN', 'IM_TYPING']);
export const ROOM = createRequestTypes('ROOM', ['ADD_USER_TYPING', 'REMOVE_USER_TYPING', 'SOMEONE_TYPING', 'OPEN', 'USER_TYPING']);
export const APP = createRequestTypes('APP', ['READY', 'INIT']);
export const MESSAGES = createRequestTypes('MESSAGES', [
...defaultTypes,

View File

@ -8,9 +8,9 @@ export function removeUserTyping(username) {
};
}
export function typing(data) {
export function someoneTyping(data) {
return {
type: types.ROOM.USER_TYPING,
type: types.ROOM.SOMEONE_TYPING,
...data
};
}
@ -29,9 +29,9 @@ export function openRoom(room) {
};
}
export function imTyping(status = true) {
export function userTyping(status = true) {
return {
type: types.ROOM.IM_TYPING,
type: types.ROOM.USER_TYPING,
status
};
}

View File

@ -4,7 +4,7 @@ import { View, TextInput, StyleSheet, SafeAreaView } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialIcons';
import ImagePicker from 'react-native-image-picker';
import { connect } from 'react-redux';
import { imTyping } from '../actions/room';
import { userTyping } from '../actions/room';
import RocketChat from '../lib/rocketchat';
import { editRequest } from '../actions/messages';
@ -41,7 +41,7 @@ const styles = StyleSheet.create({
editing: state.messages.editing
}), dispatch => ({
editRequest: message => dispatch(editRequest(message)),
typing: status => dispatch(imTyping(status))
typing: status => dispatch(userTyping(status))
}))
export default class MessageBox extends React.Component {
static propTypes = {
@ -49,7 +49,8 @@ export default class MessageBox extends React.Component {
rid: PropTypes.string.isRequired,
editRequest: PropTypes.func.isRequired,
message: PropTypes.object,
editing: PropTypes.bool
editing: PropTypes.bool,
typing: PropTypes.bool
}
componentWillReceiveProps(nextProps) {

View File

@ -8,7 +8,7 @@ import reduxStore from './createStore';
import settingsType from '../constants/settings';
import realm from './realm';
import * as actions from '../actions';
import { typing } from '../actions/room';
import { someoneTyping } from '../actions/room';
import { disconnect, connectSuccess } from '../actions/connect';
export { Accounts } from 'react-native-meteor';
@ -79,7 +79,7 @@ const RocketChat = {
if (ev !== 'typing') {
return;
}
return reduxStore.dispatch(typing({ _rid, username: ddpMessage.fields.args[0], typing: ddpMessage.fields.args[1] }));
return reduxStore.dispatch(someoneTyping({ _rid, username: ddpMessage.fields.args[0], typing: ddpMessage.fields.args[1] }));
}
if (ddpMessage.collection === 'stream-notify-user') {
const [type, data] = ddpMessage.fields.args;

View File

@ -22,7 +22,7 @@ const watchRoomsRequest = function* watchRoomsRequest() {
const cancelTyping = function* cancelTyping(username) {
while (true) {
const { typing, timeout } = yield race({
typing: take(types.ROOM.USER_TYPING),
typing: take(types.ROOM.SOMEONE_TYPING),
timeout: yield call(delay, 5000)
});
if (timeout || (typing.username === username && !typing.typing)) {
@ -33,7 +33,7 @@ const cancelTyping = function* cancelTyping(username) {
const usersTyping = function* usersTyping({ rid }) {
while (true) {
const { _rid, username, typing } = yield take(types.ROOM.USER_TYPING);
const { _rid, username, typing } = yield take(types.ROOM.SOMEONE_TYPING);
if (_rid === rid) {
yield (typing ? put(addUserTyping(username)) : put(removeUserTyping(username)));
if (typing) {
@ -70,7 +70,7 @@ const watchRoomOpen = function* watchRoomOpen({ room }) {
subscriptions.forEach(sub => sub.stop());
};
const watchImTyping = function* watchImTyping({ status }) {
const watchuserTyping = function* watchuserTyping({ status }) {
const auth = yield select(state => state.login.isAuthenticated);
if (!auth) {
yield take(types.LOGIN.SUCCESS);
@ -90,7 +90,7 @@ const watchImTyping = function* watchImTyping({ status }) {
};
const root = function* root() {
yield takeLatest(types.ROOM.IM_TYPING, watchImTyping);
yield takeLatest(types.ROOM.USER_TYPING, watchuserTyping);
yield takeLatest(types.LOGIN.SUCCESS, watchRoomsRequest);
yield takeLatest(types.ROOM.OPEN, watchRoomOpen);
};

View File

@ -71,7 +71,9 @@ export default class RoomView extends React.Component {
server: PropTypes.string,
Site_Url: PropTypes.string,
Message_TimeFormat: PropTypes.string,
loading: PropTypes.bool
loading: PropTypes.bool,
usersTyping: PropTypes.array,
username: PropTypes.string
};
constructor(props) {