diff --git a/app/containers/Sidebar.js b/app/containers/Sidebar.js
index 6e6ed7a1..b9a289e9 100644
--- a/app/containers/Sidebar.js
+++ b/app/containers/Sidebar.js
@@ -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}
/>
-
- SERVERS
item.id}
/>
+ { this.props.logout(); }}
+ >
+
+
+ Logout
+
+
+
);
diff --git a/app/lib/realm.js b/app/lib/realm.js
index 5ae58502..0a71d3e7 100644
--- a/app/lib/realm.js
+++ b/app/lib/realm.js
@@ -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);
// });
diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js
index 352eb00b..b9757d09 100644
--- a/app/lib/rocketchat.js
+++ b/app/lib/rocketchat.js
@@ -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 }`);
}
};
diff --git a/app/sagas/login.js b/app/sagas/login.js
index a8608e79..90bee464 100644
--- a/app/sagas/login.js
+++ b/app/sagas/login.js
@@ -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;
diff --git a/app/views/NewServerView.js b/app/views/NewServerView.js
index f022bc4e..c79b8cd4 100644
--- a/app/views/NewServerView.js
+++ b/app/views/NewServerView.js
@@ -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: ''
};
diff --git a/app/views/RoomsListView.js b/app/views/RoomsListView.js
index 8a8791ab..3d5d8a40 100644
--- a/app/views/RoomsListView.js
+++ b/app/views/RoomsListView.js
@@ -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();
}