almost done, missing custom emojy yet
This commit is contained in:
parent
d01c6c0ffd
commit
7fda5a528d
|
@ -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 },
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 (
|
||||
<Text style={styles.number}>
|
||||
{ unread }
|
||||
</Text>
|
||||
);
|
||||
};
|
||||
|
||||
@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 <Avatar text={name} baseUrl={baseUrl} size={40} type={type} />;
|
||||
return <Avatar text={name} baseUrl={baseUrl} size={56} type={type} />;
|
||||
}
|
||||
|
||||
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 (
|
||||
<Text style={styles.number}>
|
||||
{ unread }
|
||||
</Text>
|
||||
);
|
||||
}
|
||||
|
||||
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 {
|
|||
<View style={[styles.container, favorite && styles.favorite]}>
|
||||
{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 style={styles.row}>
|
||||
<Text style={styles.roomName} ellipsizeMode='tail' numberOfLines={1}>{ name }</Text>
|
||||
{_updatedAt ? <Text style={styles.update} ellipsizeMode='tail' numberOfLines={1}>{ date }</Text> : null}
|
||||
</View>
|
||||
<View style={styles.row}>
|
||||
|
||||
|
||||
<Text style={[styles.lastMessage, alert && styles.alert]} ellipsizeMode='tail' numberOfLines={1}>{!this.props.StoreLastMessage ? '' : lastMessage ? `${ lastMessage.u.username }: ${ emojify(lastMessage.msg, { output: 'unicode' }) }` : 'No Message'}</Text>
|
||||
|
||||
|
||||
{renderNumber(unread, userMentions)}
|
||||
</View>
|
||||
</View>
|
||||
{this.renderNumber(unread, userMentions)}
|
||||
</View>
|
||||
</Touch>
|
||||
);
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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": {
|
||||
|
|
Loading…
Reference in New Issue