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 { 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 (
<View style={[styles.message, extraStyle]}>
<View style={[styles.avatarContainer, { backgroundColor: color }]}>
<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 style={styles.texts}>
<Text onPress={this._onPress} style={styles.username}>
{this.props.item.u.username}
{username}
</Text>
<Markdown>
{msg}

View File

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

View File

@ -67,9 +67,70 @@ const messagesSchema = {
u: 'users',
// mentions: [],
// 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 },
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();

View File

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

View File

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