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: { properties: {
_id: 'string', _id: 'string',
t: 'string', t: 'string',
lastMessage: 'messages',
_updatedAt: { type: 'date', optional: true } _updatedAt: { type: 'date', optional: true }
} }
}; };

View File

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

View File

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

View File

@ -48,6 +48,7 @@ export default class RoomsListView extends React.Component {
searchText: '' searchText: ''
}; };
this.data = database.objects('subscriptions').sorted('roomUpdatedAt', true); this.data = database.objects('subscriptions').sorted('roomUpdatedAt', true);
} }
componentDidMount() { componentDidMount() {
@ -79,6 +80,12 @@ export default class RoomsListView extends React.Component {
this.search(text); 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) { search(text) {
const searchText = text.trim(); const searchText = text.trim();
if (searchText === '') { if (searchText === '') {
@ -202,6 +209,7 @@ export default class RoomsListView extends React.Component {
alert={item.alert} alert={item.alert}
unread={item.unread} unread={item.unread}
userMentions={item.userMentions} userMentions={item.userMentions}
lastMessage={this.getLastMessage(item)}
favorite={item.f} favorite={item.f}
name={item.name} name={item.name}
_updatedAt={item.roomUpdatedAt} _updatedAt={item.roomUpdatedAt}