From 597c7e165e16459f2a8e9b5d85f4a8783f8248c6 Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Sun, 19 Nov 2017 00:23:15 -0200 Subject: [PATCH 01/15] remove console.logs on production --- .babelrc | 7 ++++++- package.json | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.babelrc b/.babelrc index d0cf03df..ac8c2e03 100644 --- a/.babelrc +++ b/.babelrc @@ -1,4 +1,9 @@ { "presets": ["react-native"], - "plugins": ["transform-decorators-legacy"] + "plugins": ["transform-decorators-legacy"], + "env": { + "production": { + "plugins": ["transform-remove-console"] + } + } } diff --git a/package.json b/package.json index b65a312a..11a77c4e 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ }, "dependencies": { "babel-plugin-transform-decorators-legacy": "^1.3.4", + "babel-plugin-transform-remove-console": "^6.8.5", "babel-polyfill": "^6.26.0", "moment": "^2.19.2", "prop-types": "^15.6.0", From fe9a1ebeaa9e8a4fd516648bbbb20bd1bc615056 Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Sun, 19 Nov 2017 00:29:46 -0200 Subject: [PATCH 02/15] all room by param dont need get from realm again --- app/views/RoomView.js | 12 +++++------- app/views/RoomsListView.js | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/views/RoomView.js b/app/views/RoomView.js index acf6e53e..f60f0b8d 100644 --- a/app/views/RoomView.js +++ b/app/views/RoomView.js @@ -38,7 +38,7 @@ const styles = StyleSheet.create({ textAlign: 'center', color: '#a00' }, - header: { + loadingMore: { transform: [{ scaleY: -1 }], textAlign: 'center', padding: 5, @@ -86,7 +86,7 @@ export default class RoomView extends React.Component { .sorted('ts', true); this.state = { slow: false, - dataSource: [], + dataSource: ds.cloneWithRows(this.data), loaded: true, joined: typeof props.rid === 'undefined' }; @@ -124,14 +124,12 @@ export default class RoomView extends React.Component { this.state.end !== true ) { this.setState({ - // ...this.state, loadingMore: true }); const lastRowData = this.data[rowCount - 1]; RocketChat.loadMessagesForRoom(this.rid, lastRowData.ts, ({ end }) => { this.setState({ - // ...this.state, loadingMore: false, end }); @@ -186,11 +184,11 @@ export default class RoomView extends React.Component { renderHeader = () => { if (this.state.loadingMore) { - return Loading more messages...; + return Loading more messages...; } if (this.state.end) { - return Start of conversation; + return Start of conversation; } }; @@ -202,7 +200,7 @@ export default class RoomView extends React.Component { Date: Sun, 19 Nov 2017 00:30:09 -0200 Subject: [PATCH 03/15] loading on login --- app/views/LoginView.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/LoginView.js b/app/views/LoginView.js index 9af008fb..5928a448 100644 --- a/app/views/LoginView.js +++ b/app/views/LoginView.js @@ -1,6 +1,6 @@ import React from 'react'; -// import Spinner from 'react-native-loading-spinner-overlay'; +import Spinner from 'react-native-loading-spinner-overlay'; import PropTypes from 'prop-types'; import { Keyboard, Text, TextInput, View, TouchableOpacity, SafeAreaView } from 'react-native'; @@ -143,6 +143,7 @@ class LoginView extends React.Component { {this.props.login.failure && {this.props.login.error.reason}} + From 654967ccf999778892bf744d31bb16d0c367b62d Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Sun, 19 Nov 2017 00:31:34 -0200 Subject: [PATCH 04/15] refactor some call apis --- app/lib/rocketchat.js | 85 +++++-------------------------------------- 1 file changed, 10 insertions(+), 75 deletions(-) diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index 70d394b5..a26432b3 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -26,9 +26,7 @@ const RocketChat = { TOKEN_KEY, createChannel({ name, users, type }) { - return new Promise((resolve, reject) => { - Meteor.call(type ? 'createChannel' : 'createPrivateGroup', name, users, type, (err, res) => (err ? reject(err) : resolve(res))); - }); + return call(type ? 'createChannel' : 'createPrivateGroup', name, users, type); }, async getUserToken() { @@ -136,36 +134,15 @@ const RocketChat = { }, register({ credentials }) { - return new Promise((resolve, reject) => { - Meteor.call('registerUser', credentials, (err, userId) => { - if (err) { - reject(err); - } - resolve(userId); - }); - }); + return call('registerUser', credentials); }, setUsername({ credentials }) { - return new Promise((resolve, reject) => { - Meteor.call('setUsername', credentials.username, (err, result) => { - if (err) { - reject(err); - } - resolve(result); - }); - }); + return call('setUsername', credentials.username); }, forgotPassword(email) { - return new Promise((resolve, reject) => { - Meteor.call('sendForgotPasswordEmail', email, (err, result) => { - if (err) { - reject(err); - } - resolve(result); - }); - }); + return call('sendForgotPasswordEmail', email); }, loginWithPassword({ username, password, code }, callback) { @@ -317,38 +294,17 @@ const RocketChat = { }, spotlight(search, usernames) { - return new Promise((resolve, reject) => { - Meteor.call('spotlight', search, usernames, (error, result) => { - if (error) { - return reject(error); - } - return resolve(result); - }); - }); + return call('spotlight', search, usernames); }, createDirectMessage(username) { - return new Promise((resolve, reject) => { - Meteor.call('createDirectMessage', username, (error, result) => { - if (error) { - return reject(error); - } - return resolve(result); - }); - }); + return call('createDirectMessage', username); }, readMessages(rid) { return call('readMessages', rid); }, joinRoom(rid) { - return new Promise((resolve, reject) => { - Meteor.call('joinRoom', rid, (error, result) => { - if (error) { - return reject(error); - } - return resolve(result); - }); - }); + return call('joinRoom', rid); }, @@ -362,26 +318,12 @@ const RocketChat = { */ _ufsCreate(fileInfo) { // return call('ufsCreate', fileInfo); - return new Promise((resolve, reject) => { - Meteor.call('ufsCreate', fileInfo, (error, result) => { - if (error) { - return reject(error); - } - return resolve(result); - }); - }); + return call('ufsCreate', fileInfo); }, // ["ZTE8CKHJt7LATv7Me","fileSystem","e8E96b2819" _ufsComplete(fileId, store, token) { - return new Promise((resolve, reject) => { - Meteor.call('ufsComplete', fileId, store, token, (error, result) => { - if (error) { - return reject(error); - } - return resolve(result); - }); - }); + return call('ufsComplete', fileId, store, token); }, /* @@ -395,14 +337,7 @@ const RocketChat = { } */ _sendFileMessage(rid, data, msg = {}) { - return new Promise((resolve, reject) => { - Meteor.call('sendFileMessage', rid, null, data, msg, (error, result) => { - if (error) { - return reject(error); - } - return resolve(result); - }); - }); + return call('sendFileMessage', rid, null, data, msg); }, async sendFileMessage(rid, fileInfo, data) { const placeholder = RocketChat.getMessage(rid, 'Sending an image'); From cfd90b14f96c355a1a1323c4b239c037066c865e Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Sun, 19 Nov 2017 00:44:55 -0200 Subject: [PATCH 05/15] cache settings --- app/lib/rocketchat.js | 46 ++++++++++++++++++++----------------------- app/sagas/init.js | 4 ++++ 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index a26432b3..34d3cd9d 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -50,37 +50,17 @@ const RocketChat = { const url = `${ _url }/websocket`; Meteor.connect(url, { autoConnect: true, autoReconnect: true }); + Meteor.ddp.on('disconnected', () => { reduxStore.dispatch(disconnect()); }); + Meteor.ddp.on('connected', () => { reduxStore.dispatch(connectSuccess()); resolve(); }); - Meteor.ddp.on('connected', () => { - Meteor.call('public-settings/get', (err, data) => { - if (err) { - console.error(err); - } - - const settings = {}; - realm.write(() => { - data.forEach((item) => { - const setting = { - _id: item._id - }; - setting._server = { id: reduxStore.getState().server.server }; - if (settingsType[item.type]) { - setting[settingsType[item.type]] = item.value; - realm.create('settings', setting, true); - } - - settings[item._id] = item.value; - }); - }); - reduxStore.dispatch(actions.setAllSettings(settings)); - }); + Meteor.ddp.on('connected', async() => { Meteor.ddp.on('changed', (ddbMessage) => { if (ddbMessage.collection === 'stream-room-messages') { realm.write(() => { @@ -99,11 +79,12 @@ const RocketChat = { }); } }); + + RocketChat.getSettings(); }); }) .catch(e => console.error(e)); }, - login(params, callback) { return new Promise((resolve, reject) => { Meteor._startLoggingIn(); @@ -389,7 +370,22 @@ const RocketChat = { Meteor.disconnect(); AsyncStorage.removeItem(TOKEN_KEY); AsyncStorage.removeItem(`${ TOKEN_KEY }-${ server }`); - } + }, + async getSettings() { + const temp = realm.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._filterSettings(settings); + realm.write(() => { + filteredSettings.forEach(setting => realm.create('settings', setting, true)); + }); + reduxStore.dispatch(actions.setAllSettings(RocketChat.parseSettings(filteredSettings))); + }, + parseSettings: settings => settings.reduce((ret, item) => { + ret[item._id] = item[settingsType[item.type]] || item.valueAsString; + return ret; + }, {}), + _filterSettings: settings => settings.filter(setting => settingsType[setting.type]) }; export default RocketChat; diff --git a/app/sagas/init.js b/app/sagas/init.js index c86b5caa..66b5ea43 100644 --- a/app/sagas/init.js +++ b/app/sagas/init.js @@ -4,6 +4,8 @@ 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 RocketChat from '../lib/rocketchat'; const restore = function* restore() { try { @@ -16,6 +18,8 @@ const restore = function* restore() { const currentServer = yield call([AsyncStorage, 'getItem'], 'currentServer'); if (currentServer) { yield put(setServer(currentServer)); + const tmp = realm.objects('settings'); + yield put(actions.setAllSettings(RocketChat.parseSettings(tmp.slice(0, tmp.length)))); } yield put(actions.appReady({})); From bb5978444c1cb622a450753deae6afb8fe415845 Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Sun, 19 Nov 2017 01:41:58 -0200 Subject: [PATCH 06/15] ??? --- app/presentation/RoomItem.js | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/app/presentation/RoomItem.js b/app/presentation/RoomItem.js index fd294202..b69da666 100644 --- a/app/presentation/RoomItem.js +++ b/app/presentation/RoomItem.js @@ -120,24 +120,13 @@ export default class RoomItem extends React.PureComponent { render() { const { unread, name, _updatedAt } = this.props; - if (_updatedAt) { - return ( - - {this.icon} - - { name } - { moment(_updatedAt).format(this.props.dateFormat) } - - {this.renderNumber(unread)} - - ); - } return ( {this.icon} { name } + {_updatedAt ? { moment(_updatedAt).format(this.props.dateFormat) } : null} {this.renderNumber(unread)} From 441016330bc4e786425effb3f32cc42b2ce70165 Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Sun, 19 Nov 2017 01:42:35 -0200 Subject: [PATCH 07/15] avoid recalc colors and initials avatar --- app/presentation/RoomItem.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/presentation/RoomItem.js b/app/presentation/RoomItem.js index b69da666..a127a67c 100644 --- a/app/presentation/RoomItem.js +++ b/app/presentation/RoomItem.js @@ -87,13 +87,12 @@ export default class RoomItem extends React.PureComponent { return null; } - const { color } = avatarInitialsAndColor(name); - if (type === 'd') { return ( ); } + const { color } = avatarInitialsAndColor(name); return ( From d4d031e2e7ae5052e3f7e56b3da49360e5486b97 Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Sun, 19 Nov 2017 02:09:56 -0200 Subject: [PATCH 08/15] getrooms just get updated rooms --- app/lib/rocketchat.js | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index 34d3cd9d..a495b394 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -347,23 +347,31 @@ const RocketChat = { }); } }, - getRooms() { - return Promise.all([call('subscriptions/get'), call('rooms/get')]).then(([subscriptions, rooms]) => { - const { server, login } = reduxStore.getState(); - const data = subscriptions.map((subscription) => { - subscription._updatedAt = (rooms.find(room => room._id === subscription.rid) || {})._updatedAt; - subscription._server = { id: server.server }; - return subscription; - }); + async getRooms() { + const { server, login } = reduxStore.getState(); + let lastMessage = realm + .objects('subscriptions') + .filtered('_server.id = $0', server.server) + .sorted('_updatedAt', true)[0]; + lastMessage = lastMessage && new Date(lastMessage._updatedAt); + let [subscriptions, rooms] = await Promise.all([call('subscriptions/get', lastMessage), call('rooms/get', lastMessage)]); - realm.write(() => { - data.forEach((subscription) => { - realm.create('subscriptions', subscription, true); - }); - }); - Meteor.subscribe('stream-notify-user', `${ login.user.id }/subscriptions-changed`, false); - return data; + if (lastMessage) { + subscriptions = subscriptions.update; + rooms = rooms.update; + } + const data = subscriptions.map((subscription) => { + subscription._updatedAt = (rooms.find(room => room._id === subscription.rid) || subscription)._updatedAt; + subscription._server = { id: server.server }; + return subscription; }); + + realm.write(() => { + data.forEach(subscription => + realm.create('subscriptions', subscription, true)); + }); + Meteor.subscribe('stream-notify-user', `${ login.user.id }/subscriptions-changed`, false); + return data; }, logout({ server }) { Meteor.logout(); From 6436c0016220266bfdd808feef30714c783098e7 Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Sun, 19 Nov 2017 02:10:29 -0200 Subject: [PATCH 09/15] :x --- app/lib/realm.js | 4 +++- app/sagas/login.js | 2 +- app/views/RoomView.js | 5 ++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/lib/realm.js b/app/lib/realm.js index 75a21df1..adf877fe 100644 --- a/app/lib/realm.js +++ b/app/lib/realm.js @@ -18,7 +18,9 @@ const settingsSchema = { _server: 'servers', valueAsString: { type: 'string', optional: true }, valueAsBoolean: { type: 'bool', optional: true }, - valueAsNumber: { type: 'int', optional: true } + valueAsNumber: { type: 'int', optional: true }, + + _updatedAt: { type: 'date', optional: true } } }; diff --git a/app/sagas/login.js b/app/sagas/login.js index bd9b5287..bfa8cde2 100644 --- a/app/sagas/login.js +++ b/app/sagas/login.js @@ -145,7 +145,7 @@ const handleForgotPasswordRequest = function* handleForgotPasswordRequest({ emai }; const root = function* root() { - yield takeEvery(types.SERVER.CHANGED, handleLoginWhenServerChanges); + yield takeLatest(types.SERVER.CHANGED, handleLoginWhenServerChanges); yield takeLatest(types.LOGIN.REQUEST, handleLoginRequest); yield takeLatest(types.LOGIN.SUCCESS, saveToken); yield takeLatest(types.LOGIN.SUBMIT, handleLoginSubmit); diff --git a/app/views/RoomView.js b/app/views/RoomView.js index f60f0b8d..27a39ba9 100644 --- a/app/views/RoomView.js +++ b/app/views/RoomView.js @@ -86,7 +86,7 @@ export default class RoomView extends React.Component { .sorted('ts', true); this.state = { slow: false, - dataSource: ds.cloneWithRows(this.data), + dataSource: ds.cloneWithRows([]), loaded: true, joined: typeof props.rid === 'undefined' }; @@ -102,10 +102,9 @@ export default class RoomView extends React.Component { this.timer = setTimeout(() => this.setState({ slow: true }), 5000); this.props.getMessages(this.rid); this.data.addListener(this.updateState); - this.state.dataSource = ds.cloneWithRows(this.data); } componentDidMount() { - + this.updateState(); } componentDidUpdate() { return !this.props.loading && clearTimeout(this.timer); From 82435937164e1ae117033352c3e5b480cb88508f Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Mon, 20 Nov 2017 15:27:34 -0200 Subject: [PATCH 10/15] message on invalid password --- app/lib/rocketchat.js | 25 +++++-------------------- app/sagas/login.js | 6 +----- 2 files changed, 6 insertions(+), 25 deletions(-) diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index f86ed388..a4acb77d 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -92,6 +92,11 @@ const RocketChat = { Meteor._endLoggingIn(); Meteor._handleLoginCallback(err, result); if (err) { + if (/user not found/i.test(err.reason)) { + err.error = 1; + err.reason = 'User or Password incorrect'; + err.message = 'User or Password incorrect'; + } reject(err); } else { resolve(result); @@ -168,26 +173,6 @@ const RocketChat = { return this.login(params, callback); }, - // loadRooms(cb) { - // console.warn('a'); - // Meteor.call('rooms/get', (err, data) => { - // if (err) { - // console.error(err); - // } - // console.warn(`rooms ${ data.length }`); - // if (data.length) { - // realm.write(() => { - // data.forEach((room) => { - // room._server = { id: reduxStore.getState().server.server }; - // realm.create('rooms', room, true); - // }); - // }); - // } - - // return cb && cb(); - // }); - // }, - loadSubscriptions(cb) { Meteor.call('subscriptions/get', (err, data) => { if (err) { diff --git a/app/sagas/login.js b/app/sagas/login.js index 36d1383c..f3d83d28 100644 --- a/app/sagas/login.js +++ b/app/sagas/login.js @@ -83,11 +83,7 @@ const handleLoginRequest = function* handleLoginRequest({ credentials }) { yield put(loginSuccess(user)); } catch (err) { - if (err.error === 403) { - yield put(logout()); - } else { - yield put(loginFailure(err)); - } + yield put(loginFailure(err)); } }; From 03ac9608093f4d1a960cd6ebe0982f20b09b7eaf Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Mon, 20 Nov 2017 15:29:56 -0200 Subject: [PATCH 11/15] fix babelrc indentation --- .babelrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.babelrc b/.babelrc index ac8c2e03..34739bdc 100644 --- a/.babelrc +++ b/.babelrc @@ -1,7 +1,7 @@ { "presets": ["react-native"], "plugins": ["transform-decorators-legacy"], - "env": { + "env": { "production": { "plugins": ["transform-remove-console"] } From 80c019a973193b80cea446168a77db124909663e Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Mon, 20 Nov 2017 15:33:23 -0200 Subject: [PATCH 12/15] unused var --- app/sagas/login.js | 1 - 1 file changed, 1 deletion(-) diff --git a/app/sagas/login.js b/app/sagas/login.js index f3d83d28..0838aea0 100644 --- a/app/sagas/login.js +++ b/app/sagas/login.js @@ -9,7 +9,6 @@ import { loginSuccess, loginFailure, setToken, - logout, registerSuccess, setUsernameRequest, setUsernameSuccess, From da4ecdc3b237fafeba17c09b0302d8e484ebf30f Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Mon, 20 Nov 2017 22:52:48 -0200 Subject: [PATCH 13/15] amazing room subscriptions --- app/lib/rocketchat.js | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index a4acb77d..af32cbbf 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -62,24 +62,44 @@ const RocketChat = { Meteor.ddp.on('connected', async() => { Meteor.ddp.on('changed', (ddbMessage) => { + const server = { id: reduxStore.getState().server.server }; if (ddbMessage.collection === 'stream-room-messages') { realm.write(() => { const message = ddbMessage.fields.args[0]; message.temp = false; - message._server = { id: reduxStore.getState().server.server }; + message._server = server; realm.create('messages', message, true); }); } if (ddbMessage.collection === 'stream-notify-user') { - realm.write(() => { - const data = ddbMessage.fields.args[1]; - data._server = { id: reduxStore.getState().server.server }; - realm.create('subscriptions', data, true); - }); + const [type, data] = ddbMessage.fields.args; + const [, ev] = ddbMessage.fields.eventName.split('/'); + if (/subscriptions/.test(ev)) { + switch (type) { + case 'inserted': + data._server = server; + realm.write(() => { + realm.create('subscriptions', data, true); + }); + break; + case 'updated': + delete data._updatedAt; + realm.write(() => { + realm.create('subscriptions', data, true); + }); + break; + default: + } + } + if (/rooms/.test(ev) && type === 'updated') { + const sub = realm.objects('subscriptions').filtered('rid == $0', data._id)[0]; + realm.write(() => { + sub._updatedAt = data._updatedAt; + }); + } } }); - RocketChat.getSettings(); }); }) @@ -371,6 +391,7 @@ const RocketChat = { realm.create('subscriptions', subscription, true)); }); Meteor.subscribe('stream-notify-user', `${ login.user.id }/subscriptions-changed`, false); + Meteor.subscribe('stream-notify-user', `${ login.user.id }/rooms-changed`, false); return data; }, logout({ server }) { From 318cf7b97070b12c4a988e8c921b8832da8649a2 Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Mon, 20 Nov 2017 22:58:15 -0200 Subject: [PATCH 14/15] attachments null --- app/lib/rocketchat.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index af32cbbf..72a25d34 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -68,6 +68,7 @@ const RocketChat = { const message = ddbMessage.fields.args[0]; message.temp = false; message._server = server; + message.attachments = message.attachments || []; realm.create('messages', message, true); }); } @@ -247,6 +248,7 @@ const RocketChat = { data.messages.forEach((message) => { message.temp = false; message._server = { id: reduxStore.getState().server.server }; + message.attachments = message.attachments || []; // write('messages', message); realm.create('messages', message, true); }); From 541d9783ee9b00fa23410f14181f642a1084942b Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Mon, 20 Nov 2017 23:02:00 -0200 Subject: [PATCH 15/15] Message list scroll based on window size --- app/lib/rocketchat.js | 6 +++++- app/views/RoomView.js | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index 72a25d34..fdac2c1e 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -383,7 +383,11 @@ const RocketChat = { rooms = rooms.update; } const data = subscriptions.map((subscription) => { - subscription._updatedAt = (rooms.find(room => room._id === subscription.rid) || subscription)._updatedAt; + const room = rooms.find(({ _id }) => _id === subscription.rid); + delete subscription._updatedAt; + if (room) { + subscription._updatedAt = room._updatedAt; + } subscription._server = { id: server.server }; return subscription; }); diff --git a/app/views/RoomView.js b/app/views/RoomView.js index 27a39ba9..32db7582 100644 --- a/app/views/RoomView.js +++ b/app/views/RoomView.js @@ -1,6 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { Text, View, StyleSheet, Button, SafeAreaView } from 'react-native'; +import { Text, View, StyleSheet, Button, SafeAreaView, Dimensions } from 'react-native'; import { ListView } from 'realm/react-native'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; @@ -192,6 +192,7 @@ export default class RoomView extends React.Component { }; render() { + const { height } = Dimensions.get('window'); return ( {this.renderBanner()} @@ -199,7 +200,7 @@ export default class RoomView extends React.Component {