attempt to add last message
This commit is contained in:
parent
c81182c9cf
commit
2ec5916593
|
@ -49,6 +49,7 @@ const roomsSchema = {
|
|||
properties: {
|
||||
_id: 'string',
|
||||
t: 'string',
|
||||
lastMessage: 'messages',
|
||||
_updatedAt: { type: 'date', optional: true }
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)}
|
||||
|
|
|
@ -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}
|
||||
|
|
Loading…
Reference in New Issue