attempt to add last message

This commit is contained in:
Aaron Ogle 2018-01-19 15:06:55 -06:00
parent c81182c9cf
commit 2ec5916593
No known key found for this signature in database
GPG Key ID: 9DE7F8BEE517326A
4 changed files with 21 additions and 1 deletions

View File

@ -49,6 +49,7 @@ const roomsSchema = {
properties: {
_id: 'string',
t: 'string',
lastMessage: 'messages',
_updatedAt: { type: 'date', optional: true }
}
};

View File

@ -432,10 +432,17 @@ const RocketChat = {
}
return subscription;
});
database.write(() => {
data.forEach(subscription =>
database.create('subscriptions', subscription, true));
});
database.write(() => {
rooms.forEach(room =>
database.create('rooms', room, true));
});
this.ddp.subscribe('stream-notify-user', `${ login.user.id }/subscriptions-changed`, false);
this.ddp.subscribe('stream-notify-user', `${ login.user.id }/rooms-changed`, false);
return data;

View File

@ -52,6 +52,7 @@ export default class RoomItem extends React.PureComponent {
type: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
_updatedAt: PropTypes.instanceOf(Date),
lastMessage: PropTypes.object,
favorite: PropTypes.bool,
alert: PropTypes.bool,
unread: PropTypes.number,
@ -94,11 +95,13 @@ export default class RoomItem extends React.PureComponent {
render() {
const {
favorite, alert, unread, userMentions, name, _updatedAt
favorite, alert, unread, userMentions, name, lastMessage, _updatedAt
} = this.props;
const date = this.formatDate(_updatedAt);
console.log("do we have a last message?", lastMessage);
let accessibilityLabel = name;
if (unread === 1) {
accessibilityLabel += `, ${ unread } alert`;
@ -118,6 +121,7 @@ export default class RoomItem extends React.PureComponent {
{this.icon}
<View style={styles.roomNameView}>
<Text style={[styles.roomName, alert && styles.alert]} ellipsizeMode='tail' numberOfLines={1}>{ name }</Text>
{lastMessage ? <Text>{lastMessage.u.username}: {lastMessage.msg}</Text> : <Text>No Message</Text>}
{_updatedAt ? <Text style={styles.update} ellipsizeMode='tail' numberOfLines={1}>{ date }</Text> : null}
</View>
{this.renderNumber(unread, userMentions)}

View File

@ -48,6 +48,7 @@ export default class RoomsListView extends React.Component {
searchText: ''
};
this.data = database.objects('subscriptions').sorted('roomUpdatedAt', true);
}
componentDidMount() {
@ -79,6 +80,12 @@ export default class RoomsListView extends React.Component {
this.search(text);
}
getLastMessage = (subscription) => {
const room = database.objects('rooms').sorted('_updatedAt', true).slice().find(({ _id }) => _id === subscription.rid);
console.log('ROOM', room);
return room.lastMessage;
}
search(text) {
const searchText = text.trim();
if (searchText === '') {
@ -202,6 +209,7 @@ export default class RoomsListView extends React.Component {
alert={item.alert}
unread={item.unread}
userMentions={item.userMentions}
lastMessage={this.getLastMessage(item)}
favorite={item.f}
name={item.name}
_updatedAt={item.roomUpdatedAt}