Skip to content

Commit

Permalink
Deep linking fix and more (#294)
Browse files Browse the repository at this point in the history
* Fix - Any https link was deep linking to RocketChat

* Keyboard dismiss after add new server

* Room info bug fix

* Opacity animation

* Navigation when adding server fixed

* Throttle for unnecessary render on receiving several messages

* Search inputs without autocorrect and autocapitalize

* Search messages fixed

* Messagebox unnecessary render and spotlight fixed

* react-native-keyboard-input updated
  • Loading branch information
diegolmello authored and ggazzo committed May 18, 2018
1 parent d356f07 commit e69a6c0
Show file tree
Hide file tree
Showing 52 changed files with 611 additions and 405 deletions.
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ dependencies {
compile project(':react-native-fast-image')
compile project(':realm')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.android.support:appcompat-v7:27.1.0"
compile "com.android.support:support-v4:27.1.0"
compile 'com.android.support:customtabs:23.0.1'
compile 'com.android.support:customtabs:27.1.0'
compile "com.facebook.react:react-native:+" // From node_modules
compile 'com.facebook.fresco:fresco:1.7.1'
compile 'com.facebook.fresco:animated-gif:1.7.1'
Expand Down
3 changes: 2 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" android:host="go.rocket.chat" />
<data android:scheme="rocketchat" android:host="*" />
<data android:scheme="rocketchat" android:host="room" />
<data android:scheme="rocketchat" android:host="auth" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
Expand Down
1 change: 1 addition & 0 deletions app/ReactotronConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ if (__DEV__) {
.connect();
// Running on android device
// $ adb reverse tcp:9090 tcp:9090
console.warn = Reactotron.log;
}
6 changes: 2 additions & 4 deletions app/actions/actionsTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ export const ROOM = createRequestTypes('ROOM', [
'ERASE',
'USER_TYPING',
'MESSAGE_RECEIVED',
'SET_LAST_OPEN',
'LAYOUT_ANIMATION'
'SET_LAST_OPEN'
]);
export const APP = createRequestTypes('APP', ['READY', 'INIT']);
export const MESSAGES = createRequestTypes('MESSAGES', [
Expand Down Expand Up @@ -81,8 +80,7 @@ export const SERVER = createRequestTypes('SERVER', [
...defaultTypes,
'SELECT',
'CHANGED',
'ADD',
'GOTO_ADD'
'ADD'
]);
export const METEOR = createRequestTypes('METEOR_CONNECT', [...defaultTypes, 'DISCONNECT', 'DISCONNECT_BY_USER']);
export const LOGOUT = 'LOGOUT'; // logout is always success
Expand Down
6 changes: 0 additions & 6 deletions app/actions/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,3 @@ export function setLastOpen(date = new Date()) {
date
};
}

export function layoutAnimation() {
return {
type: types.ROOM.LAYOUT_ANIMATION
};
}
6 changes: 0 additions & 6 deletions app/actions/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,3 @@ export function changedServer(server) {
server
};
}

export function gotoAddServer() {
return {
type: SERVER.GOTO_ADD
};
}
5 changes: 3 additions & 2 deletions app/containers/EmojiPicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import styles from './styles';
import categories from './categories';
import database from '../../lib/realm';
import { emojisByCategory } from '../../emojis';
import protectedFunction from '../../lib/methods/helpers/protectedFunction';

const scrollProps = {
keyboardShouldPersistTaps: 'always',
Expand Down Expand Up @@ -68,11 +69,11 @@ export default class EmojiPicker extends Component {
}
}

_addFrequentlyUsed = (emoji) => {
_addFrequentlyUsed = protectedFunction((emoji) => {
database.write(() => {
database.create('frequentlyUsedEmoji', emoji, true);
});
}
})
_getFrequentlyUsedCount = (content) => {
const emojiRow = this.frequentlyUsed.filtered('content == $0', content);
return emojiRow.length ? emojiRow[0].count + 1 : 1;
Expand Down
58 changes: 30 additions & 28 deletions app/containers/MessageBox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { connect } from 'react-redux';
import { emojify } from 'react-emojione';
import { KeyboardAccessoryView } from 'react-native-keyboard-input';

import { userTyping, layoutAnimation } from '../../actions/room';
import { userTyping } from '../../actions/room';
import RocketChat from '../../lib/rocketchat';
import { editRequest, editCancel, clearInput } from '../../actions/messages';
import styles from './styles';
Expand All @@ -18,7 +18,7 @@ import CustomEmoji from '../EmojiPicker/CustomEmoji';
import { emojis } from '../../emojis';
import Recording from './Recording';
import './EmojiKeyboard';

import log from '../../utils/log';

const MENTIONS_TRACKING_TYPE_USERS = '@';
const MENTIONS_TRACKING_TYPE_EMOJIS = ':';
Expand All @@ -36,8 +36,7 @@ const onlyUnique = function onlyUnique(value, index, self) {
editCancel: () => dispatch(editCancel()),
editRequest: message => dispatch(editRequest(message)),
typing: status => dispatch(userTyping(status)),
clearInput: () => dispatch(clearInput()),
layoutAnimation: () => dispatch(layoutAnimation())
clearInput: () => dispatch(clearInput())
}))
export default class MessageBox extends React.PureComponent {
static propTypes = {
Expand All @@ -49,16 +48,14 @@ export default class MessageBox extends React.PureComponent {
message: PropTypes.object,
editing: PropTypes.bool,
typing: PropTypes.func,
clearInput: PropTypes.func,
layoutAnimation: PropTypes.func
clearInput: PropTypes.func
}

constructor(props) {
super(props);
this.state = {
text: '',
mentions: [],
showMentionsContainer: false,
showEmojiKeyboard: false,
recording: false
};
Expand Down Expand Up @@ -176,7 +173,7 @@ export default class MessageBox extends React.PureComponent {
if (response.didCancel) {
console.warn('User cancelled image picker');
} else if (response.error) {
console.warn('ImagePicker Error: ', response.error);
log('ImagePicker Error', response.error);
} else if (response.customButton) {
console.warn('User tapped custom button: ', response.customButton);
} else {
Expand Down Expand Up @@ -272,11 +269,13 @@ export default class MessageBox extends React.PureComponent {
RocketChat.spotlight(keyword, usernames, { users: true }),
new Promise((resolve, reject) => (this.oldPromise = reject))
]);
database.write(() => {
results.users.forEach((user) => {
database.create('users', user, true);
if (results.users && results.users.length) {
database.write(() => {
results.users.forEach((user) => {
database.create('users', user, true);
});
});
});
}
} catch (e) {
console.warn('spotlight canceled');
} finally {
Expand Down Expand Up @@ -318,7 +317,9 @@ export default class MessageBox extends React.PureComponent {
RocketChat.spotlight(keyword, [...rooms, ...this.roomsCache].map(r => r.name), { rooms: true }),
new Promise((resolve, reject) => (this.oldPromise = reject))
]);
this.roomsCache = [...this.roomsCache, ...results.rooms].filter(onlyUnique);
if (results.rooms && results.rooms.length) {
this.roomsCache = [...this.roomsCache, ...results.rooms].filter(onlyUnique);
}
this.setState({ mentions: [...rooms.slice(), ...results.rooms] });
} catch (e) {
console.warn('spotlight canceled');
Expand All @@ -338,7 +339,6 @@ export default class MessageBox extends React.PureComponent {

stopTrackingMention() {
this.setState({
showMentionsContainer: false,
mentions: [],
trackingType: ''
});
Expand All @@ -349,11 +349,7 @@ export default class MessageBox extends React.PureComponent {
}

identifyMentionKeyword(keyword, type) {
if (!this.state.showMentionsContainer) {
this.props.layoutAnimation();
}
this.setState({
showMentionsContainer: true,
showEmojiKeyboard: false,
trackingType: type
});
Expand Down Expand Up @@ -461,16 +457,22 @@ export default class MessageBox extends React.PureComponent {
</TouchableOpacity>
);
}
renderMentions = () => (
<FlatList
key='messagebox-container'
style={styles.mentionList}
data={this.state.mentions}
renderItem={({ item }) => this.renderMentionItem(item)}
keyExtractor={item => item._id || item}
keyboardShouldPersistTaps='always'
/>
);
renderMentions = () => {
const { mentions, trackingType } = this.state;
if (!trackingType) {
return null;
}
return (
<FlatList
key='messagebox-container'
style={styles.mentionList}
data={mentions}
renderItem={({ item }) => this.renderMentionItem(item)}
keyExtractor={item => item._id || item}
keyboardShouldPersistTaps='always'
/>
);
};

renderContent() {
if (this.state.recording) {
Expand Down
17 changes: 8 additions & 9 deletions app/containers/MessageBox/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export default StyleSheet.create({
flexDirection: 'row',
alignItems: 'center',
flexGrow: 0,
backgroundColor: '#fff'
backgroundColor: '#fff',
borderTopColor: '#ECECEC',
borderTopWidth: 1
},
textBoxInput: {
textAlignVertical: 'center',
Expand All @@ -40,19 +42,16 @@ export default StyleSheet.create({
flex: 0
},
mentionList: {
maxHeight: MENTION_HEIGHT * 4,
borderTopColor: '#ECECEC',
borderTopWidth: 1,
paddingHorizontal: 5,
backgroundColor: '#fff'
maxHeight: MENTION_HEIGHT * 4
},
mentionItem: {
height: MENTION_HEIGHT,
backgroundColor: '#F7F8FA',
borderBottomWidth: 1,
borderBottomColor: '#ECECEC',
borderTopWidth: 1,
borderTopColor: '#ECECEC',
flexDirection: 'row',
alignItems: 'center'
alignItems: 'center',
paddingHorizontal: 5
},
mentionItemCustomEmoji: {
margin: 8,
Expand Down
7 changes: 4 additions & 3 deletions app/containers/MessageErrorActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ActionSheet from 'react-native-actionsheet';
import { errorActionsHide } from '../actions/messages';
import RocketChat from '../lib/rocketchat';
import database from '../lib/realm';
import protectedFunction from '../lib/methods/helpers/protectedFunction';

@connect(
state => ({
Expand Down Expand Up @@ -38,14 +39,14 @@ export default class MessageErrorActions extends React.Component {
}
}

handleResend = () => RocketChat.resendMessage(this.props.actionMessage._id);
handleResend = protectedFunction(() => RocketChat.resendMessage(this.props.actionMessage._id));

handleDelete = () => {
handleDelete = protectedFunction(() => {
database.write(() => {
const msg = database.objects('messages').filtered('_id = $0', this.props.actionMessage._id);
database.delete(msg);
});
}
})

handleActionPress = (actionIndex) => {
switch (actionIndex) {
Expand Down
10 changes: 4 additions & 6 deletions app/containers/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ScrollView, Text, View, StyleSheet, FlatList, TouchableHighlight } from
import { connect } from 'react-redux';

import database from '../lib/realm';
import { setServer, gotoAddServer } from '../actions/server';
import { setServer } from '../actions/server';
import { logout } from '../actions/login';

const styles = StyleSheet.create({
Expand Down Expand Up @@ -40,16 +40,14 @@ const keyExtractor = item => item.id;
server: state.server.server
}), dispatch => ({
selectServer: server => dispatch(setServer(server)),
logout: () => dispatch(logout()),
gotoAddServer: () => dispatch(gotoAddServer())
logout: () => dispatch(logout())
}))
export default class Sidebar extends Component {
static propTypes = {
server: PropTypes.string.isRequired,
selectServer: PropTypes.func.isRequired,
navigation: PropTypes.object.isRequired,
logout: PropTypes.func.isRequired,
gotoAddServer: PropTypes.func.isRequired
logout: PropTypes.func.isRequired
}

constructor(props) {
Expand Down Expand Up @@ -120,7 +118,7 @@ export default class Sidebar extends Component {
</View>
</TouchableHighlight>
<TouchableHighlight
onPress={() => { this.props.gotoAddServer(); }}
onPress={() => { this.props.navigation.navigate({ key: 'AddServer', routeName: 'AddServer' }); }}
>
<View style={styles.serverItem}>
<Text>
Expand Down
Loading

0 comments on commit e69a6c0

Please sign in to comment.