Commit f2f05ff4 authored by JC Brand's avatar JC Brand

MUC: Don't show duplicate `join` messages.

parent 21fbb7b7
define("transcripts", [ define("transcripts", [
"tpl!converse-logs/conversejs.containers-1460718487729", "tpl!converse-logs/double_logins",
], function () { ], function () {
return arguments; return arguments;
}); });
...@@ -400,7 +400,7 @@ ...@@ -400,7 +400,7 @@
}).up() }).up()
.c('status', {code: '110'}); .c('status', {code: '110'});
_converse.connection._dataRecv(test_utils.createRequest(presence)); _converse.connection._dataRecv(test_utils.createRequest(presence));
expect($chat_content.find('div.chat-info:first').html()).toBe("some1 has joined the room"); expect($chat_content.find('div.chat-info:first').html()).toBe("some1 has joined the room.");
presence = $pres({ presence = $pres({
to: 'dummy@localhost/_converse.js-29092160', to: 'dummy@localhost/_converse.js-29092160',
...@@ -413,7 +413,20 @@ ...@@ -413,7 +413,20 @@
}); });
_converse.connection._dataRecv(test_utils.createRequest(presence)); _converse.connection._dataRecv(test_utils.createRequest(presence));
expect($chat_content.find('div.chat-info').length).toBe(2); expect($chat_content.find('div.chat-info').length).toBe(2);
expect($chat_content.find('div.chat-info:last').html()).toBe("newguy has joined the room"); expect($chat_content.find('div.chat-info:last').html()).toBe("newguy has joined the room.");
// Don't show duplicate join messages
presence = $pres({
to: 'dummy@localhost/_converse.js-290918392',
from: 'coven@chat.shakespeare.lit/newguy'
}).c('x', {xmlns: Strophe.NS.MUC_USER})
.c('item', {
'affiliation': 'none',
'jid': 'newguy@localhost/_converse.js-290929789',
'role': 'participant'
});
_converse.connection._dataRecv(test_utils.createRequest(presence));
expect($chat_content.find('div.chat-info').length).toBe(2);
presence = $pres({ presence = $pres({
to: 'dummy@localhost/_converse.js-29092160', to: 'dummy@localhost/_converse.js-29092160',
...@@ -1203,7 +1216,7 @@ ...@@ -1203,7 +1216,7 @@
expect($occupants.children().first(0).text()).toBe("oldnick"); expect($occupants.children().first(0).text()).toBe("oldnick");
expect($chat_content.find('div.chat-info').length).toBe(2); expect($chat_content.find('div.chat-info').length).toBe(2);
expect($chat_content.find('div.chat-info:first').html()).toBe("oldnick has joined the room"); expect($chat_content.find('div.chat-info:first').html()).toBe("oldnick has joined the room.");
expect($chat_content.find('div.chat-info:last').html()).toBe(__(_converse.muc.new_nickname_messages["210"], "oldnick")); expect($chat_content.find('div.chat-info:last').html()).toBe(__(_converse.muc.new_nickname_messages["210"], "oldnick"));
presence = $pres().attrs({ presence = $pres().attrs({
...@@ -1245,7 +1258,7 @@ ...@@ -1245,7 +1258,7 @@
_converse.connection._dataRecv(test_utils.createRequest(presence)); _converse.connection._dataRecv(test_utils.createRequest(presence));
expect($chat_content.find('div.chat-info').length).toBe(4); expect($chat_content.find('div.chat-info').length).toBe(4);
expect($chat_content.find('div.chat-info').get(2).textContent).toBe(__(_converse.muc.new_nickname_messages["303"], "newnick")); expect($chat_content.find('div.chat-info').get(2).textContent).toBe(__(_converse.muc.new_nickname_messages["303"], "newnick"));
expect($chat_content.find('div.chat-info').last().html()).toBe("newnick has joined the room"); expect($chat_content.find('div.chat-info').last().html()).toBe("newnick has joined the room.");
$occupants = view.$('.occupant-list'); $occupants = view.$('.occupant-list');
expect($occupants.children().length).toBe(1); expect($occupants.children().length).toBe(1);
expect($occupants.children().first(0).text()).toBe("newnick"); expect($occupants.children().first(0).text()).toBe("newnick");
......
...@@ -50,10 +50,10 @@ ...@@ -50,10 +50,10 @@
it("can be used to replay conversations", mock.initConverse(function (_converse) { it("can be used to replay conversations", mock.initConverse(function (_converse) {
/* /*
test_utils.openChatRoom(_converse, "dummy", 'rooms.localhost', 'jc'); test_utils.openAndEnterChatRoom(_converse, "dummy", 'rooms.localhost', 'jc');
test_utils.openChatRoom(_converse, "prosody", 'conference.prosody.im', 'jc'); test_utils.openAndEnterChatRoom(_converse, "prosody", 'conference.prosody.im', 'jc');
*/ */
test_utils.openChatRoom(_converse, "discuss", 'conference.conversejs.org', 'ee'); test_utils.openAndEnterChatRoom(_converse, "discuss", 'conference.conversejs.org', 'jc');
spyOn(_converse, 'areDesktopNotificationsEnabled').andReturn(true); spyOn(_converse, 'areDesktopNotificationsEnabled').andReturn(true);
_.each(transcripts, function (transcript) { _.each(transcripts, function (transcript) {
var text = transcript(); var text = transcript();
......
...@@ -1702,15 +1702,24 @@ ...@@ -1702,15 +1702,24 @@
// result look like the structure returned by // result look like the structure returned by
// parseXUserElement. Not nice... // parseXUserElement. Not nice...
var nick = Strophe.getResourceFromJid(stanza.getAttribute('from')); var nick = Strophe.getResourceFromJid(stanza.getAttribute('from'));
if (stanza.getAttribute('type') === 'unavailable') {
var stat = stanza.querySelector('status'); var stat = stanza.querySelector('status');
if (stanza.getAttribute('type') === 'unavailable') {
if (!_.isNull(stat) && stat.textContent) { if (!_.isNull(stat) && stat.textContent) {
return [{'messages': [__(nick+' has left the room. "'+stat.textContent+'"')]}]; return [{'messages': [__(nick+' has left the room. "'+stat.textContent+'"')]}];
} else { } else {
return [{'messages': [__(nick+' has left the room')]}]; return [{'messages': [__(nick+' has left the room')]}];
} }
} }
return [{'messages': [__(nick+' has joined the room')]}]; if (!this.occupantsview.model.find({'nick': nick})) {
// Only show join message if we don't already have the
// occupant model. Doing so avoids showing duplicate
// join messages.
if (!_.isNull(stat) && stat.textContent) {
return [{'messages': [__(nick+' has joined the room. "'+stat.textContent+'"')]}];
} else {
return [{'messages': [__(nick+' has joined the room.')]}];
}
}
}, },
showStatusMessages: function (stanza) { showStatusMessages: function (stanza) {
...@@ -1837,6 +1846,8 @@ ...@@ -1837,6 +1846,8 @@
this.getRoomFeatures(); this.getRoomFeatures();
} }
this.hideSpinner().showStatusMessages(pres); this.hideSpinner().showStatusMessages(pres);
// This must be called after showStatusMessages so that
// "join" messages are correctly shown.
this.occupantsview.updateOccupantsOnPresence(pres); this.occupantsview.updateOccupantsOnPresence(pres);
if (this.model.get('role') !== 'none' && if (this.model.get('role') !== 'none' &&
this.model.get('connection_status') === ROOMSTATUS.CONNECTING) { this.model.get('connection_status') === ROOMSTATUS.CONNECTING) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment