From b7be727d0e8d105b2b1824cb06c8a881074dcb16 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Thu, 10 Aug 2017 13:16:32 -0300 Subject: [PATCH] Add room search (#16) --- .expo/packager-info.json | 5 ++ .expo/settings.json | 9 +++ app/components/RoomItem.js | 2 +- app/lib/rocketchat.js | 33 +++++++++ app/views/room.js | 56 +++++++++++---- app/views/roomsList.js | 139 ++++++++++++++++++++++++++++++------- 6 files changed, 202 insertions(+), 42 deletions(-) create mode 100644 .expo/packager-info.json create mode 100644 .expo/settings.json diff --git a/.expo/packager-info.json b/.expo/packager-info.json new file mode 100644 index 000000000..24e8ec399 --- /dev/null +++ b/.expo/packager-info.json @@ -0,0 +1,5 @@ +{ + "expoServerPort": null, + "packagerPort": null, + "packagerPid": null +} \ No newline at end of file diff --git a/.expo/settings.json b/.expo/settings.json new file mode 100644 index 000000000..5eee78b49 --- /dev/null +++ b/.expo/settings.json @@ -0,0 +1,9 @@ +{ + "hostType": "tunnel", + "lanType": "ip", + "dev": true, + "strict": false, + "minify": false, + "urlType": "exp", + "urlRandomness": null +} \ No newline at end of file diff --git a/app/components/RoomItem.js b/app/components/RoomItem.js index 89ed5c1ec..7a11c42d1 100644 --- a/app/components/RoomItem.js +++ b/app/components/RoomItem.js @@ -34,7 +34,7 @@ export default class RoomItem extends React.PureComponent { } _onPress = () => { - this.props.onPressItem(this.props.id); + this.props.onPressItem(this.props.id, this.props.item); }; renderNumber = (item) => { diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index 3ed431b5f..aa28d875b 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -147,6 +147,39 @@ const RocketChat = { return resolve(result); }); }); + }, + + spotlight(search, usernames) { + return new Promise((resolve, reject) => { + Meteor.call('spotlight', search, usernames, (error, result) => { + if (error) { + return reject(error); + } + return resolve(result); + }); + }); + }, + + createDirectMessage(username) { + return new Promise((resolve, reject) => { + Meteor.call('createDirectMessage', username, (error, result) => { + if (error) { + return reject(error); + } + return resolve(result); + }); + }); + }, + + joinRoom(rid) { + return new Promise((resolve, reject) => { + Meteor.call('joinRoom', rid, (error, result) => { + if (error) { + return reject(error); + } + return resolve(result); + }); + }); } }; diff --git a/app/views/room.js b/app/views/room.js index d8d52f527..69619f2a4 100644 --- a/app/views/room.js +++ b/app/views/room.js @@ -1,6 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { Text, View, FlatList, StyleSheet } from 'react-native'; +import { Text, View, FlatList, StyleSheet, Button } from 'react-native'; import realm from '../lib/realm'; import RocketChat from '../lib/rocketchat'; @@ -36,17 +36,18 @@ export default class RoomView extends React.Component { } static navigationOptions = ({ navigation }) => ({ - title: realm.objectForPrimaryKey('subscriptions', navigation.state.params.sid).name + title: navigation.state.params.name || realm.objectForPrimaryKey('subscriptions', navigation.state.params.sid).name }); constructor(props) { super(props); - this.rid = realm.objectForPrimaryKey('subscriptions', props.navigation.state.params.sid).rid; + this.rid = props.navigation.state.params.rid || realm.objectForPrimaryKey('subscriptions', props.navigation.state.params.sid).rid; // this.rid = 'GENERAL'; this.state = { dataSource: this.getMessages(), - loaded: false + loaded: false, + joined: typeof props.navigation.state.params.rid === 'undefined' }; this.url = realm.objectForPrimaryKey('settings', 'Site_Url').value; @@ -77,13 +78,14 @@ export default class RoomView extends React.Component { sendMessage = message => RocketChat.sendMessage(this.rid, message); - renderItem = ({ item }) => ( - - ); + joinRoom = () => { + RocketChat.joinRoom(this.props.navigation.state.params.rid) + .then(() => { + this.setState({ + joined: true + }); + }); + }; renderBanner = () => { if (this.state.loaded === false) { @@ -93,6 +95,34 @@ export default class RoomView extends React.Component { ); } + }; + + renderItem = ({ item }) => ( + + ); + + renderSeparator = () => ( + + ); + + renderFooter = () => { + if (!this.state.joined) { + return ( + + You are in preview mode. +