@@ -18,8 +18,14 @@ class IncomingCallPage extends Component {
1818 constructor ( props ) {
1919 super ( props ) ;
2020
21+ let selectedMatcherIndex = 0 ;
22+ if ( props . session . contactMatch ) {
23+ selectedMatcherIndex = props . nameMatches . findIndex ( match =>
24+ match . id === props . session . contactMatch . id
25+ ) ;
26+ }
2127 this . state = {
22- selectedMatcherIndex : 0 ,
28+ selectedMatcherIndex,
2329 avatarUrl : null ,
2430 } ;
2531
@@ -29,10 +35,10 @@ class IncomingCallPage extends Component {
2935 selectedMatcherIndex : ( index - 1 ) ,
3036 avatarUrl : null ,
3137 } ) ;
32- const nameMatches = this . props . session . direction === callDirections . outbound ?
33- this . props . toMatches : this . props . fromMatches ;
38+ const nameMatches = this . props . nameMatches ;
3439 const contact = nameMatches && nameMatches [ index - 1 ] ;
3540 if ( contact ) {
41+ this . props . updateSessionMatchedContact ( this . props . session . id , contact ) ;
3642 this . props . getAvatarUrl ( contact ) . then ( ( avatarUrl ) => {
3743 this . setState ( { avatarUrl } ) ;
3844 } ) ;
@@ -53,13 +59,19 @@ class IncomingCallPage extends Component {
5359
5460 componentWillReceiveProps ( nextProps ) {
5561 if ( this . props . session . id !== nextProps . session . id ) {
62+ let selectedMatcherIndex = 0 ;
63+ let contact = nextProps . session . contactMatch ;
64+ if ( ! contact ) {
65+ contact = nextProps . nameMatches && nextProps . nameMatches [ 0 ] ;
66+ } else {
67+ selectedMatcherIndex = nextProps . nameMatches . findIndex ( match =>
68+ match . id === contact . id
69+ ) ;
70+ }
5671 this . setState ( {
57- selectedMatcherIndex : 0 ,
72+ selectedMatcherIndex,
5873 avatarUrl : null ,
5974 } ) ;
60- const nameMatches = nextProps . session . direction === callDirections . outbound ?
61- nextProps . toMatches : nextProps . fromMatches ;
62- const contact = nameMatches && nameMatches [ 0 ] ;
6375 if ( contact ) {
6476 nextProps . getAvatarUrl ( contact ) . then ( ( avatarUrl ) => {
6577 this . setState ( { avatarUrl } ) ;
@@ -90,8 +102,6 @@ class IncomingCallPage extends Component {
90102 }
91103 const phoneNumber = session . direction === callDirections . outbound ?
92104 session . to : session . from ;
93- const nameMatches = session . direction === callDirections . outbound ?
94- this . props . toMatches : this . props . fromMatches ;
95105 let fallbackUserName ;
96106 if ( session . direction === callDirections . inbound && session . from === 'anonymous' ) {
97107 fallbackUserName = i18n . getString ( 'anonymous' , this . props . currentLocale ) ;
@@ -102,7 +112,7 @@ class IncomingCallPage extends Component {
102112 return (
103113 < IncomingCallPanel
104114 currentLocale = { this . props . currentLocale }
105- nameMatches = { nameMatches }
115+ nameMatches = { this . props . nameMatches }
106116 fallBackName = { fallbackUserName }
107117 phoneNumber = { phoneNumber }
108118 answer = { this . answer }
@@ -135,6 +145,7 @@ IncomingCallPage.propTypes = {
135145 isOnRecord : PropTypes . bool ,
136146 to : PropTypes . string ,
137147 from : PropTypes . string ,
148+ contactMatch : PropTypes . object ,
138149 } ) . isRequired ,
139150 currentLocale : PropTypes . string . isRequired ,
140151 minimized : PropTypes . bool . isRequired ,
@@ -145,13 +156,13 @@ IncomingCallPage.propTypes = {
145156 replyWithMessage : PropTypes . func . isRequired ,
146157 formatPhone : PropTypes . func . isRequired ,
147158 children : PropTypes . node ,
148- toMatches : PropTypes . array . isRequired ,
149- fromMatches : PropTypes . array . isRequired ,
159+ nameMatches : PropTypes . array . isRequired ,
150160 areaCode : PropTypes . string . isRequired ,
151161 countryCode : PropTypes . string . isRequired ,
152162 getAvatarUrl : PropTypes . func . isRequired ,
153163 forwardingNumbers : PropTypes . array . isRequired ,
154164 onForward : PropTypes . func . isRequired ,
165+ updateSessionMatchedContact : PropTypes . func . isRequired ,
155166} ;
156167
157168IncomingCallPage . defaultProps = {
@@ -167,9 +178,12 @@ function mapToProps(_, {
167178} ) {
168179 const currentSession = webphone . currentSession || { } ;
169180 const contactMapping = contactMatcher && contactMatcher . dataMapping ;
181+ const fromMatches = ( contactMapping && contactMapping [ currentSession . from ] ) || [ ] ;
182+ const toMatches = ( contactMapping && contactMapping [ currentSession . to ] ) || [ ] ;
183+ const nameMatches =
184+ currentSession . direction === callDirections . outbound ? toMatches : fromMatches ;
170185 return {
171- fromMatches : ( contactMapping && contactMapping [ currentSession . from ] ) || [ ] ,
172- toMatches : ( contactMapping && contactMapping [ currentSession . to ] ) || [ ] ,
186+ nameMatches,
173187 currentLocale : locale . currentLocale ,
174188 session : currentSession ,
175189 minimized : webphone . minimized ,
@@ -196,6 +210,8 @@ function mapToFunctions(_, {
196210 onForward : ( sessionId , forwardNumber ) => webphone . forward ( sessionId , forwardNumber ) ,
197211 replyWithMessage : ( sessionId , message ) => webphone . replyWithMessage ( sessionId , message ) ,
198212 toggleMinimized : ( ) => webphone . toggleMinimized ( ) ,
213+ updateSessionMatchedContact : ( sessionId , contact ) =>
214+ webphone . updateSessionMatchedContact ( sessionId , contact ) ,
199215 getAvatarUrl,
200216 } ;
201217}
0 commit comments