Fix room ordering
This commit is contained in:
parent
6d4e6f0c6c
commit
329669f18f
|
@ -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 = {
|
const subscriptionSchema = {
|
||||||
name: 'subscriptions',
|
name: 'subscriptions',
|
||||||
primaryKey: '_id',
|
primaryKey: '_id',
|
||||||
|
@ -71,8 +82,6 @@ const attachment = {
|
||||||
title_link_download: { type: 'bool', optional: true },
|
title_link_download: { type: 'bool', optional: true },
|
||||||
type: { type: 'string', optional: true }
|
type: { type: 'string', optional: true }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const messagesSchema = {
|
const messagesSchema = {
|
||||||
|
@ -100,7 +109,7 @@ const messagesSchema = {
|
||||||
// Realm.clearTestState();
|
// Realm.clearTestState();
|
||||||
// AsyncStorage.clear();
|
// AsyncStorage.clear();
|
||||||
const realm = new Realm({
|
const realm = new Realm({
|
||||||
schema: [settingsSchema, serversSchema, subscriptionSchema, messagesSchema, usersSchema, attachment]
|
schema: [settingsSchema, serversSchema, subscriptionSchema, messagesSchema, usersSchema, roomsSchema, attachment]
|
||||||
});
|
});
|
||||||
export default realm;
|
export default realm;
|
||||||
|
|
||||||
|
|
|
@ -186,6 +186,26 @@ const RocketChat = {
|
||||||
return this.login(params, callback);
|
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) {
|
loadSubscriptions(cb) {
|
||||||
Meteor.call('subscriptions/get', (err, data) => {
|
Meteor.call('subscriptions/get', (err, data) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -389,12 +409,9 @@ const RocketChat = {
|
||||||
},
|
},
|
||||||
getRooms() {
|
getRooms() {
|
||||||
return Promise.all([call('subscriptions/get'), call('rooms/get')]).then(([subscriptions, rooms]) => {
|
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 { server, login } = reduxStore.getState();
|
||||||
const data = subscriptions.map((subscription, index) => {
|
const data = subscriptions.map((subscription) => {
|
||||||
subscription._updatedAt = rooms[index]._updatedAt;
|
subscription._updatedAt = (rooms.find(room => room._id === subscription.rid) || {})._updatedAt;
|
||||||
subscription._server = { id: server.server };
|
subscription._server = { id: server.server };
|
||||||
return subscription;
|
return subscription;
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import moment from 'moment';
|
||||||
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
|
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { View, Text, StyleSheet, TouchableOpacity } from 'react-native';
|
import { View, Text, StyleSheet, TouchableOpacity } from 'react-native';
|
||||||
|
@ -25,13 +26,24 @@ const styles = StyleSheet.create({
|
||||||
paddingLeft: 5,
|
paddingLeft: 5,
|
||||||
paddingRight: 5
|
paddingRight: 5
|
||||||
},
|
},
|
||||||
roomName: {
|
roomNameView: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
fontSize: 16,
|
|
||||||
color: '#444',
|
|
||||||
marginLeft: 16,
|
marginLeft: 16,
|
||||||
marginRight: 4
|
marginRight: 4
|
||||||
},
|
},
|
||||||
|
roomName: {
|
||||||
|
paddingTop: 10,
|
||||||
|
flex: 1,
|
||||||
|
fontSize: 16,
|
||||||
|
height: 16,
|
||||||
|
color: '#444'
|
||||||
|
},
|
||||||
|
update: {
|
||||||
|
flex: 1,
|
||||||
|
fontSize: 10,
|
||||||
|
height: 10,
|
||||||
|
color: '#888'
|
||||||
|
},
|
||||||
iconContainer: {
|
iconContainer: {
|
||||||
height: 40,
|
height: 40,
|
||||||
width: 40,
|
width: 40,
|
||||||
|
@ -60,9 +72,11 @@ export default class RoomItem extends React.PureComponent {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
type: PropTypes.string.isRequired,
|
type: PropTypes.string.isRequired,
|
||||||
name: PropTypes.string.isRequired,
|
name: PropTypes.string.isRequired,
|
||||||
|
_updatedAt: PropTypes.date,
|
||||||
unread: PropTypes.number,
|
unread: PropTypes.number,
|
||||||
baseUrl: PropTypes.string,
|
baseUrl: PropTypes.string,
|
||||||
onPress: PropTypes.func
|
onPress: PropTypes.func,
|
||||||
|
Message_DateFormat: PropTypes.string.isRequired
|
||||||
}
|
}
|
||||||
|
|
||||||
get icon() {
|
get icon() {
|
||||||
|
@ -111,11 +125,14 @@ export default class RoomItem extends React.PureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { unread, name } = this.props;
|
const { unread, name, _updatedAt } = this.props;
|
||||||
return (
|
return (
|
||||||
<TouchableOpacity onPress={this.props.onPress} style={styles.container}>
|
<TouchableOpacity onPress={this.props.onPress} style={styles.container}>
|
||||||
{this.icon}
|
{this.icon}
|
||||||
|
<View style={styles.roomNameView}>
|
||||||
<Text style={styles.roomName} ellipsizeMode='tail' numberOfLines={1}>{ name }</Text>
|
<Text style={styles.roomName} ellipsizeMode='tail' numberOfLines={1}>{ name }</Text>
|
||||||
|
<Text style={styles.update} ellipsizeMode='tail' numberOfLines={1}>{ moment(_updatedAt).format(this.props.Message_DateFormat) }</Text>
|
||||||
|
</View>
|
||||||
{this.renderNumber(unread)}
|
{this.renderNumber(unread)}
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
);
|
);
|
||||||
|
|
|
@ -60,6 +60,7 @@ const ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1 !== r2 });
|
||||||
login: state.login,
|
login: state.login,
|
||||||
Site_Url: state.settings.Site_Url,
|
Site_Url: state.settings.Site_Url,
|
||||||
canShowList: state.login.token || state.login.user.token
|
canShowList: state.login.token || state.login.user.token
|
||||||
|
// Message_DateFormat: state.settings.Message_DateFormat
|
||||||
}), dispatch => ({
|
}), dispatch => ({
|
||||||
login: () => dispatch(actions.login()),
|
login: () => dispatch(actions.login()),
|
||||||
connect: () => dispatch(server.connectRequest())
|
connect: () => dispatch(server.connectRequest())
|
||||||
|
@ -69,6 +70,7 @@ export default class RoomsListView extends React.Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
navigation: PropTypes.object.isRequired,
|
navigation: PropTypes.object.isRequired,
|
||||||
Site_Url: PropTypes.string,
|
Site_Url: PropTypes.string,
|
||||||
|
// Message_DateFormat: PropTypes.string,
|
||||||
server: PropTypes.string
|
server: PropTypes.string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,9 +239,11 @@ export default class RoomsListView extends React.Component {
|
||||||
<RoomItem
|
<RoomItem
|
||||||
unread={item.unread}
|
unread={item.unread}
|
||||||
name={item.name}
|
name={item.name}
|
||||||
|
_updatedAt={item._updatedAt}
|
||||||
key={item._id}
|
key={item._id}
|
||||||
type={item.t}
|
type={item.t}
|
||||||
baseUrl={this.props.Site_Url}
|
baseUrl={this.props.Site_Url}
|
||||||
|
Message_DateFormat={'MM-DD-YYYY HH:mm:ss'}
|
||||||
onPress={() => this._onPressItem(item._id, item)}
|
onPress={() => this._onPressItem(item._id, item)}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|
|
@ -10987,6 +10987,16 @@
|
||||||
"crypto-js": "3.1.9-1"
|
"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": {
|
"react-native-loading-spinner-overlay": {
|
||||||
"version": "0.5.2",
|
"version": "0.5.2",
|
||||||
"resolved": "https://registry.npmjs.org/react-native-loading-spinner-overlay/-/react-native-loading-spinner-overlay-0.5.2.tgz",
|
"resolved": "https://registry.npmjs.org/react-native-loading-spinner-overlay/-/react-native-loading-spinner-overlay-0.5.2.tgz",
|
||||||
|
|
Loading…
Reference in New Issue