diff --git a/app/lib/realm.js b/app/lib/realm.js
index 7087ac26..bca5a7a1 100644
--- a/app/lib/realm.js
+++ b/app/lib/realm.js
@@ -81,7 +81,8 @@ const subscriptionSchema = {
// userMentions: 0,
// groupMentions: 0,
roomUpdatedAt: { type: 'date', optional: true },
- ro: { type: 'bool', optional: true }
+ ro: { type: 'bool', optional: true },
+ lastMessage: { type: 'messages', optional: true }
}
};
@@ -135,7 +136,7 @@ const attachment = {
const url = {
name: 'url',
properties: {
- _id: 'int',
+ // _id: { type: 'int', optional: true },
url: { type: 'string', optional: true },
title: { type: 'string', optional: true },
description: { type: 'string', optional: true },
@@ -184,7 +185,7 @@ const messagesSchema = {
groupable: { type: 'bool', optional: true },
avatar: { type: 'string', optional: true },
attachments: { type: 'list', objectType: 'attachment' },
- urls: { type: 'list', objectType: 'url' },
+ urls: { type: 'list', objectType: 'url', default: [] },
_updatedAt: { type: 'date', optional: true },
status: { type: 'int', optional: true },
pinned: { type: 'bool', optional: true },
diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js
index d561e5e0..0e1b1211 100644
--- a/app/lib/rocketchat.js
+++ b/app/lib/rocketchat.js
@@ -92,7 +92,7 @@ const RocketChat = {
reduxStore.dispatch(connectFailure());
});
- this.ddp.on('connected', () => this.ddp.subscribe('activeUsers', null, false));
+ // this.ddp.on('connected', () => this.ddp.subscribe('activeUsers', null, false));
this.ddp.on('users', (ddpMessage) => {
if (ddpMessage.collection === 'users') {
@@ -128,11 +128,15 @@ const RocketChat = {
const sub = database.objects('subscriptions').filtered('rid == $0', data._id)[0];
database.write(() => {
sub.roomUpdatedAt = data._updatedAt;
+ if (data.lastMessage) {
+ // data.lastMessage.url = data.lastMessage.url || [];
+ }
+ sub.lastMessage = data.lastMessage;
sub.ro = data.ro;
});
}
});
- });
+ }).catch(console.log);
},
me({ server, token, userId }) {
@@ -428,6 +432,10 @@ const RocketChat = {
const room = rooms.find(({ _id }) => _id === subscription.rid);
if (room) {
subscription.roomUpdatedAt = room._updatedAt;
+ // if (room.lastMessage) {
+ // room.lastMessage.url = room.lastMessage.url || [];
+ // }
+ subscription.lastMessage = room.lastMessage;
subscription.ro = room.ro;
}
if (subscription.roles) {
@@ -436,12 +444,16 @@ const RocketChat = {
return subscription;
});
- database.write(() => {
- data.forEach(subscription =>
- database.create('subscriptions', subscription, true));
- rooms.forEach(room =>
- database.create('rooms', room, true));
- });
+ try {
+ database.write(() => {
+ data.forEach(subscription => database.create('subscriptions', subscription, true));
+ // rooms.forEach(room => database.create('rooms', room, true));
+ });
+ } catch (e) {
+ alert(JSON.stringify(e));
+ } finally {
+
+ }
this.ddp.subscribe('stream-notify-user', `${ login.user.id }/subscriptions-changed`, false);
this.ddp.subscribe('stream-notify-user', `${ login.user.id }/rooms-changed`, false);
diff --git a/app/presentation/RoomItem.js b/app/presentation/RoomItem.js
index 82bd362a..c3b74203 100644
--- a/app/presentation/RoomItem.js
+++ b/app/presentation/RoomItem.js
@@ -2,6 +2,9 @@ import React from 'react';
import moment from 'moment';
import PropTypes from 'prop-types';
import { View, Text, StyleSheet } from 'react-native';
+import { emojify } from 'react-emojione';
+import { connect } from 'react-redux';
+
import Avatar from '../containers/Avatar';
import Touch from '../utils/touch/index'; //eslint-disable-line
@@ -9,29 +12,45 @@ const styles = StyleSheet.create({
container: {
flexDirection: 'row',
paddingHorizontal: 16,
- paddingVertical: 10,
- alignItems: 'center'
+ paddingVertical: 12,
+ alignItems: 'flex-start',
+ borderBottomWidth: 0.5,
+ borderBottomColor: '#ddd'
},
number: {
- minWidth: 20,
- borderRadius: 3,
+ minWidth: 25,
+ borderRadius: 4,
backgroundColor: '#1d74f5',
color: '#fff',
- textAlign: 'center',
overflow: 'hidden',
fontSize: 14,
+ paddingVertical: 4,
paddingHorizontal: 5,
- paddingVertical: 2
+
+ textAlign: 'center',
+ alignItems: 'center',
+ justifyContent: 'center'
},
roomNameView: {
flex: 1,
+ height: '100%',
marginLeft: 16,
marginRight: 4
},
roomName: {
flex: 1,
+ fontSize: 18,
+ color: '#444',
+ fontWeight: 'bold',
+ marginRight: 8
+ },
+ lastMessage: {
+ flex: 1,
+ flexShrink: 1,
fontSize: 16,
- color: '#444'
+ color: '#444',
+ marginRight: 8
+ // margin: 0
},
alert: {
fontWeight: 'bold'
@@ -39,14 +58,44 @@ const styles = StyleSheet.create({
favorite: {
// backgroundColor: '#eee'
},
- update: {
+ row: {
+ width: '100%',
flex: 1,
+ flexDirection: 'row',
+ alignItems: 'center',
+ justifyContent: 'center'
+ },
+ update: {
fontSize: 10,
- // height: 10,
- color: '#888'
+ color: '#888',
+ alignItems: 'center',
+ justifyContent: 'center'
}
});
+const renderNumber = (unread, userMentions) => {
+ if (!unread || unread <= 0) {
+ return;
+ }
+
+ if (unread >= 1000) {
+ unread = '999+';
+ }
+
+ if (userMentions > 0) {
+ unread = `@ ${ unread }`;
+ }
+
+ return (
+
+ { unread }
+
+ );
+};
+
+@connect(state => ({
+ StoreLastMessage: state.settings.Store_Last_Message
+}))
export default class RoomItem extends React.PureComponent {
static propTypes = {
type: PropTypes.string.isRequired,
@@ -63,7 +112,7 @@ export default class RoomItem extends React.PureComponent {
get icon() {
const { type, name, baseUrl } = this.props;
- return ;
+ return ;
}
formatDate = date => moment(date).calendar(null, {
@@ -73,26 +122,6 @@ export default class RoomItem extends React.PureComponent {
sameElse: 'MMM D'
})
- renderNumber = (unread, userMentions) => {
- if (!unread || unread <= 0) {
- return;
- }
-
- if (unread >= 1000) {
- unread = '999+';
- }
-
- if (userMentions > 0) {
- unread = `@ ${ unread }`;
- }
-
- return (
-
- { unread }
-
- );
- }
-
render() {
const {
favorite, alert, unread, userMentions, name, lastMessage, _updatedAt
@@ -100,7 +129,7 @@ export default class RoomItem extends React.PureComponent {
const date = this.formatDate(_updatedAt);
- console.log("do we have a last message?", lastMessage);
+ console.log('do we have a last message?', lastMessage);
let accessibilityLabel = name;
if (unread === 1) {
@@ -120,11 +149,19 @@ export default class RoomItem extends React.PureComponent {
{this.icon}
- { name }
- {lastMessage ? {lastMessage.u.username}: {lastMessage.msg} : No Message}
- {_updatedAt ? { date } : null}
+
+ { name }
+ {_updatedAt ? { date } : null}
+
+
+
+
+ {!this.props.StoreLastMessage ? '' : lastMessage ? `${ lastMessage.u.username }: ${ emojify(lastMessage.msg, { output: 'unicode' }) }` : 'No Message'}
+
+
+ {renderNumber(unread, userMentions)}
+
- {this.renderNumber(unread, userMentions)}
);
diff --git a/app/views/RoomsListView/index.js b/app/views/RoomsListView/index.js
index 69f39d00..7cabb482 100644
--- a/app/views/RoomsListView/index.js
+++ b/app/views/RoomsListView/index.js
@@ -48,7 +48,6 @@ export default class RoomsListView extends React.Component {
searchText: ''
};
this.data = database.objects('subscriptions').sorted('roomUpdatedAt', true);
-
}
componentDidMount() {
@@ -81,9 +80,9 @@ export default class RoomsListView extends React.Component {
}
getLastMessage = (subscription) => {
- const [ room ] = database.objects('rooms').filtered('_id = $0', subscription.rid).slice();
+ const [room] = database.objects('rooms').filtered('_id = $0', subscription.rid).slice();
console.log('ROOM', room);
- return room.lastMessage;
+ return room && room.lastMessage;
}
search(text) {
@@ -209,8 +208,8 @@ export default class RoomsListView extends React.Component {
alert={item.alert}
unread={item.unread}
userMentions={item.userMentions}
- lastMessage={this.getLastMessage(item)}
favorite={item.f}
+ lastMessage={item.lastMessage}
name={item.name}
_updatedAt={item.roomUpdatedAt}
key={item._id}
diff --git a/package-lock.json b/package-lock.json
index 57ab9160..a7b1330c 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -12573,11 +12573,6 @@
"requires": {
"lodash": "4.17.4",
"react-native-keyboard-tracking-view": "git+https://github.com/RocketChat/react-native-keyboard-tracking-view.git#3a4084f0a1063e23ae6435facdf1f79152558d15"
- },
- "dependencies": {
- "react-native-keyboard-tracking-view": {
- "version": "git+https://github.com/RocketChat/react-native-keyboard-tracking-view.git#3a4084f0a1063e23ae6435facdf1f79152558d15"
- }
}
},
"react-native-keyboard-tracking-view": {