diff --git a/__tests__/__snapshots__/RoomItem.js.snap b/__tests__/__snapshots__/RoomItem.js.snap
index 08dd1e5fc..23643947b 100644
--- a/__tests__/__snapshots__/RoomItem.js.snap
+++ b/__tests__/__snapshots__/RoomItem.js.snap
@@ -489,6 +489,7 @@ exports[`render unread +999 1`] = `
>
NA
+
NA
+
NA
+
TE
+
AA
+
BB
+
TE
+
@@ -229,6 +233,7 @@ exports[`Storyshots Channel Cell Direct Messages 1`] = `
>
RC
+
RC
+
RC
+
LC
+
LC
+
LC
+
LC
+
LC
+
W
+
WW
+
+
({
- baseUrl: state.settings.Site_Url
+ baseUrl: state.settings.Site_Url || state.server ? state.server.server : ''
}))
class Avatar extends React.PureComponent {
diff --git a/app/containers/MessageBox/index.js b/app/containers/MessageBox/index.js
index 6a9829fe3..cfea7b3a2 100644
--- a/app/containers/MessageBox/index.js
+++ b/app/containers/MessageBox/index.js
@@ -9,7 +9,7 @@ import RocketChat from '../../lib/rocketchat';
import { editRequest, editCancel, clearInput } from '../../actions/messages';
import styles from './style';
import MyIcon from '../icons';
-import realm from '../../lib/realm';
+import database from '../../lib/realm';
import Avatar from '../Avatar';
import AnimatedContainer from './AnimatedContainer';
@@ -23,7 +23,7 @@ const onlyUnique = function onlyUnique(value, index, self) {
room: state.room,
message: state.messages.message,
editing: state.messages.editing,
- baseUrl: state.settings.Site_Url
+ baseUrl: state.settings.Site_Url || state.server ? state.server.server : ''
}), dispatch => ({
editCancel: () => dispatch(editCancel()),
editRequest: message => dispatch(editRequest(message)),
@@ -200,7 +200,7 @@ export default class MessageBox extends React.Component {
}
async _getUsers(keyword) {
- this.users = realm.objects('users');
+ this.users = database.objects('users');
if (keyword) {
this.users = this.users.filtered('username CONTAINS[c] $0', keyword);
}
@@ -222,28 +222,24 @@ export default class MessageBox extends React.Component {
RocketChat.spotlight(keyword, usernames, { users: true }),
new Promise((resolve, reject) => (this.oldPromise = reject))
]);
- realm.write(() => {
+ database.write(() => {
results.users.forEach((user) => {
- user._server = {
- id: this.props.baseUrl,
- current: true
- };
- realm.create('users', user, true);
+ database.create('users', user, true);
});
});
} catch (e) {
console.log('spotlight canceled');
} finally {
delete this.oldPromise;
- this.users = realm.objects('users').filtered('username CONTAINS[c] $0', keyword);
+ this.users = database.objects('users').filtered('username CONTAINS[c] $0', keyword);
this.setState({ mentions: this.users.slice() });
}
}
async _getRooms(keyword = '') {
this.roomsCache = this.roomsCache || [];
- this.rooms = realm.objects('subscriptions')
- .filtered('_server.id = $0 AND t != $1', this.props.baseUrl, 'd');
+ this.rooms = database.objects('subscriptions')
+ .filtered('t != $0', 'd');
if (keyword) {
this.rooms = this.rooms.filtered('name CONTAINS[c] $0', keyword);
}
diff --git a/app/containers/MessageErrorActions.js b/app/containers/MessageErrorActions.js
index 88bb5487b..b96ca79aa 100644
--- a/app/containers/MessageErrorActions.js
+++ b/app/containers/MessageErrorActions.js
@@ -5,7 +5,7 @@ import ActionSheet from 'react-native-actionsheet';
import { errorActionsHide } from '../actions/messages';
import RocketChat from '../lib/rocketchat';
-import realm from '../lib/realm';
+import database from '../lib/realm';
@connect(
state => ({
@@ -41,9 +41,9 @@ export default class MessageActions extends React.Component {
handleResend = () => RocketChat.resendMessage(this.props.actionMessage._id);
handleDelete = () => {
- realm.write(() => {
- const msg = realm.objects('messages').filtered('_id = $0', this.props.actionMessage._id);
- realm.delete(msg);
+ database.write(() => {
+ const msg = database.objects('messages').filtered('_id = $0', this.props.actionMessage._id);
+ database.delete(msg);
});
}
diff --git a/app/containers/Routes.js b/app/containers/Routes.js
index b62f1443a..11dc773fb 100644
--- a/app/containers/Routes.js
+++ b/app/containers/Routes.js
@@ -31,13 +31,13 @@ export default class Routes extends React.Component {
}
componentDidMount() {
- if (!this.props.app.starting) {
+ if (this.props.app.ready) {
SplashScreen.hide();
}
}
componentWillReceiveProps(nextProps) {
- if (!nextProps.app.starting && this.props.app.starting !== nextProps.app.starting) {
+ if (nextProps.app.ready && this.props.app.ready !== nextProps.app.ready) {
SplashScreen.hide();
}
}
@@ -49,6 +49,10 @@ export default class Routes extends React.Component {
render() {
const { login } = this.props;
+ if (this.props.app.starting) {
+ return null;
+ }
+
if (!login.token || login.isRegistering) {
return ( this.navigator = nav} />);
}
diff --git a/app/containers/Sidebar.js b/app/containers/Sidebar.js
index 4d9f7eb75..e4f96875b 100644
--- a/app/containers/Sidebar.js
+++ b/app/containers/Sidebar.js
@@ -4,7 +4,7 @@ import { ScrollView, Text, View, StyleSheet, FlatList, TouchableHighlight } from
import { DrawerItems } from 'react-navigation';
import { connect } from 'react-redux';
-import realm from '../lib/realm';
+import database from '../lib/realm';
import { setServer, gotoAddServer } from '../actions/server';
import { logout } from '../actions/login';
@@ -54,12 +54,12 @@ export default class Sidebar extends Component {
}
componentWillMount() {
- realm.addListener('change', this.updateState);
+ realm.databases.serversDB.addListener('change', this.updateState);
this.setState(this.getState());
}
componentWillUnmount() {
- realm.removeListener('change', this.updateState);
+ realm.databases.serversDB.removeListener('change', this.updateState);
}
onItemPress = ({ route, focused }) => {
@@ -75,7 +75,7 @@ export default class Sidebar extends Component {
}
getState = () => ({
- servers: realm.objects('servers')
+ servers: realm.databases.serversDB.objects('servers')
})
updateState = () => {
diff --git a/app/lib/realm.js b/app/lib/realm.js
index eaec7ecc8..aace9e7fd 100644
--- a/app/lib/realm.js
+++ b/app/lib/realm.js
@@ -1,5 +1,8 @@
import Realm from 'realm';
+
// import { AsyncStorage } from 'react-native';
+// Realm.clearTestState();
+// AsyncStorage.clear();
const serversSchema = {
name: 'servers',
@@ -15,7 +18,6 @@ const settingsSchema = {
primaryKey: '_id',
properties: {
_id: 'string',
- _server: 'servers',
valueAsString: { type: 'string', optional: true },
valueAsBoolean: { type: 'bool', optional: true },
valueAsNumber: { type: 'int', optional: true },
@@ -36,7 +38,6 @@ const permissionsSchema = {
primaryKey: '_id',
properties: {
_id: 'string',
- _server: 'servers',
roles: { type: 'list', objectType: 'permissionsRoles' },
_updatedAt: { type: 'date', optional: true }
}
@@ -47,7 +48,6 @@ const roomsSchema = {
primaryKey: '_id',
properties: {
_id: 'string',
- _server: 'servers',
t: 'string',
_updatedAt: { type: 'date', optional: true }
}
@@ -65,7 +65,6 @@ const subscriptionSchema = {
primaryKey: '_id',
properties: {
_id: 'string',
- _server: 'servers',
f: { type: 'bool', optional: true },
t: 'string',
ts: { type: 'date', optional: true },
@@ -89,7 +88,6 @@ const usersSchema = {
primaryKey: '_id',
properties: {
_id: 'string',
- _server: 'servers',
username: 'string',
name: { type: 'string', optional: true }
}
@@ -157,7 +155,6 @@ const messagesSchema = {
primaryKey: '_id',
properties: {
_id: 'string',
- _server: 'servers',
msg: { type: 'string', optional: true },
t: { type: 'string', optional: true },
rid: 'string',
@@ -178,28 +175,56 @@ const messagesSchema = {
editedBy: 'messagesEditedBy'
}
};
-//
-// Realm.clearTestState();
-// AsyncStorage.clear();
-const realm = new Realm({
- schema: [
- settingsSchema,
- serversSchema,
- subscriptionSchema,
- subscriptionRolesSchema,
- messagesSchema,
- usersSchema,
- roomsSchema,
- attachment,
- attachmentFields,
- messagesEditedBySchema,
- permissionsSchema,
- permissionsRolesSchema,
- url
- ],
- deleteRealmIfMigrationNeeded: true
-});
-export default realm;
+const schema = [
+ settingsSchema,
+ subscriptionSchema,
+ subscriptionRolesSchema,
+ messagesSchema,
+ usersSchema,
+ roomsSchema,
+ attachment,
+ attachmentFields,
+ messagesEditedBySchema,
+ permissionsSchema,
+ permissionsRolesSchema,
+ url
+];
+class DB {
+ databases = {
+ serversDB: new Realm({
+ path: 'default.realm',
+ schema: [
+ serversSchema
+ ],
+ deleteRealmIfMigrationNeeded: true
+ })
+ };
+ deleteAll(...args) {
+ return this.database.write(() => this.database.deleteAll(...args));
+ }
+ write(...args) {
+ return this.database.write(...args);
+ }
+ create(...args) {
+ return this.database.create(...args);
+ }
+ objects(...args) {
+ return this.database.objects(...args);
+ }
+ get database() {
+ return this.databases.activeDB;
+ }
+
+ setActiveDB(database) {
+ const path = database.replace(/(^\w+:|^)\/\//, '');
+ return this.databases.activeDB = new Realm({
+ path: `${ path }.realm`,
+ schema,
+ deleteRealmIfMigrationNeeded: true
+ });
+ }
+}
+export default new DB();
// realm.write(() => {
// realm.create('servers', { id: 'https://open.rocket.chat', current: false }, true);
diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js
index 0759037fc..b8d7fe68f 100644
--- a/app/lib/rocketchat.js
+++ b/app/lib/rocketchat.js
@@ -6,7 +6,7 @@ import RNFetchBlob from 'react-native-fetch-blob';
import reduxStore from './createStore';
import settingsType from '../constants/settings';
import messagesStatus from '../constants/messagesStatus';
-import realm from './realm';
+import database from './realm';
import * as actions from '../actions';
import { someoneTyping } from '../actions/room';
import { setUser } from '../actions/login';
@@ -77,7 +77,9 @@ const RocketChat = {
this.ddp.on('disconnected', () => {
reduxStore.dispatch(disconnect());
});
- this.ddp.on('open', async() => resolve(reduxStore.dispatch(connectSuccess())));
+ this.ddp.on('open', async() => {
+ resolve(reduxStore.dispatch(connectSuccess()));
+ });
this.ddp.on('connected', () => {
RocketChat.getSettings();
RocketChat.getPermissions();
@@ -90,16 +92,15 @@ const RocketChat = {
this.ddp.on('connected', () => this.ddp.subscribe('activeUsers', null, false));
-
this.ddp.on('users', (ddpMessage) => {
if (ddpMessage.collection === 'users') {
return RocketChat._setUser(ddpMessage);
}
});
- this.ddp.on('stream-room-messages', ddpMessage => realm.write(() => {
+ this.ddp.on('stream-room-messages', ddpMessage => database.write(() => {
const message = this._buildMessage(ddpMessage.fields.args[0]);
- realm.create('messages', message, true);
+ database.create('messages', message, true);
}));
this.ddp.on('stream-notify-room', (ddpMessage) => {
@@ -117,13 +118,13 @@ const RocketChat = {
if (data.roles) {
data.roles = data.roles.map(role => ({ value: role }));
}
- realm.write(() => {
- realm.create('subscriptions', data, true);
+ database.write(() => {
+ database.create('subscriptions', data, true);
});
}
if (/rooms/.test(ev) && type === 'updated') {
- const sub = realm.objects('subscriptions').filtered('rid == $0', data._id)[0];
- realm.write(() => {
+ const sub = database.objects('subscriptions').filtered('rid == $0', data._id)[0];
+ database.write(() => {
sub.roomUpdatedAt = data._updatedAt;
});
}
@@ -208,20 +209,11 @@ const RocketChat = {
},
loadSubscriptions(cb) {
- const { server } = reduxStore.getState().server;
this.ddp.call('subscriptions/get').then((data) => {
if (data.length) {
- realm.write(() => {
+ database.write(() => {
data.forEach((subscription) => {
- // const subscription = {
- // _id: item._id
- // };
- // if (typeof item.value === 'string') {
- // subscription.value = item.value;
- // }
- subscription._server = { id: server };
- // write('subscriptions', subscription);
- realm.create('subscriptions', subscription, true);
+ database.create('subscriptions', subscription, true);
});
});
}
@@ -262,9 +254,7 @@ const RocketChat = {
});
},
_buildMessage(message) {
- const { server } = reduxStore.getState().server;
message.status = messagesStatus.SENT;
- message._server = { id: server };
message.attachments = message.attachments || [];
if (message.urls) {
message.urls = RocketChat._parseUrls(message.urls);
@@ -278,9 +268,9 @@ const RocketChat = {
return this.ddp.call('loadHistory', rid, end, 20).then((data) => {
if (data && data.messages.length) {
const messages = data.messages.map(message => this._buildMessage(message));
- realm.write(() => {
+ database.write(() => {
messages.forEach((message) => {
- realm.create('messages', message, true);
+ database.create('messages', message, true);
});
});
}
@@ -300,7 +290,6 @@ const RocketChat = {
getMessage(rid, msg = {}) {
const _id = Random.id();
- // console.log('reduxStore.getState().login.id ', reduxStore.getState().login);
const message = {
_id,
rid,
@@ -308,16 +297,14 @@ const RocketChat = {
ts: new Date(),
_updatedAt: new Date(),
status: messagesStatus.TEMP,
- _server: { id: reduxStore.getState().server.server },
u: {
_id: reduxStore.getState().login.user.id || '1',
username: reduxStore.getState().login.user.username
}
};
- realm.write(() => {
- realm.create('messages', message, true);
- // write('messages', message, true);
+ database.write(() => {
+ database.create('messages', message, true);
});
return message;
},
@@ -327,9 +314,9 @@ const RocketChat = {
const timeoutCall = new Promise(resolve => setTimeout(resolve, SERVER_TIMEOUT, 'timeout'));
const result = await Promise.race([sendMessageCall, timeoutCall]);
if (result === 'timeout') {
- realm.write(() => {
+ database.write(() => {
message.status = messagesStatus.ERROR;
- realm.create('messages', message, true);
+ database.create('messages', message, true);
});
}
},
@@ -338,10 +325,10 @@ const RocketChat = {
return RocketChat._sendMessageCall(tempMessage);
},
async resendMessage(messageId) {
- const message = await realm.objects('messages').filtered('_id = $0', messageId)[0];
- realm.write(() => {
+ const message = await database.objects('messages').filtered('_id = $0', messageId)[0];
+ database.write(() => {
message.status = messagesStatus.TEMP;
- realm.create('messages', message, true);
+ database.create('messages', message, true);
});
return RocketChat._sendMessageCall(message);
},
@@ -413,17 +400,16 @@ const RocketChat = {
} catch (e) {
return e;
} finally {
- realm.write(() => {
- const msg = realm.objects('messages').filtered('_id = $0', placeholder._id);
- realm.delete(msg);
+ database.write(() => {
+ const msg = database.objects('messages').filtered('_id = $0', placeholder._id);
+ database.delete(msg);
});
}
},
async getRooms() {
- const { server, login } = reduxStore.getState();
- let lastMessage = realm
+ const { login } = reduxStore.getState();
+ let lastMessage = database
.objects('subscriptions')
- .filtered('_server.id = $0', server.server)
.sorted('roomUpdatedAt', true)[0];
lastMessage = lastMessage && new Date(lastMessage.roomUpdatedAt);
let [subscriptions, rooms] = await Promise.all([call('subscriptions/get', lastMessage), call('rooms/get', lastMessage)]);
@@ -441,12 +427,11 @@ const RocketChat = {
if (subscription.roles) {
subscription.roles = subscription.roles.map(role => ({ value: role }));
}
- subscription._server = { id: server.server };
return subscription;
});
- realm.write(() => {
+ database.write(() => {
data.forEach(subscription =>
- realm.create('subscriptions', subscription, true));
+ database.create('subscriptions', subscription, true));
});
this.ddp.subscribe('stream-notify-user', `${ login.user.id }/subscriptions-changed`, false);
this.ddp.subscribe('stream-notify-user', `${ login.user.id }/rooms-changed`, false);
@@ -481,20 +466,20 @@ const RocketChat = {
logout({ server }) {
if (this.ddp) {
this.ddp.logout();
- // this.disconnect();
}
+ database.deleteAll();
AsyncStorage.removeItem(TOKEN_KEY);
AsyncStorage.removeItem(`${ TOKEN_KEY }-${ server }`);
},
async getSettings() {
- const temp = realm.objects('settings').sorted('_updatedAt', true)[0];
+ const temp = database.objects('settings').sorted('_updatedAt', true)[0];
const result = await (!temp ? call('public-settings/get') : call('public-settings/get', new Date(temp._updatedAt)));
const settings = temp ? result.update : result;
const filteredSettings = RocketChat._prepareSettings(RocketChat._filterSettings(settings));
- realm.write(() => {
- filteredSettings.forEach(setting => realm.create('settings', setting, true));
+ database.write(() => {
+ filteredSettings.forEach(setting => database.create('settings', setting, true));
});
- reduxStore.dispatch(actions.setAllSettings(RocketChat.parseSettings(filteredSettings)));
+ reduxStore.dispatch(actions.addSettings(RocketChat.parseSettings(filteredSettings)));
},
parseSettings: settings => settings.reduce((ret, item) => {
ret[item._id] = item[settingsType[item.type]] || item.valueAsString || item.valueAsNumber ||
@@ -509,12 +494,12 @@ const RocketChat = {
},
_filterSettings: settings => settings.filter(setting => settingsType[setting.type] && setting.value),
async getPermissions() {
- const temp = realm.objects('permissions').sorted('_updatedAt', true)[0];
+ const temp = database.objects('permissions').sorted('_updatedAt', true)[0];
const result = await (!temp ? call('permissions/get') : call('permissions/get', new Date(temp._updatedAt)));
let permissions = temp ? result.update : result;
permissions = RocketChat._preparePermissions(permissions);
- realm.write(() => {
- permissions.forEach(permission => realm.create('permissions', permission, true));
+ database.write(() => {
+ permissions.forEach(permission => database.create('permissions', permission, true));
});
reduxStore.dispatch(actions.setAllPermissions(RocketChat.parsePermissions(permissions)));
},
@@ -545,7 +530,7 @@ const RocketChat = {
return call('pinMessage', message);
},
getRoom(rid) {
- const result = realm.objects('subscriptions').filtered('rid = $0', rid);
+ const result = database.objects('subscriptions').filtered('rid = $0', rid);
if (result.length === 0) {
return Promise.reject(new Error('Room not found'));
}
diff --git a/app/reducers/permissions.js b/app/reducers/permissions.js
index e90a871e6..58d749907 100644
--- a/app/reducers/permissions.js
+++ b/app/reducers/permissions.js
@@ -13,5 +13,12 @@ export default function permissions(state = initialState.permissions, action) {
};
}
+ if (action.type === types.ADD_PERMISSIONS) {
+ return {
+ ...state,
+ ...action.payload
+ };
+ }
+
return state;
}
diff --git a/app/reducers/reducers.js b/app/reducers/reducers.js
index 059acd6fb..95291484f 100644
--- a/app/reducers/reducers.js
+++ b/app/reducers/reducers.js
@@ -3,11 +3,15 @@ import initialState from './initialState';
export default function settings(state = initialState.settings, action) {
if (action.type === types.SET_ALL_SETTINGS) {
+ return {
+ ...action.payload
+ };
+ }
+ if (action.type === types.ADD_SETTINGS) {
return {
...state,
...action.payload
};
}
-
return state;
}
diff --git a/app/reducers/server.js b/app/reducers/server.js
index 337c393e8..f704b22f6 100644
--- a/app/reducers/server.js
+++ b/app/reducers/server.js
@@ -5,7 +5,7 @@ const initialState = {
connected: false,
errorMessage: '',
failure: false,
- server: ''
+ server: {}
};
diff --git a/app/sagas/init.js b/app/sagas/init.js
index 5117c86ca..673a7626e 100644
--- a/app/sagas/init.js
+++ b/app/sagas/init.js
@@ -4,7 +4,7 @@ import * as actions from '../actions';
import { setServer } from '../actions/server';
import { restoreToken } from '../actions/login';
import { APP } from '../actions/actionsTypes';
-import realm from '../lib/realm';
+import database from '../lib/realm';
import RocketChat from '../lib/rocketchat';
const restore = function* restore() {
@@ -17,9 +17,9 @@ const restore = function* restore() {
const currentServer = yield call([AsyncStorage, 'getItem'], 'currentServer');
if (currentServer) {
yield put(setServer(currentServer));
- const settings = realm.objects('settings');
+ const settings = database.objects('settings');
yield put(actions.setAllSettings(RocketChat.parseSettings(settings.slice(0, settings.length))));
- const permissions = realm.objects('permissions');
+ const permissions = database.objects('permissions');
yield put(actions.setAllPermissions(RocketChat.parsePermissions(permissions.slice(0, permissions.length))));
}
yield put(actions.appReady({}));
diff --git a/app/sagas/selectServer.js b/app/sagas/selectServer.js
index 8e4d9cdf2..ff67573a4 100644
--- a/app/sagas/selectServer.js
+++ b/app/sagas/selectServer.js
@@ -2,10 +2,11 @@ import { put, call, takeLatest, race, take } from 'redux-saga/effects';
import { delay } from 'redux-saga';
import { AsyncStorage } from 'react-native';
import { SERVER } from '../actions/actionsTypes';
+import * as actions from '../actions';
import { connectRequest, disconnect, disconnect_by_user } from '../actions/connect';
import { changedServer, serverSuccess, serverFailure, serverRequest, setServer } from '../actions/server';
import RocketChat from '../lib/rocketchat';
-import realm from '../lib/realm';
+import database from '../lib/realm';
import * as NavigationService from '../containers/routes/NavigationService';
const validate = function* validate(server) {
@@ -13,10 +14,15 @@ const validate = function* validate(server) {
};
const selectServer = function* selectServer({ server }) {
+ yield database.setActiveDB(server);
yield put(disconnect_by_user());
yield put(disconnect());
yield put(changedServer(server));
yield call([AsyncStorage, 'setItem'], 'currentServer', server);
+ const settings = database.objects('settings');
+ yield put(actions.setAllSettings(RocketChat.parseSettings(settings.slice(0, settings.length))));
+ const permissions = database.objects('permissions');
+ yield put(actions.setAllPermissions(RocketChat.parsePermissions(permissions.slice(0, permissions.length))));
yield put(connectRequest(server));
};
@@ -39,8 +45,8 @@ const addServer = function* addServer({ server }) {
success: take(SERVER.SUCCESS)
});
if (!error) {
- realm.write(() => {
- realm.create('servers', { id: server, current: false }, true);
+ database.databases.serversDB.write(() => {
+ database.databases.serversDB.create('servers', { id: server, current: false }, true);
});
yield put(setServer(server));
}
diff --git a/app/views/ListServerView.js b/app/views/ListServerView.js
index 4dccbc482..cb3772010 100644
--- a/app/views/ListServerView.js
+++ b/app/views/ListServerView.js
@@ -6,7 +6,7 @@ import Zeroconf from 'react-native-zeroconf';
import { View, Text, SectionList, StyleSheet, SafeAreaView } from 'react-native';
import { connect } from 'react-redux';
import { setServer } from '../actions/server';
-import realm from '../lib/realm';
+import database from '../lib/realm';
import Fade from '../animations/fade';
const styles = StyleSheet.create({
@@ -83,8 +83,9 @@ export default class ListServerView extends React.Component {
this.state = {
sections: []
};
+ this.data = database.databases.serversDB.objects('servers');
this.redirected = false;
- realm.addListener('change', this.updateState);
+ this.data.addListener(this.updateState);
}
componentWillMount() {
@@ -109,7 +110,7 @@ export default class ListServerView extends React.Component {
componentWillUnmount() {
zeroconf.stop();
- realm.removeListener('change', this.updateState);
+ this.data.removeAllListeners();
zeroconf.removeListener('update', this.updateState);
}
@@ -120,7 +121,7 @@ export default class ListServerView extends React.Component {
getState = () => {
const sections = [{
title: 'My servers',
- data: realm.objects('servers')
+ data: this.data
}];
this.state.nearBy = zeroconf.getServices();
diff --git a/app/views/LoginView.js b/app/views/LoginView.js
index c3d8b4e71..f7432ee8a 100644
--- a/app/views/LoginView.js
+++ b/app/views/LoginView.js
@@ -1,15 +1,11 @@
import React from 'react';
-
import Spinner from 'react-native-loading-spinner-overlay';
-
import PropTypes from 'prop-types';
import { Keyboard, Text, TextInput, View, ScrollView, TouchableOpacity, SafeAreaView } from 'react-native';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
-// import * as actions from '../actions';
import * as loginActions from '../actions/login';
import KeyboardView from '../presentation/KeyboardView';
-// import { Keyboard } from 'react-native'
import styles from './Styles';
@@ -81,7 +77,6 @@ class LoginView extends React.Component {
return null;
}
- // {this.props.login.isFetching && LOGANDO}
render() {
return (
({
user: state.login.user,
- baseUrl: state.settings.Site_Url,
+ baseUrl: state.settings.Site_Url || state.server ? state.server.server : '',
activeUsers: state.activeUsers
}))
export default class extends React.Component {
diff --git a/app/views/RoomView/index.js b/app/views/RoomView/index.js
index ae1a14657..0e9e323b7 100644
--- a/app/views/RoomView/index.js
+++ b/app/views/RoomView/index.js
@@ -8,7 +8,7 @@ import { bindActionCreators } from 'redux';
import * as actions from '../../actions';
import { openRoom } from '../../actions/room';
import { editCancel } from '../../actions/messages';
-import realm from '../../lib/realm';
+import database from '../../lib/realm';
import RocketChat from '../../lib/rocketchat';
import Message from '../../containers/message';
import MessageActions from '../../containers/MessageActions';
@@ -25,8 +25,7 @@ const ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1._id !== r2._i
const typing = () => ;
@connect(
state => ({
- server: state.server.server,
- Site_Url: state.settings.Site_Url,
+ Site_Url: state.settings.Site_Url || state.server ? state.server.server : '',
Message_TimeFormat: state.settings.Message_TimeFormat,
loading: state.messages.isFetching,
user: state.login.user
@@ -44,7 +43,6 @@ export default class RoomView extends React.Component {
user: PropTypes.object.isRequired,
editCancel: PropTypes.func,
rid: PropTypes.string,
- server: PropTypes.string,
name: PropTypes.string,
Site_Url: PropTypes.string,
Message_TimeFormat: PropTypes.string,
@@ -64,11 +62,10 @@ export default class RoomView extends React.Component {
this.props.navigation.state.params.name ||
this.props.navigation.state.params.room.name;
- this.data = realm
- .objects('messages')
- .filtered('_server.id = $0 AND rid = $1', this.props.server, this.rid)
+ this.data = database.objects('messages')
+ .filtered('rid = $0', this.rid)
.sorted('ts', true);
- this.room = realm.objects('subscriptions').filtered('rid = $0', this.rid);
+ this.room = database.objects('subscriptions').filtered('rid = $0', this.rid);
this.state = {
dataSource: ds.cloneWithRows([]),
loaded: true,
diff --git a/app/views/RoomsListView/Header/index.js b/app/views/RoomsListView/Header/index.js
index a095bc58b..52b4d5064 100644
--- a/app/views/RoomsListView/Header/index.js
+++ b/app/views/RoomsListView/Header/index.js
@@ -16,7 +16,7 @@ import styles from './styles';
@connect(state => ({
user: state.login.user,
connected: state.meteor.connected,
- baseUrl: state.settings.Site_Url
+ baseUrl: state.settings.Site_Url || state.server ? state.server.server : ''
}), dispatch => ({
setSearch: searchText => dispatch(setSearch(searchText))
}))
diff --git a/app/views/RoomsListView/index.js b/app/views/RoomsListView/index.js
index 410524010..f22926723 100644
--- a/app/views/RoomsListView/index.js
+++ b/app/views/RoomsListView/index.js
@@ -7,7 +7,7 @@ import { Platform, View, TextInput, SafeAreaView } from 'react-native';
import { connect } from 'react-redux';
import * as actions from '../../actions';
import * as server from '../../actions/connect';
-import realm from '../../lib/realm';
+import database from '../../lib/realm';
import RocketChat from '../../lib/rocketchat';
import RoomItem from '../../presentation/RoomItem';
import Banner from '../../containers/Banner';
@@ -47,7 +47,7 @@ export default class RoomsListView extends React.Component {
dataSource: ds.cloneWithRows([]),
searchText: ''
};
- this.data = realm.objects('subscriptions').filtered('_server.id = $0', this.props.server).sorted('roomUpdatedAt', true);
+ this.data = database.objects('subscriptions').sorted('roomUpdatedAt', true);
}
componentDidMount() {
@@ -63,7 +63,7 @@ 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('roomUpdatedAt', true);
+ this.data = database.objects('subscriptions').sorted('roomUpdatedAt', true);
this.data.addListener(this.updateState);
} else if (this.props.searchText !== props.searchText) {
this.search(props.searchText);
@@ -151,7 +151,8 @@ export default class RoomsListView extends React.Component {
if (item.t === 'd') {
RocketChat.createDirectMessage(item.username)
.then(room => new Promise((resolve) => {
- const data = realm.objects('subscriptions').filtered('_server.id = $0 AND rid = $1', this.props.server, room.rid);
+ const data = database.objects('subscriptions')
+ .filtered('rid = $1', room.rid);
if (data.length) {
return resolve(data[0]);
diff --git a/app/views/SelectUsersView.js b/app/views/SelectUsersView.js
index 10d6045c2..667ecccf0 100644
--- a/app/views/SelectUsersView.js
+++ b/app/views/SelectUsersView.js
@@ -8,7 +8,7 @@ import { connect } from 'react-redux';
import * as actions from '../actions';
import * as server from '../actions/connect';
import * as createChannelActions from '../actions/createChannel';
-import realm from '../lib/realm';
+import database from '../lib/realm';
import RocketChat from '../lib/rocketchat';
import RoomItem from '../presentation/RoomItem';
import Banner from '../containers/Banner';
@@ -57,7 +57,6 @@ const styles = StyleSheet.create({
const ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1 !== r2 });
@connect(
state => ({
- server: state.server.server,
login: state.login,
Site_Url: state.settings.Site_Url,
users: state.createChannel.users
@@ -74,7 +73,6 @@ export default class RoomsListView extends React.Component {
static propTypes = {
navigation: PropTypes.object.isRequired,
Site_Url: PropTypes.string,
- server: PropTypes.string,
addUser: PropTypes.func.isRequired,
removeUser: PropTypes.func.isRequired,
resetCreateChannel: PropTypes.func.isRequired,
@@ -83,15 +81,12 @@ export default class RoomsListView extends React.Component {
constructor(props) {
super(props);
- this.data = realm
+ this.data = database
.objects('subscriptions')
- .filtered('_server.id = $0 AND t = $1', this.props.server, 'd');
+ .filtered('t = $0', 'd');
this.state = {
dataSource: ds.cloneWithRows(this.data),
- // searching: false,
- // searchDataSource: [],
searchText: ''
- // login: false
};
this.data.addListener(this.updateState);
}
@@ -105,7 +100,6 @@ export default class RoomsListView extends React.Component {
const searchText = text.trim();
this.setState({
searchText: text
- // searching: searchText !== ''
});
if (searchText === '') {
return this.setState({
diff --git a/package.json b/package.json
index 2b05ff739..6f4fedd38 100644
--- a/package.json
+++ b/package.json
@@ -21,7 +21,7 @@
]
},
"dependencies": {
- "@storybook/addons": "^3.2.18",
+ "@storybook/addons": "^3.3.1",
"@storybook/react-native": "^3.2.18",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-remove-console": "^6.8.5",