Bug 851032 - [SMS] Receiving a new message it's not properly threaded r=julienw #8716
Changes from all commits
7e6f7d4
a9d3907
86a0ac7
7f05a32
83c4bec
91b893b
440d99d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,10 @@ var MessageManager = { | |
var message = e.message; | ||
var num = message.receiver; | ||
if (window.location.hash == '#new') { | ||
// We update the currentThread | ||
if (!MessageManager.currentThread) { | ||
MessageManager.currentThread = message.threadId; | ||
} | ||
// If we are in 'new' we go to the right thread | ||
// 'num' has been internationalized by Gecko | ||
window.location.hash = '#num=' + num; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are we still use this hash ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently there is no |
||
|
@@ -56,6 +60,7 @@ var MessageManager = { | |
// thread without requesting Gecko, so we increase the performance and we | ||
// reduce Gecko requests. | ||
return { | ||
id: message.threadId, | ||
senderOrReceiver: message.sender, | ||
body: message.body, | ||
timestamp: message.timestamp, | ||
|
@@ -66,14 +71,10 @@ var MessageManager = { | |
onMessageReceived: function mm_onMessageReceived(e) { | ||
var message = e.message; | ||
|
||
var num; | ||
if (this.currentNum) { | ||
num = this.currentNum; | ||
} | ||
|
||
var sender = message.sender; | ||
if (num && num === sender) { | ||
//Append message and mark as unread | ||
var currentThread = this.currentThread; | ||
var threadId = message.threadId; | ||
if (currentThread != null && currentThread === threadId) { | ||
// Append message and mark as read | ||
this.markMessagesRead([message.id], true, function() { | ||
MessageManager.getThreads(ThreadListUI.renderThreads); | ||
}); | ||
|
@@ -120,8 +121,8 @@ var MessageManager = { | |
onVisibilityChange: function mm_onVisibilityChange(e) { | ||
LinkActionHandler.resetActivityInProgress(); | ||
ThreadListUI.updateContactsInfo(); | ||
ThreadUI.updateHeaderData(); | ||
Utils.updateTimeHeaders(); | ||
ThreadUI.updateHeaderData(); | ||
}, | ||
|
||
slide: function mm_slide(callback) { | ||
|
@@ -164,7 +165,7 @@ var MessageManager = { | |
contactButton.parentNode.appendChild(contactButton); | ||
document.getElementById('messages-container').innerHTML = ''; | ||
ThreadUI.cleanFields(); | ||
MessageManager.currentNum = null; | ||
MessageManager.currentThread = null; | ||
threadMessages.classList.add('new'); | ||
MessageManager.slide(function() { | ||
receiverInput.focus(); | ||
|
@@ -174,7 +175,7 @@ var MessageManager = { | |
//Keep the visible button the :last-child | ||
var editButton = document.getElementById('icon-edit'); | ||
editButton.parentNode.appendChild(editButton); | ||
MessageManager.currentNum = null; | ||
MessageManager.currentThread = null; | ||
if (mainWrapper.classList.contains('edit')) { | ||
mainWrapper.classList.remove('edit'); | ||
if (ThreadListUI.editDone) { | ||
|
@@ -211,14 +212,13 @@ var MessageManager = { | |
var num = this.getNumFromHash(); | ||
if (num) { | ||
var filter = this.createFilter(num); | ||
var input = document.getElementById('messages-input'); | ||
MessageManager.currentNum = num; | ||
|
||
if (mainWrapper.classList.contains('edit')) { | ||
mainWrapper.classList.remove('edit'); | ||
} else if (threadMessages.classList.contains('new')) { | ||
ThreadUI.updateHeaderData(); | ||
ThreadUI.renderMessages(filter); | ||
threadMessages.classList.remove('new'); | ||
ThreadUI.updateHeaderData(); | ||
} else { | ||
// As soon as we click in the thread, we visually mark it | ||
// as read. | ||
|
@@ -227,7 +227,8 @@ var MessageManager = { | |
threadRead.getElementsByTagName('a')[0].classList | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (I hate github for this: I'd like to comment the context that is before that) Why not using the thread id instead of the number as the thread HTML id ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as before. Currently the whole model and API it's based on the number. This is changing, but currently we have to keep it because it's more relevant the phone number than ID by now. |
||
.remove('unread'); | ||
} | ||
|
||
// Update the currentThread | ||
MessageManager.currentThread = threadRead.dataset.threadId; | ||
var self = this; | ||
// Update Header | ||
ThreadUI.updateHeaderData(function headerReady() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -269,6 +269,7 @@ var ThreadListUI = { | |
var threadDOM = document.createElement('li'); | ||
threadDOM.id = 'thread_' + num; | ||
threadDOM.dataset.time = timestamp; | ||
threadDOM.dataset.threadId = thread.id; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's put the thread_id in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and you can put the phoneNumber in the dataset instead. Which really makes sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change will come when the paradigm will be complete, and we have |
||
|
||
// Retrieving params from thread | ||
var bodyText = (thread.body || '').split('\n')[0]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -372,6 +372,15 @@ var ThreadUI = { | |
}, | ||
// Method for updating the header with the info retrieved from Contacts API | ||
updateHeaderData: function thui_updateHeaderData(callback) { | ||
if (MessageManager.currentThread === null) { | ||
return; | ||
} | ||
// Retrieve phone number from Hash | ||
var number = MessageManager.getNumFromHash(); | ||
// Add data to contact activity interaction | ||
this.headerText.dataset.phoneNumber = number; | ||
this.headerText.textContent = number; | ||
|
||
// For Desktop Testing, mozContacts it's mockuped but it's not working | ||
// completely. So in the case of Desktop testing we are going to execute | ||
// the callback directly in order to make it works! | ||
|
@@ -381,13 +390,6 @@ var ThreadUI = { | |
return; | ||
} | ||
|
||
var number = MessageManager.currentNum; | ||
if (!number) { | ||
return; | ||
} | ||
|
||
// Add data to contact activity interaction | ||
this.headerText.dataset.phoneNumber = number; | ||
|
||
Contacts.findByString(number, function gotContact(contacts) { | ||
var carrierTag = document.getElementById('contact-carrier'); | ||
|
@@ -778,8 +780,8 @@ var ThreadUI = { | |
this.noResults.classList.add('hide'); | ||
this.container.classList.remove('hide'); | ||
|
||
if (resendText && typeof resendText === 'string') { | ||
num = MessageManager.currentNum; | ||
if (resendText && (typeof(resendText) === 'string') && resendText !== '') { | ||
num = MessageManager.getNumFromHash(); | ||
text = resendText; | ||
} else { | ||
// Retrieve num depending on hash | ||
|
@@ -791,7 +793,7 @@ var ThreadUI = { | |
return; | ||
} | ||
} else { | ||
num = MessageManager.currentNum; | ||
num = MessageManager.getNumFromHash(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. idem |
||
} | ||
|
||
// Retrieve text | ||
|
@@ -802,10 +804,6 @@ var ThreadUI = { | |
} | ||
// Clean fields (this lock any repeated click in 'send' button) | ||
this.cleanFields(true); | ||
// Remove when | ||
// https://bugzilla.mozilla.org/show_bug.cgi?id=825604 landed | ||
MessageManager.currentNum = num; | ||
this.updateHeaderData(); | ||
// Send the SMS | ||
MessageManager.send(num, text); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are you sure this is not necessary ? bug 825604 hasn't landed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've changed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes but we do have the number here (because we're sending to it) so maybe we could pass it directly to updateHeaderData as a parameter ? I'll see how it feels as soon as I'll have a working build, maybe it is good enough like that |
||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say we could do the vibration in our
MessageManager.onMessageReceived
instead.but since this is a tef+ bug let's keep that here now.