- logout
- changed default server to open.rocket.chat

* fixed server change bug
This commit is contained in:
Diego Mello 2017-11-07 18:25:04 -02:00 committed by Guilherme Gazzo
parent a2b4e39a05
commit 6d4e6f0c6c
6 changed files with 36 additions and 9 deletions

View File

@ -6,6 +6,7 @@ import { connect } from 'react-redux';
import realm from '../lib/realm';
import { setServer } from '../actions/server';
import { logout } from '../actions/login';
const styles = StyleSheet.create({
scrollView: {
@ -39,13 +40,15 @@ const styles = StyleSheet.create({
@connect(state => ({
server: state.server.server
}), dispatch => ({
selectServer: server => dispatch(setServer(server))
selectServer: server => dispatch(setServer(server)),
logout: () => dispatch(logout())
}))
export default class Sidebar extends Component {
static propTypes = {
server: PropTypes.string.isRequired,
selectServer: PropTypes.func.isRequired,
navigation: PropTypes.object.isRequired
navigation: PropTypes.object.isRequired,
logout: PropTypes.func.isRequired
}
componentWillMount() {
@ -100,13 +103,20 @@ export default class Sidebar extends Component {
{...this.props}
onItemPress={this.onItemPress}
/>
<Text style={styles.serverTitle}>SERVERS</Text>
<FlatList
data={this.state.servers}
renderItem={this.renderItem}
keyExtractor={item => item.id}
/>
<TouchableHighlight
onPress={() => { this.props.logout(); }}
>
<View style={styles.serverItem}>
<Text>
Logout
</Text>
</View>
</TouchableHighlight>
</View>
</ScrollView>
);

View File

@ -105,7 +105,7 @@ const realm = new Realm({
export default realm;
// realm.write(() => {
// realm.create('servers', { id: 'https://demo.rocket.chat', current: false }, true);
// realm.create('servers', { id: 'https://open.rocket.chat', current: false }, true);
// realm.create('servers', { id: 'http://localhost:3000', current: false }, true);
// realm.create('servers', { id: 'http://10.0.2.2:3000', current: false }, true);
// });

View File

@ -20,6 +20,7 @@ const call = (method, ...params) => new Promise((resolve, reject) => {
resolve(data);
});
});
const TOKEN_KEY = 'reactnativemeteor_usertoken';
const RocketChat = {
createChannel({ name, users, type }) {
@ -29,7 +30,6 @@ const RocketChat = {
},
async getUserToken() {
const TOKEN_KEY = 'reactnativemeteor_usertoken';
try {
return await AsyncStorage.getItem(TOKEN_KEY);
} catch (error) {
@ -408,8 +408,10 @@ const RocketChat = {
return data;
});
},
logout() {
return AsyncStorage.clear();
logout({ server }) {
Meteor.logout();
AsyncStorage.removeItem(TOKEN_KEY);
AsyncStorage.removeItem(`${ TOKEN_KEY }-${ server }`);
}
};

View File

@ -21,6 +21,7 @@ const getServer = state => state.server.server;
const loginCall = args => (args.resume ? RocketChat.login(args) : RocketChat.loginWithPassword(args));
const registerCall = args => RocketChat.register(args);
const setUsernameCall = args => RocketChat.setUsername(args);
const logoutCall = args => RocketChat.logout(args);
const getToken = function* getToken() {
const currentServer = yield select(getServer);
@ -132,6 +133,11 @@ const handleSetUsernameRequest = function* handleSetUsernameRequest({ credential
}
};
const handleLogout = function* handleLogout() {
const server = yield select(getServer);
yield call(logoutCall, { server });
};
const root = function* root() {
yield takeEvery(types.SERVER.CHANGED, handleLoginWhenServerChanges);
yield takeLatest(types.LOGIN.REQUEST, handleLoginRequest);
@ -142,5 +148,6 @@ const root = function* root() {
yield takeLatest(types.LOGIN.REGISTER_SUCCESS, handleRegisterSuccess);
yield takeLatest(types.LOGIN.SET_USERNAME_SUBMIT, handleSetUsernameSubmit);
yield takeLatest(types.LOGIN.SET_USERNAME_REQUEST, handleSetUsernameRequest);
yield takeLatest(types.LOGOUT, handleLogout);
};
export default root;

View File

@ -68,7 +68,7 @@ export default class NewServerView extends React.Component {
constructor(props) {
super(props);
this.state = {
defaultServer: 'https://demo.rocket.chat',
defaultServer: 'https://open.rocket.chat',
editable: true,
text: ''
};

View File

@ -94,6 +94,14 @@ 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.addListener(this.updateState);
}
}
componentWillUnmount() {
this.data.removeAllListeners();
}