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

Commit

Permalink
Merge pull request #30279 from azasypkin/bug-1127398-participants-sen…
Browse files Browse the repository at this point in the history
…d-message

 Bug 1168941 - [Messages] Conversation view is rendered incorrectly when user tries to send message from Participants view. r=julien
  • Loading branch information
rvandermeulen committed Jun 3, 2015
2 parents 126e8f8 + 9fadd43 commit 5ef5d28
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 27 deletions.
52 changes: 38 additions & 14 deletions apps/sms/views/conversation/js/conversation.js
Expand Up @@ -513,16 +513,16 @@ var ConversationView = {
// get an event whenever the panel changes?
Threads.currentId = args.id;

var prevPanel = args.meta.prev && args.meta.prev.panel;
var prevPanel = args.meta.prev;

// If transitioning from composer, we don't need to notify about type
// conversion but only after the type of the thread is set
// (afterEnterThread)
if (prevPanel !== 'composer') {
if (!prevPanel || prevPanel.panel !== 'composer') {
this.enableConvertNoticeBanners();
}

if (prevPanel !== 'group-view' && prevPanel !== 'report-view') {
if (!this.isConversationPanel(args.id, prevPanel)) {
this.initializeRendering();
}

Expand Down Expand Up @@ -569,9 +569,9 @@ var ConversationView = {
afterEnterThread: function conv_afterEnterThread(args) {
var threadId = +args.id;

var prevPanel = args.meta.prev && args.meta.prev.panel;
var prevPanel = args.meta.prev;

if (prevPanel !== 'group-view' && prevPanel !== 'report-view') {
if (!this.isConversationPanel(threadId, prevPanel)) {
this.renderMessages(threadId);

// Populate draft if there is one
Expand Down Expand Up @@ -599,7 +599,7 @@ var ConversationView = {
});

// Enable notifications redirected from composer only after the user enters.
if (prevPanel === 'composer') {
if (prevPanel && prevPanel.panel === 'composer') {
this.enableConvertNoticeBanners();
}

Expand All @@ -613,7 +613,7 @@ var ConversationView = {
beforeLeave: function conv_beforeLeave(args) {
this.disableConvertNoticeBanners();

var nextPanel = args.meta.next && args.meta.next.panel;
var nextPanel = args.meta.next;

// This should be in afterLeave, but the edit mode interface does not seem
// to slide correctly. Bug 1009541
Expand All @@ -630,7 +630,7 @@ var ConversationView = {
}

// TODO move most of back() here: Bug 1010223
if (nextPanel !== 'group-view' && nextPanel !== 'report-view') {
if (!this.isConversationPanel(Threads.currentId, nextPanel)) {
this.cleanFields();
}
},
Expand Down Expand Up @@ -814,21 +814,45 @@ var ConversationView = {
TimeHeaders.updateAll('header[data-time-update]');
},

isCurrentThread: function conv_isCurrentThread(threadId) {
return Navigation.isCurrentPanel('thread', { id: threadId }) ||
/**
* Checks if specified conversation id is currently active. It can be true for
* either conversation, participants or report panels.
* @param {number} conversationId Id of the conversation.
* @returns {boolean}
*/
isCurrentConversation: function conv_isCurrentConversation(conversationId) {
return Navigation.isCurrentPanel('thread', { id: conversationId }) ||
Navigation.isCurrentPanel('report-view', {
threadId: threadId
threadId: conversationId
}) ||
Navigation.isCurrentPanel('group-view', {
id: threadId
id: conversationId
});
},

/**
* Checks if specified panel corresponds to the specified conversation id. It
* can be true for either conversation, participants or report panels.
* @param {number} conversationId Id of the conversation.
* @param {Object} panel Panel description object to compare against.
* @returns {boolean}
*/
isConversationPanel:
function conv_isConversationPanel(conversationId, panel) {
if (!panel) {
return false;
}

return panel.panel === 'thread' && panel.args.id === conversationId ||
panel.panel === 'report-view' && panel.args.threadId === conversationId ||
panel.panel === 'group-view' && panel.args.id === conversationId;
},

onMessageReceived: function conv_onMessageReceived(e) {
var message = e.message;

// If user currently in other thread then there is nothing to do here
if (!this.isCurrentThread(message.threadId)) {
if (!this.isCurrentConversation(message.threadId)) {
return;
}

Expand All @@ -843,7 +867,7 @@ var ConversationView = {

onMessageSending: function conv_onMessageReceived(e) {
var message = e.message;
if (this.isCurrentThread(message.threadId)) {
if (this.isCurrentConversation(message.threadId)) {
this.onMessage(message);
this.forceScrollViewToBottom();
} else {
Expand Down
59 changes: 46 additions & 13 deletions apps/sms/views/conversation/test/unit/conversation_test.js
Expand Up @@ -6117,7 +6117,7 @@ suite('conversation.js >', function() {
});
});

suite('isCurrentThread(current threadId is 1)', function() {
suite('isCurrentConversation(current threadId is 1)', function() {
setup(function() {
this.sinon.stub(Navigation, 'isCurrentPanel').returns(false);
});
Expand All @@ -6126,25 +6126,58 @@ suite('conversation.js >', function() {
test('check thread panel with threadId is' + id, function() {
Navigation.isCurrentPanel.withArgs('thread', { id: 1 }).returns(true);

assert.equal(ConversationView.isCurrentThread(id), id === 1);
assert.equal(ConversationView.isCurrentConversation(id), id === 1);
});

test('check report panel with threadId is' + id, function() {
Navigation.isCurrentPanel.withArgs(
'report-view',
{ threadId: 1 }
'report-view', { threadId: 1 }
).returns(true);

assert.equal(ConversationView.isCurrentThread(id), id === 1);
assert.equal(ConversationView.isCurrentConversation(id), id === 1);
});

test('check group panel with threadId is' + id, function() {
Navigation.isCurrentPanel.withArgs(
'group-view',
{ id: 1 }
'group-view', { id: 1 }
).returns(true);

assert.equal(ConversationView.isCurrentThread(id), id === 1);
assert.equal(ConversationView.isCurrentConversation(id), id === 1);
});
});
});

suite('isConversationPanel(threadId is 1)', function() {
test('panel description is not available', function() {
assert.isFalse(ConversationView.isConversationPanel(1, null));
});

[1, 2].forEach((id) => {
test('check thread panel with threadId is' + id, function() {
var panel = {
panel: 'thread',
args: { id: 1 }
};

assert.equal(ConversationView.isConversationPanel(id, panel), id === 1);
});

test('check report panel with threadId is' + id, function() {
var panel = {
panel: 'report-view',
args: { threadId: 1 }
};

assert.equal(ConversationView.isConversationPanel(id, panel), id === 1);
});

test('check group panel with threadId is' + id, function() {
var panel = {
panel: 'group-view',
args: { id: 1 }
};

assert.equal(ConversationView.isConversationPanel(id, panel), id === 1);
});
});
});
Expand All @@ -6154,15 +6187,15 @@ suite('conversation.js >', function() {

setup(function() {
this.sinon.stub(ConversationView, 'appendMessage');
this.sinon.stub(ConversationView, 'isCurrentThread').returns(false);
this.sinon.stub(ConversationView, 'isCurrentConversation').returns(false);

this.sinon.spy(Navigation, 'toPanel');
});

test('should append message if the user is in correct thread', function() {
// not implemented yet: https://github.com/cjohansen/Sinon.JS/issues/461
// Navigation.isCurrentPanel.withExactArgs('thread').returns(true);
ConversationView.isCurrentThread.withArgs(1).returns(true);
ConversationView.isCurrentConversation.withArgs(1).returns(true);

var message = MockMessages.sms({
threadId: 1
Expand Down Expand Up @@ -6193,7 +6226,7 @@ suite('conversation.js >', function() {

suite('onMessageReceived >', function() {
setup(function() {
this.sinon.stub(ConversationView, 'isCurrentThread').returns(false);
this.sinon.stub(ConversationView, 'isCurrentConversation').returns(false);
this.sinon.spy(MessageManager, 'markMessagesRead');
});

Expand All @@ -6214,7 +6247,7 @@ suite('conversation.js >', function() {
threadId: 1
});

ConversationView.isCurrentThread.withArgs(1).returns(true);
ConversationView.isCurrentConversation.withArgs(1).returns(true);

MessageManager.on.withArgs('message-received').yield({
message: message
Expand Down Expand Up @@ -6923,7 +6956,7 @@ suite('conversation.js >', function() {
setup(function() {
transitionArgs.meta.prev = {
panel: 'report-view',
args: { id: 1 }
args: { id: 1, threadId: threadId }
};

setActiveThread(threadId);
Expand Down

0 comments on commit 5ef5d28

Please sign in to comment.