Skip to content

Commit b79f585

Browse files
authored
save call contact match that selected (#295)
1 parent c623d71 commit b79f585

File tree

2 files changed

+61
-28
lines changed

2 files changed

+61
-28
lines changed

src/containers/CallCtrlPage/index.js

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@ class CallCtrlPage extends Component {
1515
constructor(props) {
1616
super(props);
1717

18+
let selectedMatcherIndex = 0;
19+
if (props.session.contactMatch) {
20+
selectedMatcherIndex = props.nameMatches.findIndex(match =>
21+
match.id === props.session.contactMatch.id
22+
);
23+
}
1824
this.state = {
19-
selectedMatcherIndex: 0,
25+
selectedMatcherIndex,
2026
avatarUrl: null,
2127
};
2228

@@ -26,10 +32,10 @@ class CallCtrlPage extends Component {
2632
selectedMatcherIndex: (index - 1),
2733
avatarUrl: null,
2834
});
29-
const nameMatches = this.props.session.direction === callDirections.outbound ?
30-
this.props.toMatches : this.props.fromMatches;
35+
const nameMatches = this.props.nameMatches;
3136
const contact = nameMatches && nameMatches[index - 1];
3237
if (contact) {
38+
this.props.updateSessionMatchedContact(this.props.session.id, contact);
3339
this.props.getAvatarUrl(contact).then((avatarUrl) => {
3440
this.setState({ avatarUrl });
3541
});
@@ -56,13 +62,19 @@ class CallCtrlPage extends Component {
5662

5763
componentWillReceiveProps(nextProps) {
5864
if (this.props.session.id !== nextProps.session.id) {
65+
let contact = nextProps.session.contactMatch;
66+
let selectedMatcherIndex = 0;
67+
if (!contact) {
68+
contact = nextProps.nameMatches && nextProps.nameMatches[0];
69+
} else {
70+
selectedMatcherIndex = nextProps.nameMatches.findIndex(match =>
71+
match.id === contact.id
72+
);
73+
}
5974
this.setState({
60-
selectedMatcherIndex: 0,
75+
selectedMatcherIndex,
6176
avatarUrl: null,
6277
});
63-
const nameMatches = nextProps.session.direction === callDirections.outbound ?
64-
nextProps.toMatches : nextProps.fromMatches;
65-
const contact = nameMatches && nameMatches[0];
6678
if (contact) {
6779
nextProps.getAvatarUrl(contact).then((avatarUrl) => {
6880
this.setState({ avatarUrl });
@@ -79,8 +91,6 @@ class CallCtrlPage extends Component {
7991
// isRinging = true;
8092
const phoneNumber = session.direction === callDirections.outbound ?
8193
session.to : session.from;
82-
const nameMatches = session.direction === callDirections.outbound ?
83-
this.props.toMatches : this.props.fromMatches;
8494
let fallbackUserName;
8595
if (session.direction === callDirections.inbound && session.from === 'anonymous') {
8696
fallbackUserName = i18n.getString('anonymous', this.props.currentLocale);
@@ -110,7 +120,7 @@ class CallCtrlPage extends Component {
110120
onKeyPadChange={this.onKeyPadChange}
111121
hangup={this.hangup}
112122
onAdd={this.props.onAdd}
113-
nameMatches={nameMatches}
123+
nameMatches={this.props.nameMatches}
114124
fallBackName={fallbackUserName}
115125
areaCode={this.props.areaCode}
116126
countryCode={this.props.countryCode}
@@ -134,6 +144,7 @@ CallCtrlPage.propTypes = {
134144
isOnRecord: PropTypes.bool,
135145
to: PropTypes.string,
136146
from: PropTypes.string,
147+
contactMatch: PropTypes.object,
137148
}).isRequired,
138149
currentLocale: PropTypes.string.isRequired,
139150
onMute: PropTypes.func.isRequired,
@@ -147,12 +158,12 @@ CallCtrlPage.propTypes = {
147158
formatPhone: PropTypes.func.isRequired,
148159
onAdd: PropTypes.func.isRequired,
149160
children: PropTypes.node,
150-
toMatches: PropTypes.array.isRequired,
151-
fromMatches: PropTypes.array.isRequired,
161+
nameMatches: PropTypes.array.isRequired,
152162
areaCode: PropTypes.string.isRequired,
153163
countryCode: PropTypes.string.isRequired,
154164
getAvatarUrl: PropTypes.func.isRequired,
155165
onBackButtonClick: PropTypes.func.isRequired,
166+
updateSessionMatchedContact: PropTypes.func.isRequired,
156167
};
157168

158169
CallCtrlPage.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
areaCode: regionSettings.areaCode,
@@ -198,8 +212,11 @@ function mapToFunctions(_, {
198212
onRecord: sessionId => webphone.startRecord(sessionId),
199213
onStopRecord: sessionId => webphone.stopRecord(sessionId),
200214
sendDTMF: (value, sessionId) => webphone.sendDTMF(value, sessionId),
215+
updateSessionMatchedContact: (sessionId, contact) =>
216+
webphone.updateSessionMatchedContact(sessionId, contact),
201217
getAvatarUrl,
202218
onBackButtonClick,
219+
onAdd,
203220
};
204221
}
205222

src/containers/IncomingCallPage/index.js

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

157168
IncomingCallPage.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

Comments
 (0)