Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 31 additions & 14 deletions src/containers/CallCtrlPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ class CallCtrlPage extends Component {
constructor(props) {
super(props);

let selectedMatcherIndex = 0;
if (props.session.contactMatch) {
selectedMatcherIndex = props.nameMatches.findIndex(match =>
match.id === props.session.contactMatch.id
);
}
this.state = {
selectedMatcherIndex: 0,
selectedMatcherIndex,
avatarUrl: null,
};

Expand All @@ -26,10 +32,10 @@ class CallCtrlPage extends Component {
selectedMatcherIndex: (index - 1),
avatarUrl: null,
});
const nameMatches = this.props.session.direction === callDirections.outbound ?
this.props.toMatches : this.props.fromMatches;
const nameMatches = this.props.nameMatches;
const contact = nameMatches && nameMatches[index - 1];
if (contact) {
this.props.updateSessionMatchedContact(this.props.session.id, contact);
this.props.getAvatarUrl(contact).then((avatarUrl) => {
this.setState({ avatarUrl });
});
Expand All @@ -56,13 +62,19 @@ class CallCtrlPage extends Component {

componentWillReceiveProps(nextProps) {
if (this.props.session.id !== nextProps.session.id) {
let contact = nextProps.session.contactMatch;
let selectedMatcherIndex = 0;
if (!contact) {
contact = nextProps.nameMatches && nextProps.nameMatches[0];
} else {
selectedMatcherIndex = nextProps.nameMatches.findIndex(match =>
match.id === contact.id
);
}
this.setState({
selectedMatcherIndex: 0,
selectedMatcherIndex,
avatarUrl: null,
});
const nameMatches = nextProps.session.direction === callDirections.outbound ?
nextProps.toMatches : nextProps.fromMatches;
const contact = nameMatches && nameMatches[0];
if (contact) {
nextProps.getAvatarUrl(contact).then((avatarUrl) => {
this.setState({ avatarUrl });
Expand All @@ -79,8 +91,6 @@ class CallCtrlPage extends Component {
// isRinging = true;
const phoneNumber = session.direction === callDirections.outbound ?
session.to : session.from;
const nameMatches = session.direction === callDirections.outbound ?
this.props.toMatches : this.props.fromMatches;
let fallbackUserName;
if (session.direction === callDirections.inbound && session.from === 'anonymous') {
fallbackUserName = i18n.getString('anonymous', this.props.currentLocale);
Expand Down Expand Up @@ -110,7 +120,7 @@ class CallCtrlPage extends Component {
onKeyPadChange={this.onKeyPadChange}
hangup={this.hangup}
onAdd={this.props.onAdd}
nameMatches={nameMatches}
nameMatches={this.props.nameMatches}
fallBackName={fallbackUserName}
areaCode={this.props.areaCode}
countryCode={this.props.countryCode}
Expand All @@ -134,6 +144,7 @@ CallCtrlPage.propTypes = {
isOnRecord: PropTypes.bool,
to: PropTypes.string,
from: PropTypes.string,
contactMatch: PropTypes.object,
}).isRequired,
currentLocale: PropTypes.string.isRequired,
onMute: PropTypes.func.isRequired,
Expand All @@ -147,12 +158,12 @@ CallCtrlPage.propTypes = {
formatPhone: PropTypes.func.isRequired,
onAdd: PropTypes.func.isRequired,
children: PropTypes.node,
toMatches: PropTypes.array.isRequired,
fromMatches: PropTypes.array.isRequired,
nameMatches: PropTypes.array.isRequired,
areaCode: PropTypes.string.isRequired,
countryCode: PropTypes.string.isRequired,
getAvatarUrl: PropTypes.func.isRequired,
onBackButtonClick: PropTypes.func.isRequired,
updateSessionMatchedContact: PropTypes.func.isRequired,
};

CallCtrlPage.defaultProps = {
Expand All @@ -167,9 +178,12 @@ function mapToProps(_, {
}) {
const currentSession = webphone.currentSession || {};
const contactMapping = contactMatcher && contactMatcher.dataMapping;
const fromMatches = (contactMapping && contactMapping[currentSession.from]) || [];
const toMatches = (contactMapping && contactMapping[currentSession.to]) || [];
const nameMatches =
currentSession.direction === callDirections.outbound ? toMatches : fromMatches;
return {
fromMatches: (contactMapping && contactMapping[currentSession.from]) || [],
toMatches: (contactMapping && contactMapping[currentSession.to]) || [],
nameMatches,
currentLocale: locale.currentLocale,
session: currentSession,
areaCode: regionSettings.areaCode,
Expand Down Expand Up @@ -198,8 +212,11 @@ function mapToFunctions(_, {
onRecord: sessionId => webphone.startRecord(sessionId),
onStopRecord: sessionId => webphone.stopRecord(sessionId),
sendDTMF: (value, sessionId) => webphone.sendDTMF(value, sessionId),
updateSessionMatchedContact: (sessionId, contact) =>
webphone.updateSessionMatchedContact(sessionId, contact),
getAvatarUrl,
onBackButtonClick,
onAdd,
};
}

Expand Down
44 changes: 30 additions & 14 deletions src/containers/IncomingCallPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ class IncomingCallPage extends Component {
constructor(props) {
super(props);

let selectedMatcherIndex = 0;
if (props.session.contactMatch) {
selectedMatcherIndex = props.nameMatches.findIndex(match =>
match.id === props.session.contactMatch.id
);
}
this.state = {
selectedMatcherIndex: 0,
selectedMatcherIndex,
avatarUrl: null,
};

Expand All @@ -29,10 +35,10 @@ class IncomingCallPage extends Component {
selectedMatcherIndex: (index - 1),
avatarUrl: null,
});
const nameMatches = this.props.session.direction === callDirections.outbound ?
this.props.toMatches : this.props.fromMatches;
const nameMatches = this.props.nameMatches;
const contact = nameMatches && nameMatches[index - 1];
if (contact) {
this.props.updateSessionMatchedContact(this.props.session.id, contact);
this.props.getAvatarUrl(contact).then((avatarUrl) => {
this.setState({ avatarUrl });
});
Expand All @@ -53,13 +59,19 @@ class IncomingCallPage extends Component {

componentWillReceiveProps(nextProps) {
if (this.props.session.id !== nextProps.session.id) {
let selectedMatcherIndex = 0;
let contact = nextProps.session.contactMatch;
if (!contact) {
contact = nextProps.nameMatches && nextProps.nameMatches[0];
} else {
selectedMatcherIndex = nextProps.nameMatches.findIndex(match =>
match.id === contact.id
);
}
this.setState({
selectedMatcherIndex: 0,
selectedMatcherIndex,
avatarUrl: null,
});
const nameMatches = nextProps.session.direction === callDirections.outbound ?
nextProps.toMatches : nextProps.fromMatches;
const contact = nameMatches && nameMatches[0];
if (contact) {
nextProps.getAvatarUrl(contact).then((avatarUrl) => {
this.setState({ avatarUrl });
Expand Down Expand Up @@ -90,8 +102,6 @@ class IncomingCallPage extends Component {
}
const phoneNumber = session.direction === callDirections.outbound ?
session.to : session.from;
const nameMatches = session.direction === callDirections.outbound ?
this.props.toMatches : this.props.fromMatches;
let fallbackUserName;
if (session.direction === callDirections.inbound && session.from === 'anonymous') {
fallbackUserName = i18n.getString('anonymous', this.props.currentLocale);
Expand All @@ -102,7 +112,7 @@ class IncomingCallPage extends Component {
return (
<IncomingCallPanel
currentLocale={this.props.currentLocale}
nameMatches={nameMatches}
nameMatches={this.props.nameMatches}
fallBackName={fallbackUserName}
phoneNumber={phoneNumber}
answer={this.answer}
Expand Down Expand Up @@ -135,6 +145,7 @@ IncomingCallPage.propTypes = {
isOnRecord: PropTypes.bool,
to: PropTypes.string,
from: PropTypes.string,
contactMatch: PropTypes.object,
}).isRequired,
currentLocale: PropTypes.string.isRequired,
minimized: PropTypes.bool.isRequired,
Expand All @@ -145,13 +156,13 @@ IncomingCallPage.propTypes = {
replyWithMessage: PropTypes.func.isRequired,
formatPhone: PropTypes.func.isRequired,
children: PropTypes.node,
toMatches: PropTypes.array.isRequired,
fromMatches: PropTypes.array.isRequired,
nameMatches: PropTypes.array.isRequired,
areaCode: PropTypes.string.isRequired,
countryCode: PropTypes.string.isRequired,
getAvatarUrl: PropTypes.func.isRequired,
forwardingNumbers: PropTypes.array.isRequired,
onForward: PropTypes.func.isRequired,
updateSessionMatchedContact: PropTypes.func.isRequired,
};

IncomingCallPage.defaultProps = {
Expand All @@ -167,9 +178,12 @@ function mapToProps(_, {
}) {
const currentSession = webphone.currentSession || {};
const contactMapping = contactMatcher && contactMatcher.dataMapping;
const fromMatches = (contactMapping && contactMapping[currentSession.from]) || [];
const toMatches = (contactMapping && contactMapping[currentSession.to]) || [];
const nameMatches =
currentSession.direction === callDirections.outbound ? toMatches : fromMatches;
return {
fromMatches: (contactMapping && contactMapping[currentSession.from]) || [],
toMatches: (contactMapping && contactMapping[currentSession.to]) || [],
nameMatches,
currentLocale: locale.currentLocale,
session: currentSession,
minimized: webphone.minimized,
Expand All @@ -196,6 +210,8 @@ function mapToFunctions(_, {
onForward: (sessionId, forwardNumber) => webphone.forward(sessionId, forwardNumber),
replyWithMessage: (sessionId, message) => webphone.replyWithMessage(sessionId, message),
toggleMinimized: () => webphone.toggleMinimized(),
updateSessionMatchedContact: (sessionId, contact) =>
webphone.updateSessionMatchedContact(sessionId, contact),
getAvatarUrl,
};
}
Expand Down