Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #7316 from steveck-chung/sms-CharCounter

Bug 826614 - [SMS]  Refine characters counter and indicator in SMS application
  • Loading branch information...
commit 0a31d943f82dc46a1267189a06ed51f1e0faf53a 2 parents 39caebc + 9788355
Francisco Borja Salguero Castellano authored
Showing with 16 additions and 54 deletions.
  1. +0 −1  apps/sms/index.html
  2. +16 −53 apps/sms/js/sms.js
View
1  apps/sms/index.html
@@ -24,7 +24,6 @@
<link rel="resource" type="application/l10n" href="locales/locales.ini">
<link rel="resource" type="application/l10n" href="shared/locales/date.ini">
<!-- Shared code -->
- <script type="text/javascript" src="shared/js/settings_listener.js"></script>
<script type="text/javascript" src="shared/js/async_storage.js"></script>
<script type="text/javascript" src="shared/js/l10n.js"></script>
<script type="text/javascript" src="shared/js/l10n_date.js"></script>
View
69 apps/sms/js/sms.js
@@ -85,9 +85,7 @@ var MessageManager = {
var contactButton = document.getElementById('icon-contact');
contactButton.parentNode.appendChild(contactButton);
document.getElementById('messages-container').innerHTML = '';
- messageInput.value = '';
- receiverInput.value = '';
- ThreadUI.sendButton.disabled = true;
+ ThreadUI.cleanFields();
MessageManager.currentNum = null;
threadMessages.classList.add('new');
MessageManager.slide(function() {
@@ -733,9 +731,6 @@ var ThreadUI = {
return this.sendForm = document.getElementById('new-sms-form');
},
- // Does the operator force 7-bit encoding
- is7BitEncoding: false,
-
init: function thui_init() {
this.sendButton.addEventListener('click', this.sendMessage.bind(this));
@@ -775,23 +770,18 @@ var ThreadUI = {
this.editForm.addEventListener('submit', this);
this.telForm.addEventListener('submit', this);
this.sendForm.addEventListener('submit', this);
-
- var self = this;
- SettingsListener.observe('ril.sms.strict7BitEncoding.enabled',
- function onSMSEncodingChange(value) {
- self.is7BitEncoding = !!value;
- });
},
enableSend: function thui_enableSend() {
+ if (this.input.value.length > 0) {
+ this.updateCounter();
+ }
if (window.location.hash == '#new' && this.contactInput.value.length == 0) {
this.sendButton.disabled = true;
- this.updateCounter();
return;
}
this.sendButton.disabled = !(this.input.value.length > 0);
- this.updateCounter();
},
scrollViewToBottom: function thui_scrollViewToBottom(animateFromPos) {
@@ -813,50 +803,22 @@ var ThreadUI = {
}).bind(this), 100);
},
- has7BitOnlyCharacters: function thui_has7BitOnluCharacter(value) {
- for (var i = 0; i < value.length; i++) {
- if (value.charCodeAt(i) >= 128) {
- return false;
- }
- }
-
- return true;
- },
-
updateCounter: function thui_updateCount(evt) {
var value = this.input.value;
-
- // In theory the maximum concatenated number of SMS is 255.
- var kMaxConcatenatedMessages = 255;
- var excessive = false;
-
- // A sms can hold 140 bytes of data or 134 bytes of data depending
- // if it is a single or concatenated sms. To be fun the numbers of
- // sms also depends on the character encoding of the message.
- if (this.is7BitEncoding || this.has7BitOnlyCharacters(value)) {
- var kMaxCharsIfSingle = 160; // (140 * 8) / 7 = 160.
- var kMaxCharsIfMultiple = 153; // ((140 - 6) / 7 ~= 153.
- } else {
- var kMaxCharsIfSingle = 70; // (140 * 8) / 16 = 70.
- var kMaxCharsIfMultiple = 67; // ((140 - 6) / 16 = 67.
- }
-
+ // We set maximum concatenated number of our SMS app to 10 based on:
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=813686#c0
+ var kMaxConcatenatedMessages = 10;
+
+ // Use backend api for precise sms segmetation information.
+ var smsInfo = navigator.mozSms.getSegmentInfoForText(value);
+ var segments = smsInfo.segments;
+ var availableChars = smsInfo.charsAvailableInLastSegment;
var counter = '';
- var length = value.length;
- if ((length / kMaxCharsIfSingle) > 1) {
- var charsLeft = kMaxCharsIfMultiple - (length % kMaxCharsIfMultiple);
- var smsCount = Math.ceil(length / kMaxCharsIfMultiple);
- counter = charsLeft + '/' + smsCount;
-
- // Make sure the current number of sms is not bigger than the maximum
- // theorical number of sms that can be concatenate.
- if (smsCount > kMaxConcatenatedMessages) {
- excessive = true;
- }
+ if (segments > 1) {
+ counter = availableChars + '/' + segments;
}
-
this.sendButton.dataset.counter = counter;
- this.sendButton.disabled = excessive;
+ this.sendButton.disabled = (segments > kMaxConcatenatedMessages);
},
updateInputHeight: function thui_updateInputHeight() {
@@ -1210,6 +1172,7 @@ var ThreadUI = {
cleanFields: function thui_cleanFields() {
this.sendButton.disabled = true;
+ this.sendButton.dataset.counter = '';
this.contactInput.value = '';
this.input.value = '';
this.updateInputHeight();
Please sign in to comment.
Something went wrong with that request. Please try again.