From 329669f18f398a2779558bff51bbd49b114011b8 Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Wed, 8 Nov 2017 18:23:46 -0200 Subject: [PATCH] Fix room ordering --- app/lib/realm.js | 15 ++++++++++++--- app/lib/rocketchat.js | 27 ++++++++++++++++++++++----- app/presentation/RoomItem.js | 29 +++++++++++++++++++++++------ app/views/RoomsListView.js | 4 ++++ package-lock.json | 10 ++++++++++ 5 files changed, 71 insertions(+), 14 deletions(-) diff --git a/app/lib/realm.js b/app/lib/realm.js index 0a71d3e76..75a21df17 100644 --- a/app/lib/realm.js +++ b/app/lib/realm.js @@ -22,6 +22,17 @@ const settingsSchema = { } }; +const roomsSchema = { + name: 'rooms', + primaryKey: '_id', + properties: { + _id: 'string', + _server: 'servers', + t: 'string', + _updatedAt: { type: 'date', optional: true } + } +}; + const subscriptionSchema = { name: 'subscriptions', primaryKey: '_id', @@ -71,8 +82,6 @@ const attachment = { title_link_download: { type: 'bool', optional: true }, type: { type: 'string', optional: true } } - - }; const messagesSchema = { @@ -100,7 +109,7 @@ const messagesSchema = { // Realm.clearTestState(); // AsyncStorage.clear(); const realm = new Realm({ - schema: [settingsSchema, serversSchema, subscriptionSchema, messagesSchema, usersSchema, attachment] + schema: [settingsSchema, serversSchema, subscriptionSchema, messagesSchema, usersSchema, roomsSchema, attachment] }); export default realm; diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index b9757d09a..139d94db8 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -186,6 +186,26 @@ 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) { @@ -389,12 +409,9 @@ const RocketChat = { }, getRooms() { return Promise.all([call('subscriptions/get'), call('rooms/get')]).then(([subscriptions, rooms]) => { - subscriptions = subscriptions.sort((s1, s2) => (s1.rid > s2.rid ? 1 : -1)); - rooms = rooms.sort((s1, s2) => (s1._id > s2._id ? 1 : -1)); - const { server, login } = reduxStore.getState(); - const data = subscriptions.map((subscription, index) => { - subscription._updatedAt = rooms[index]._updatedAt; + const data = subscriptions.map((subscription) => { + subscription._updatedAt = (rooms.find(room => room._id === subscription.rid) || {})._updatedAt; subscription._server = { id: server.server }; return subscription; }); diff --git a/app/presentation/RoomItem.js b/app/presentation/RoomItem.js index de65d424e..3452f81fb 100644 --- a/app/presentation/RoomItem.js +++ b/app/presentation/RoomItem.js @@ -1,4 +1,5 @@ import React from 'react'; +import moment from 'moment'; import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons'; import PropTypes from 'prop-types'; import { View, Text, StyleSheet, TouchableOpacity } from 'react-native'; @@ -25,13 +26,24 @@ const styles = StyleSheet.create({ paddingLeft: 5, paddingRight: 5 }, - roomName: { + roomNameView: { flex: 1, - fontSize: 16, - color: '#444', marginLeft: 16, marginRight: 4 }, + roomName: { + paddingTop: 10, + flex: 1, + fontSize: 16, + height: 16, + color: '#444' + }, + update: { + flex: 1, + fontSize: 10, + height: 10, + color: '#888' + }, iconContainer: { height: 40, width: 40, @@ -60,9 +72,11 @@ export default class RoomItem extends React.PureComponent { static propTypes = { type: PropTypes.string.isRequired, name: PropTypes.string.isRequired, + _updatedAt: PropTypes.date, unread: PropTypes.number, baseUrl: PropTypes.string, - onPress: PropTypes.func + onPress: PropTypes.func, + Message_DateFormat: PropTypes.string.isRequired } get icon() { @@ -111,11 +125,14 @@ export default class RoomItem extends React.PureComponent { } render() { - const { unread, name } = this.props; + const { unread, name, _updatedAt } = this.props; return ( {this.icon} - { name } + + { name } + { moment(_updatedAt).format(this.props.Message_DateFormat) } + {this.renderNumber(unread)} ); diff --git a/app/views/RoomsListView.js b/app/views/RoomsListView.js index 3d5d8a40c..3f6139012 100644 --- a/app/views/RoomsListView.js +++ b/app/views/RoomsListView.js @@ -60,6 +60,7 @@ const ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1 !== r2 }); login: state.login, Site_Url: state.settings.Site_Url, canShowList: state.login.token || state.login.user.token + // Message_DateFormat: state.settings.Message_DateFormat }), dispatch => ({ login: () => dispatch(actions.login()), connect: () => dispatch(server.connectRequest()) @@ -69,6 +70,7 @@ export default class RoomsListView extends React.Component { static propTypes = { navigation: PropTypes.object.isRequired, Site_Url: PropTypes.string, + // Message_DateFormat: PropTypes.string, server: PropTypes.string } @@ -237,9 +239,11 @@ export default class RoomsListView extends React.Component { this._onPressItem(item._id, item)} /> ) diff --git a/package-lock.json b/package-lock.json index b72dfd9a1..0f72fe190 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10987,6 +10987,16 @@ "crypto-js": "3.1.9-1" } }, + "react-native-keyboard-aware-scroll-view": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/react-native-keyboard-aware-scroll-view/-/react-native-keyboard-aware-scroll-view-0.3.0.tgz", + "integrity": "sha512-gMZq/o3xSd4p8GN2N9++SeYhURHt619ouCJnndHTdKyoDc3qdrETXeC356ogf7IqDVDI4Q42G30Vftktvsn+4g==", + "requires": { + "create-react-class": "15.6.2", + "prop-types": "15.6.0", + "react-timer-mixin": "0.13.3" + } + }, "react-native-loading-spinner-overlay": { "version": "0.5.2", "resolved": "https://registry.npmjs.org/react-native-loading-spinner-overlay/-/react-native-loading-spinner-overlay-0.5.2.tgz",