From 34ea211506f912c93f51d0e0f64e071c4fb2443a Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Sun, 13 Aug 2017 20:45:47 -0300 Subject: [PATCH] Add message alias and custom avatar --- app/components/Message.js | 14 +++++++-- app/components/RoomItem.js | 2 +- app/lib/realm.js | 61 ++++++++++++++++++++++++++++++++++++++ app/views/room.js | 10 +++---- app/views/roomsList.js | 2 +- 5 files changed, 79 insertions(+), 10 deletions(-) diff --git a/app/components/Message.js b/app/components/Message.js index 949ad39c..53c744e4 100644 --- a/app/components/Message.js +++ b/app/components/Message.js @@ -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 ( {initials} - + - {this.props.item.u.username} + {username} {msg} diff --git a/app/components/RoomItem.js b/app/components/RoomItem.js index 208ad084..baa4062d 100644 --- a/app/components/RoomItem.js +++ b/app/components/RoomItem.js @@ -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 = { diff --git a/app/lib/realm.js b/app/lib/realm.js index c0f9a872..a2125925 100644 --- a/app/lib/realm.js +++ b/app/lib/realm.js @@ -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 : Recipient address rejected: User unknown in virtual mailbox table' + // } + // ] + // } + // ], + // bot: { + // i: 'EMQ3S3GGNJrrgJa4Z' + // }, + // u: { + // _id: 'rocket.cat', + // username: 'rocket.cat' + // }, + // roles: [ + // 'bot', + // null + // ] + // } }; // Realm.clearTestState(); diff --git a/app/views/room.js b/app/views/room.js index 3000ab02..54d0e886 100644 --- a/app/views/room.js +++ b/app/views/room.js @@ -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 { ); diff --git a/app/views/roomsList.js b/app/views/roomsList.js index 75b95f7d..98f62097 100644 --- a/app/views/roomsList.js +++ b/app/views/roomsList.js @@ -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);