Add message alias and custom avatar

This commit is contained in:
Rodrigo Nascimento 2017-08-13 20:45:47 -03:00
parent b9f802cfac
commit 34ea211506
5 changed files with 79 additions and 10 deletions

View File

@ -60,17 +60,25 @@ export default class Message extends React.PureComponent {
const msg = emojify(this.props.item.msg, { output: 'unicode' }); const msg = emojify(this.props.item.msg, { output: 'unicode' });
const { initials, color } = avatarInitialsAndColor(this.props.item.u.username); const username = this.props.item.alias || this.props.item.u.username;
let { initials, color } = avatarInitialsAndColor(username);
const avatar = this.props.item.avatar || `${ this.props.baseUrl }/avatar/${ this.props.item.u.username }`;
if (this.props.item.avatar) {
initials = '';
color = 'transparent';
}
return ( return (
<View style={[styles.message, extraStyle]}> <View style={[styles.message, extraStyle]}>
<View style={[styles.avatarContainer, { backgroundColor: color }]}> <View style={[styles.avatarContainer, { backgroundColor: color }]}>
<Text style={styles.avatarInitials}>{initials}</Text> <Text style={styles.avatarInitials}>{initials}</Text>
<CachedImage style={styles.avatar} source={{ uri: `${ this.props.baseUrl }/avatar/${ this.props.item.u.username }` }} /> <CachedImage style={styles.avatar} source={{ uri: avatar }} />
</View> </View>
<View style={styles.texts}> <View style={styles.texts}>
<Text onPress={this._onPress} style={styles.username}> <Text onPress={this._onPress} style={styles.username}>
{this.props.item.u.username} {username}
</Text> </Text>
<Markdown> <Markdown>
{msg} {msg}

View File

@ -60,7 +60,7 @@ const styles = StyleSheet.create({
export default class RoomItem extends React.PureComponent { export default class RoomItem extends React.PureComponent {
static propTypes = { static propTypes = {
item: PropTypes.object.isRequired, item: PropTypes.object.isRequired,
baseUrl: PropTypes.string.isRequired baseUrl: PropTypes.string
} }
get icon() { get icon() {
const icon = { const icon = {

View File

@ -67,9 +67,70 @@ const messagesSchema = {
u: 'users', u: 'users',
// mentions: [], // mentions: [],
// channels: [], // channels: [],
alias: { type: 'string', optional: true },
parseUrls: { type: 'bool', optional: true },
groupable: { type: 'bool', optional: true },
avatar: { type: 'string', optional: true },
_updatedAt: { type: 'date', optional: true }, _updatedAt: { type: 'date', optional: true },
temp: { type: 'bool', optional: true } temp: { type: 'bool', optional: true }
} }
// a: {
// attachments: [
// {
// color: 'danger',
// fields: [
// {
// title: 'Bounce Type',
// value: 'Permanent'
// },
// {
// title: 'Bounce Sub Type',
// value: 'General'
// },
// {
// title: 'Reporting MTA',
// value: 'dsn; a8-82.smtp-out.amazonses.com'
// },
// {
// title: 'Timestamp',
// value: 'Tue Apr 19 2016 14:11:08 GMT-0400 (EDT)'
// }
// ]
// },
// {
// fields: [
// {
// title: 'Email Address',
// value: 'aaa@asd.at'
// },
// {
// title: 'Status',
// value: '5.1.1'
// },
// {
// title: 'Action',
// value: 'failed'
// },
// {
// title: 'Diagnostic Code',
// value: 'smtp; 550 5.1.1 <aaa@asd.at>: Recipient address rejected: User unknown in virtual mailbox table'
// }
// ]
// }
// ],
// bot: {
// i: 'EMQ3S3GGNJrrgJa4Z'
// },
// u: {
// _id: 'rocket.cat',
// username: 'rocket.cat'
// },
// roles: [
// 'bot',
// null
// ]
// }
}; };
// Realm.clearTestState(); // Realm.clearTestState();

View File

@ -44,7 +44,8 @@ const styles = StyleSheet.create({
@connect(state => ({ @connect(state => ({
server: state.server server: state.server,
Site_Url: state.settings.Site_Url
}), dispatch => ({ }), dispatch => ({
actions: bindActionCreators(actions, dispatch) actions: bindActionCreators(actions, dispatch)
})) }))
@ -54,7 +55,8 @@ export default class RoomView extends React.Component {
rid: PropTypes.string, rid: PropTypes.string,
sid: PropTypes.string, sid: PropTypes.string,
name: PropTypes.string, name: PropTypes.string,
server: PropTypes.string server: PropTypes.string,
Site_Url: PropTypes.string
} }
constructor(props) { constructor(props) {
@ -68,8 +70,6 @@ export default class RoomView extends React.Component {
loaded: true, loaded: true,
joined: typeof props.rid === 'undefined' joined: typeof props.rid === 'undefined'
}; };
// console.log(this.messages);
this.url = realm.objectForPrimaryKey('settings', 'Site_Url').value;
this.props.navigator.setTitle({ this.props.navigator.setTitle({
title: this.props.name || realm.objectForPrimaryKey('subscriptions', this.props.sid).name title: this.props.name || realm.objectForPrimaryKey('subscriptions', this.props.sid).name
@ -152,7 +152,7 @@ export default class RoomView extends React.Component {
<Message <Message
id={item._id} id={item._id}
item={item} item={item}
baseUrl={this.url} baseUrl={this.props.Site_Url}
/> />
); );

View File

@ -79,7 +79,7 @@ class RoomsListItem extends React.PureComponent {
static propTypes = { static propTypes = {
item: PropTypes.object.isRequired, item: PropTypes.object.isRequired,
onPress: PropTypes.func.isRequired, onPress: PropTypes.func.isRequired,
baseUrl: PropTypes.string.isRequired baseUrl: PropTypes.string
} }
_onPress = (...args) => { _onPress = (...args) => {
this.props.onPress(...args); this.props.onPress(...args);