attempt to add last message
This commit is contained in:
parent
c81182c9cf
commit
2ec5916593
|
@ -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 }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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)}
|
||||||
|
|
|
@ -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}
|
||||||
|
|
Loading…
Reference in New Issue