diff --git a/app/actions/index.js b/app/actions/index.js
index f7c6888f..97271809 100644
--- a/app/actions/index.js
+++ b/app/actions/index.js
@@ -7,9 +7,13 @@ export function setCurrentServer(server) {
};
}
-export function preventESLintError() {
- return {};
+export function setAllSettings(settings) {
+ return {
+ type: types.SET_ALL_SETTINGS,
+ payload: settings
+ };
}
+
// // GENRES
// export function retrieveMoviesGenresSuccess(res) {
// return {
diff --git a/app/constants/settings.js b/app/constants/settings.js
new file mode 100644
index 00000000..8f8a714e
--- /dev/null
+++ b/app/constants/settings.js
@@ -0,0 +1,15 @@
+export default {
+ boolean: 'valueAsBoolean',
+ int: 'valueAsNumber',
+ string: 'valueAsString',
+ select: 'valueAsString',
+ code: 'valueAsString',
+ relativeUrl: 'valueAsString',
+ language: 'valueAsString',
+ action: 'valueAsString',
+ password: 'valueAsString',
+ // asset: ' Object',
+ color: 'valueAsString',
+ font: 'valueAsString',
+ roomPick: 'valueAsString'
+};
diff --git a/app/constants/types.js b/app/constants/types.js
index 301c702d..97c8b2e7 100644
--- a/app/constants/types.js
+++ b/app/constants/types.js
@@ -7,4 +7,4 @@
// export const RETRIEVE_MOVIES_SEARCH_RESULT_SUCCESS = 'RETRIEVE_MOVIES_SEARCH_RESULT_SUCCESS';
export const SET_CURRENT_SERVER = 'SET_CURRENT_SERVER';
-export const ESLINT_FIX = 'ESLINT_FIX';
+export const SET_ALL_SETTINGS = 'SET_ALL_SETTINGS';
diff --git a/app/lib/createStore.js b/app/lib/createStore.js
index 6571eab3..f7342ff1 100644
--- a/app/lib/createStore.js
+++ b/app/lib/createStore.js
@@ -13,10 +13,8 @@ if (__DEV__) {
middleware = [...middleware];
}
-export default function configureStore(initialState) {
- return createStore(
- rootReducer,
- initialState,
- applyMiddleware(...middleware)
- );
-}
+export default createStore(
+ rootReducer,
+ undefined,
+ applyMiddleware(...middleware)
+);
diff --git a/app/lib/realm.js b/app/lib/realm.js
index 64c057fe..c0f9a872 100644
--- a/app/lib/realm.js
+++ b/app/lib/realm.js
@@ -15,7 +15,9 @@ const settingsSchema = {
properties: {
_id: 'string',
_server: 'servers',
- value: { type: 'string', optional: true }
+ valueAsString: { type: 'string', optional: true },
+ valueAsBoolean: { type: 'bool', optional: true },
+ valueAsNumber: { type: 'int', optional: true }
}
};
@@ -70,13 +72,14 @@ const messagesSchema = {
}
};
+// Realm.clearTestState();
+
const realm = new Realm({
schema: [settingsSchema, serversSchema, subscriptionSchema, messagesSchema, usersSchema]
});
export default realm;
-// Realm.clearTestState();
// realm.write(() => {
// realm.create('servers', { id: 'https://demo.rocket.chat', current: false }, true);
// realm.create('servers', { id: 'http://localhost:3000', current: false }, true);
diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js
index 09992994..d67abd5a 100644
--- a/app/lib/rocketchat.js
+++ b/app/lib/rocketchat.js
@@ -1,9 +1,13 @@
import Meteor from 'react-native-meteor';
import Random from 'react-native-meteor/lib/Random';
import { AsyncStorage } from 'react-native';
+import { hashPassword } from 'react-native-meteor/lib/utils';
+import reduxStore from '../lib/createStore';
+import settingsType from '../constants/settings';
import realm from './realm';
import debounce from '../utils/debounce';
+import * as actions from '../actions';
export { Accounts } from 'react-native-meteor';
@@ -76,19 +80,22 @@ const RocketChat = {
console.error(err);
}
+ const settings = {};
realm.write(() => {
data.forEach((item) => {
const setting = {
_id: item._id
};
setting._server = { id: RocketChat.currentServer };
- if (typeof item.value === 'string') {
- setting.value = item.value;
+ if (settingsType[item.type]) {
+ setting[settingsType[item.type]] = item.value;
+ realm.create('settings', setting, true);
}
- // write('settings', setting);
- realm.create('settings', setting, true);
+
+ settings[item._id] = item.value;
});
});
+ reduxStore.dispatch(actions.setAllSettings(settings));
if (cb) {
cb();
@@ -138,8 +145,53 @@ const RocketChat = {
});
},
- loginWithPassword(selector, password, cb) {
- Meteor.loginWithPassword(selector, password, () => cb && cb());
+ login(params, callback) {
+ Meteor._startLoggingIn();
+ Meteor.call('login', params, (err, result) => {
+ Meteor._endLoggingIn();
+
+ Meteor._handleLoginCallback(err, result);
+
+ if (typeof callback === 'function') {
+ callback(err);
+ }
+ });
+ },
+
+ loginWithPassword(username, password, callback) {
+ let params = {};
+ const state = reduxStore.getState();
+
+ if (state.settings.LDAP_Enable) {
+ params = {
+ ldap: true,
+ username,
+ ldapPass: password,
+ ldapOptions: {}
+ };
+ } else if (state.settings.CROWD_Enable) {
+ params = {
+ crowd: true,
+ username,
+ crowdPassword: password
+ };
+ } else {
+ params = {
+ password: hashPassword(password),
+ user: {
+ username
+ }
+ };
+
+ if (typeof username === 'string') {
+ if (username.indexOf('@') !== -1) {
+ params.user = { email: username };
+ }
+ }
+ }
+
+ console.log({ params });
+ this.login(params, callback);
},
loadSubscriptions(cb) {
@@ -333,6 +385,10 @@ const RocketChat = {
export default RocketChat;
+if (RocketChat.currentServer) {
+ reduxStore.dispatch(actions.setCurrentServer(RocketChat.currentServer));
+}
+
Meteor.Accounts.onLogin(() => {
Promise.all([call('subscriptions/get'), call('rooms/get')]).then(([subscriptions, rooms]) => {
subscriptions = subscriptions.sort((s1, s2) => (s1.rid > s2.rid ? 1 : -1));
diff --git a/app/navigation.js b/app/navigation.js
index 87d3cc61..870f4a27 100644
--- a/app/navigation.js
+++ b/app/navigation.js
@@ -7,9 +7,7 @@ import ListServerView from './views/serverList';
import RoomsListView from './views/roomsList';
import RoomView from './views/room';
import CreateChannel from './views/CreateChannel';
-import configureStore from './lib/createStore';
-
-const store = configureStore();
+import store from './lib/createStore';
Navigation.registerComponent('Rooms', () => RoomsListView, store, Provider);
Navigation.registerComponent('Room', () => RoomView, store, Provider);
diff --git a/app/reducers/initialState.js b/app/reducers/initialState.js
index 94083a9a..ecf309b5 100644
--- a/app/reducers/initialState.js
+++ b/app/reducers/initialState.js
@@ -1,6 +1,5 @@
-import RocketChat from '../lib/rocketchat';
-
export default {
- server: RocketChat.currentServer,
- login: {}
+ server: null,
+ login: {},
+ settings: {}
};
diff --git a/app/reducers/reducers.js b/app/reducers/reducers.js
index f70ea40d..3cd0c5ac 100644
--- a/app/reducers/reducers.js
+++ b/app/reducers/reducers.js
@@ -2,51 +2,21 @@ import RocketChat from '../lib/rocketchat';
import * as types from '../constants/types';
import initialState from './initialState';
-export default function(state = initialState, action) {
- switch (action.type) {
- case types.SET_CURRENT_SERVER:
- RocketChat.currentServer = action.payload;
- return {
- ...state,
- server: action.payload
- };
-
- // case types.RETRIEVE_POPULAR_MOVIES_SUCCESS:
- // return {
- // ...state,
- // popularMovies: action.popularMovies
- // };
-
- // case types.RETRIEVE_NOWPLAYING_MOVIES_SUCCESS:
- // return {
- // ...state,
- // nowPlayingMovies: action.nowPlayingMovies
- // };
-
- // case types.RETRIEVE_MOVIES_GENRES_SUCCESS:
- // return {
- // ...state,
- // genres: action.moviesGenres
- // };
-
- // case types.RETRIEVE_MOVIES_LIST_SUCCESS:
- // return {
- // ...state,
- // list: action.list
- // };
-
- // case types.RETRIEVE_MOVIE_DETAILS_SUCCESS:
- // return {
- // ...state,
- // details: action.details
- // };
-
- // case types.RETRIEVE_MOVIES_SEARCH_RESULT_SUCCESS:
- // return {
- // ...state,
- // searchResults: action.searchResults
- // };
- default:
- return state;
+export function server(state = initialState.server, action) {
+ if (action.type === types.SET_CURRENT_SERVER) {
+ RocketChat.currentServer = action.payload;
+ return action.payload;
}
+
+ return state;
+}
+
+export function settings(state = initialState.settings, action) {
+ if (action.type === types.SET_ALL_SETTINGS) {
+ return {
+ ...action.payload
+ };
+ }
+
+ return state;
}
diff --git a/app/reducers/rootReducer.js b/app/reducers/rootReducer.js
index f240a6a9..49ef2cfd 100644
--- a/app/reducers/rootReducer.js
+++ b/app/reducers/rootReducer.js
@@ -1,9 +1,8 @@
-// import { combineReducers } from 'redux';
-import reducers from './reducers';
+import { combineReducers } from 'redux';
+import * as reducers from './reducers';
-// const rootReducer = combineReducers({
-// reducers
-// });
+const rootReducer = combineReducers({
+ ...reducers
+});
-// export default rootReducer;
-export default reducers;
+export default rootReducer;
diff --git a/app/views/CreateChannel.js b/app/views/CreateChannel.js
index bcd51cf9..8d9d12eb 100644
--- a/app/views/CreateChannel.js
+++ b/app/views/CreateChannel.js
@@ -1,7 +1,7 @@
import ActionButton from 'react-native-action-button';
import Icon from 'react-native-vector-icons/Ionicons';
import React from 'react';
-import PropTypes from 'prop-types';
+// import PropTypes from 'prop-types';
import { TextInput, StyleSheet, View, Text, Switch } from 'react-native';
import RocketChat from '../lib/rocketchat';
@@ -45,9 +45,9 @@ const styles = StyleSheet.create({
});
const mainIcon = ;
export default class CreateChannelView extends React.Component {
- static propTypes = {
- navigation: PropTypes.object.isRequired
- }
+ // static propTypes = {
+ // navigation: PropTypes.object.isRequired
+ // }
static navigationOptions = () => ({
title: 'Create Channel'
diff --git a/app/views/roomsList.js b/app/views/roomsList.js
index 8148d8d3..75b95f7d 100644
--- a/app/views/roomsList.js
+++ b/app/views/roomsList.js
@@ -100,23 +100,22 @@ class RoomsListItem extends React.PureComponent {
}
@connect(state => ({
- server: state.server
+ server: state.server,
+ Site_Url: state.settings.Site_Url
}), dispatch => ({
actions: bindActionCreators(actions, dispatch)
}))
export default class RoomsListView extends React.Component {
static propTypes = {
navigator: PropTypes.object.isRequired,
- server: PropTypes.string
+ server: PropTypes.string,
+ Site_Url: PropTypes.string
}
constructor(props) {
super(props);
+
this.data = realm.objects('subscriptions').filtered('_server.id = $0', this.props.server);
- const siteUrl = realm.objectForPrimaryKey('settings', 'Site_Url');
- if (siteUrl) {
- this.url = siteUrl.value;
- }
this.state = {
dataSource: ds.cloneWithRows([]),
searching: false,
@@ -249,7 +248,6 @@ export default class RoomsListView extends React.Component {
getSubscriptions = () => this.data.sorted('_updatedAt', true)
updateState = debounce(() => {
- this.url = realm.objectForPrimaryKey('settings', 'Site_Url').value;
this.setState({
dataSource: ds.cloneWithRows(this.data.filtered('_server.id = $0', this.props.server).sorted('ls', true))
});
@@ -319,7 +317,7 @@ export default class RoomsListView extends React.Component {
this._onPressItem(item._id, item)}
- baseUrl={this.url}
+ baseUrl={this.props.Site_Url}
/>
);