From c86e06afa0f5197a410cb82884f6c0c0255cbb0d Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Fri, 19 Jan 2018 10:38:14 -0200 Subject: [PATCH] @all & @here mention (#200) --- app/containers/MessageBox/index.js | 45 +++++++++++++++++++++++------- app/containers/MessageBox/style.js | 5 ++++ 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/app/containers/MessageBox/index.js b/app/containers/MessageBox/index.js index af1a196d..be054279 100644 --- a/app/containers/MessageBox/index.js +++ b/app/containers/MessageBox/index.js @@ -212,11 +212,21 @@ export default class MessageBox extends React.PureComponent { }); } + _getFixedMentions(keyword) { + if ('all'.indexOf(keyword) !== -1) { + this.users = [{ _id: -1, username: 'all', desc: 'all' }, ...this.users]; + } + if ('here'.indexOf(keyword) !== -1) { + this.users = [{ _id: -2, username: 'here', desc: 'active users' }, ...this.users]; + } + } + async _getUsers(keyword) { this.users = database.objects('users'); if (keyword) { this.users = this.users.filtered('username CONTAINS[c] $0', keyword); } + this._getFixedMentions(keyword); this.setState({ mentions: this.users.slice() }); const usernames = []; @@ -244,8 +254,9 @@ export default class MessageBox extends React.PureComponent { console.log('spotlight canceled'); } finally { delete this.oldPromise; - this.users = database.objects('users').filtered('username CONTAINS[c] $0', keyword); - this.setState({ mentions: this.users.slice() }); + this.users = database.objects('users').filtered('username CONTAINS[c] $0', keyword).slice(); + this._getFixedMentions(keyword); + this.setState({ mentions: this.users }); } } @@ -345,20 +356,34 @@ export default class MessageBox extends React.PureComponent { this.component.setNativeProps({ text: newText }); this.setState({ text: newText }); } - renderMentionItem = item => ( + renderFixedMentionItem = item => ( this._onPressMention(item)} > - - {item.username || item.name } + {item.username} + Notify {item.desc} in this room ) + renderMentionItem = (item) => { + if (item.username === 'all' || item.username === 'here') { + return this.renderFixedMentionItem(item); + } + return ( + this._onPressMention(item)} + > + + {item.username || item.name } + + ); + } renderEmoji() { const emojiContainer = ( diff --git a/app/containers/MessageBox/style.js b/app/containers/MessageBox/style.js index bee61609..6bb79baa 100644 --- a/app/containers/MessageBox/style.js +++ b/app/containers/MessageBox/style.js @@ -85,5 +85,10 @@ export default StyleSheet.create({ borderTopColor: '#ECECEC', borderTopWidth: 1, backgroundColor: '#fff' + }, + fixedMentionAvatar: { + fontWeight: 'bold', + textAlign: 'center', + width: 46 } });