From da4ecdc3b237fafeba17c09b0302d8e484ebf30f Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Mon, 20 Nov 2017 22:52:48 -0200 Subject: [PATCH 1/3] 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 2/3] 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 3/3] 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 {