Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Bug 885264 - [SMS/MMS] Ensure Carrier is not displayed for manually e…
Browse files Browse the repository at this point in the history
…ntered (unknown contact) recipients

1. If a phone number has carrier associated with it
    the output will be:

  type | carrier

2. If there is no carrier associated with the phone number
    the output will be:

  type | phonenumber

3. If for some reason a single contact has two phone numbers with
    the same type and the same carrier the output will be:

  type | phonenumber

4. If for some reason a single contact has no name and no carrier,
    the output will be:

  type

5. If for some reason a single contact has no name, no type
    and no carrier, the output will be nothing.

https://bugzilla.mozilla.org/show_bug.cgi?id=885264
Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
  • Loading branch information
rwaldron committed Jun 27, 2013
1 parent 12a6565 commit eb02e61
Show file tree
Hide file tree
Showing 6 changed files with 323 additions and 143 deletions.
3 changes: 2 additions & 1 deletion apps/sms/js/desktop_contacts_mock.js
Expand Up @@ -272,7 +272,8 @@
familyName: 'Shannon',
givenName: 'Claude',
tel: {
value: '103'
value: '103',
type: 'Mobile'
}
})
);
Expand Down
31 changes: 21 additions & 10 deletions apps/sms/js/thread_ui.js
Expand Up @@ -822,15 +822,11 @@ var ThreadUI = global.ThreadUI = {
//
Contacts.findByPhoneNumber(number, function gotContact(contacts) {
var carrierTag = document.getElementById('contact-carrier');
/** If we have more than one contact sharing the same phone number
* we show the title of contact detail with validate name/company
* and how many other contacts share that same number. We think it's
* user's responsability to correct this mess with the agenda.
*/
// Bug 867948: contacts null is a legitimate case, and
// getContactDetails is okay with that.
var details = Utils.getContactDetails(number, contacts);
var contactName = details.title || number;
var carrierText;

this.headerText.dataset.isContact = !!details.isContact;
this.headerText.textContent = navigator.mozL10n.get(
Expand All @@ -841,14 +837,29 @@ var ThreadUI = global.ThreadUI = {

// The carrier banner is meaningless and confusing in
// group message mode.
if (thread.participants.length === 1) {
if (contacts && contacts.length) {
carrierTag.textContent = Utils.getContactCarrier(
number, contacts[0].tel
);
if (thread.participants.length === 1 &&
(contacts && contacts.length)) {


carrierText = Utils.getCarrierTag(
number, contacts[0].tel, details
);

// Known Contact with at least:
//
// 1. a name
// 2. a carrier
// 3. a type
//

if (carrierText) {
carrierTag.textContent = carrierText;
carrierTag.classList.remove('hide');
} else {
carrierTag.classList.add('hide');
}
} else {
// Hide carrier tag in group message or unknown contact cases.
carrierTag.classList.add('hide');
}

Expand Down
30 changes: 20 additions & 10 deletions apps/sms/js/utils.js
Expand Up @@ -216,32 +216,37 @@
return details;
},

getContactCarrier: function(input, tels) {
getCarrierTag: function ut_getCarrierTag(input, tels, details) {
/**
1. If a phone number has carrier associated with it
the output will be:
Firstname Lastname
type | carrier
2. If there is no carrier associated with the phone number
the output will be:
Firstname Lastname
type | phonenumber
3. If for some reason a single contact has two phone numbers with
the same type and the same carrier the output will be:
Firstname Lastname
type | phonenumber
*/
4. If for some reason a single contact has no name and no carrier,
the output will be:
type
5. If for some reason a single contact has no name, no type
and no carrier, the output will be nothing.
*/
var length = tels.length;
var hasDetails = typeof details !== 'undefined';
var hasUniqueCarriers = true;
var hasUniqueTypes = true;
var found, tel, type, carrier, value;
var name = hasDetails ? details.name : '';
var found, tel, type, carrier, value, ending;

for (var i = 0; i < length; i++) {
tel = tels[i];
Expand All @@ -259,18 +264,23 @@
}

carrier = tel.carrier;
type = tel.type[0];
type = (tel.type && tel.type[0]) || '';
}

if (!found) {
return '';
}

type = found.type[0];
carrier = hasUniqueCarriers || hasUniqueTypes ? found.carrier : '';
type = (found.type && found.type[0]) || '';
carrier = (hasUniqueCarriers || hasUniqueTypes) ? found.carrier : '';
value = carrier || found.value;
ending = ' | ' + (carrier || value);

if (hasDetails && !name && !carrier) {
ending = '';
}

return type + ' | ' + (carrier || value);
return type + ending;
},

// Based on "non-dialables" in https://github.com/andreasgal/PhoneNumber.js
Expand Down
1 change: 1 addition & 0 deletions apps/sms/test/unit/mock_utils.js
Expand Up @@ -20,6 +20,7 @@ var MockUtils = {
params: Utils.params,
getContactDetails: Utils.getContactDetails,
getResizedImgBlob: Utils.getResizedImgBlob,
getCarrierTag: Utils.getCarrierTag,
removeNonDialables: Utils.removeNonDialables,
compareDialables: Utils.compareDialables
};

1 comment on commit eb02e61

@rwaldron
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit is r=julienw (I failed to rewrite the commit message)

Please sign in to comment.