Commit 8e3c97ae authored by JC Brand's avatar JC Brand

Some fixes to minimization of chats. Updates #622

Don't call trimChats in onChatBoxAdded event. Reduntant because it will be
called after maximization and after being shown.

Add new method getShownChats and don't trim if only one or zero chats are being
shown.

Don't trim chats when in responsive mode.

Don't call trimChats unnecessarily in the render method of the trimmed chats
thingy.
parent 868aacb2
...@@ -3857,18 +3857,10 @@ define("polyfill", function(){}); ...@@ -3857,18 +3857,10 @@ define("polyfill", function(){});
}, },
onChatBoxAdded: function (item) { onChatBoxAdded: function (item) {
var view = this.get(item.get('id')); // Views aren't created here, since the core code doesn't
// Views aren't created here, since the core code doesn't have
// contain any views. Instead, they're created in overrides in // contain any views. Instead, they're created in overrides in
// converse-chatiew.js and/or converse-muc.js // plugins, such as in converse-chatview.js and converse-muc.js
if (view) { return this.get(item.get('id'));
// This is an optimization. We don't remove older views, so
// when one is available, we reuse it.
delete view.model; // Remove ref to old model to help garbage collection
view.model = item;
view.initialize();
}
return view;
}, },
removeChat: function (item) { removeChat: function (item) {
...@@ -4344,9 +4336,14 @@ define("polyfill", function(){}); ...@@ -4344,9 +4336,14 @@ define("polyfill", function(){});
'initialize': function (settings, callback) { 'initialize': function (settings, callback) {
converse.initialize(settings, callback); converse.initialize(settings, callback);
}, },
'connection': {
'connected': function () {
return converse.connection && converse.connection.connected || false;
},
'disconnect': function () { 'disconnect': function () {
converse.connection.disconnect(); converse.connection.disconnect();
}, },
},
'user': { 'user': {
'logout': function () { 'logout': function () {
converse.logOut(); converse.logOut();
...@@ -4474,7 +4471,7 @@ define("polyfill", function(){}); ...@@ -4474,7 +4471,7 @@ define("polyfill", function(){});
converse.connection.addHandler( converse.connection.addHandler(
handler, handler,
options.ns, options.ns,
options.name, name,
options.type, options.type,
options.id, options.id,
options.from, options.from,
...@@ -5680,6 +5677,7 @@ return parser; ...@@ -5680,6 +5677,7 @@ return parser;
}, },
onScroll: function (ev) { onScroll: function (ev) {
// XXX: This should go into converse-mam.js
if ($(ev.target).scrollTop() === 0 && this.model.messages.length) { if ($(ev.target).scrollTop() === 0 && this.model.messages.length) {
this.fetchArchivedMessages({ this.fetchArchivedMessages({
'before': this.model.messages.at(0).get('archive_id'), 'before': this.model.messages.at(0).get('archive_id'),
...@@ -5698,6 +5696,7 @@ return parser; ...@@ -5698,6 +5696,7 @@ return parser;
this.model.messages.fetch({ this.model.messages.fetch({
'add': true, 'add': true,
'success': function () { 'success': function () {
// XXX: This should go into converse-mam.js
if (!converse.features.findWhere({'var': Strophe.NS.MAM})) { if (!converse.features.findWhere({'var': Strophe.NS.MAM})) {
return; return;
} }
...@@ -5719,6 +5718,7 @@ return parser; ...@@ -5719,6 +5718,7 @@ return parser;
* Then, upon receiving them, call onMessage on the chat box, * Then, upon receiving them, call onMessage on the chat box,
* so that they are displayed inside it. * so that they are displayed inside it.
*/ */
// XXX: This should go into converse-mam.js
if (!converse.features.findWhere({'var': Strophe.NS.MAM})) { if (!converse.features.findWhere({'var': Strophe.NS.MAM})) {
converse.log("Attempted to fetch archived messages but this user's server doesn't support XEP-0313"); converse.log("Attempted to fetch archived messages but this user's server doesn't support XEP-0313");
return; return;
...@@ -7501,10 +7501,16 @@ return parser; ...@@ -7501,10 +7501,16 @@ return parser;
ChatBoxViews: { ChatBoxViews: {
onChatBoxAdded: function (item) { onChatBoxAdded: function (item) {
if (item.get('box_id') === 'controlbox') {
var view = this.get(item.get('id')); var view = this.get(item.get('id'));
if (!view && item.get('box_id') === 'controlbox') { if (view) {
view.model = item;
view.initialize();
return view;
} else {
view = new converse.ControlBoxView({model: item}); view = new converse.ControlBoxView({model: item});
return this.add(item.get('id'), view); return this.add(item.get('id'), view);
}
} else { } else {
return this._super.onChatBoxAdded.apply(this, arguments); return this._super.onChatBoxAdded.apply(this, arguments);
} }
...@@ -9932,10 +9938,6 @@ return parser; ...@@ -9932,10 +9938,6 @@ return parser;
return chatbox; return chatbox;
}, },
onChatBoxAdded: function (item) {
this.trimChats(this._super.onChatBoxAdded.apply(this, arguments));
},
getChatBoxWidth: function (view) { getChatBoxWidth: function (view) {
if (!view.model.get('minimized') && view.$el.is(':visible')) { if (!view.model.get('minimized') && view.$el.is(':visible')) {
return view.$el.outerWidth(true); return view.$el.outerWidth(true);
...@@ -9943,6 +9945,12 @@ return parser; ...@@ -9943,6 +9945,12 @@ return parser;
return 0; return 0;
}, },
getShownChats: function () {
return this.filter(function (view) {
return (!view.model.get('minimized') && view.$el.is(':visible'));
});
},
trimChats: function (newchat) { trimChats: function (newchat) {
/* This method is called when a newly created chat box will /* This method is called when a newly created chat box will
* be shown. * be shown.
...@@ -9951,7 +9959,14 @@ return parser; ...@@ -9951,7 +9959,14 @@ return parser;
* another chat box. Otherwise it minimizes the oldest chat box * another chat box. Otherwise it minimizes the oldest chat box
* to create space. * to create space.
*/ */
if (converse.no_trimming || (this.model.length <= 1)) { var shown_chats = this.getShownChats();
if (converse.no_trimming || shown_chats.length <= 1) {
return;
}
if (this.getChatBoxWidth(shown_chats[0]) === $('body').outerWidth(true)) {
// If the chats shown are the same width as the body,
// then we're in responsive mode and the chats are
// fullscreen. In this case we don't trim.
return; return;
} }
var oldest_chat, boxes_width, view, var oldest_chat, boxes_width, view,
...@@ -10107,7 +10122,7 @@ return parser; ...@@ -10107,7 +10122,7 @@ return parser;
render: function () { render: function () {
if (this.keys().length === 0) { if (this.keys().length === 0) {
this.$el.hide('fast', converse.chatboxviews.trimChats.bind(converse.chatboxviews)); this.$el.hide('fast', converse.chatboxviews.trimChats.bind(converse.chatboxviews));
} else if (this.keys().length === 1) { } else if (this.keys().length === 1 && !this.$el.is(':visible')) {
this.$el.show('fast', converse.chatboxviews.trimChats.bind(converse.chatboxviews)); this.$el.show('fast', converse.chatboxviews.trimChats.bind(converse.chatboxviews));
} }
return this.$el; return this.$el;
......
...@@ -29656,18 +29656,10 @@ return Backbone.BrowserStorage; ...@@ -29656,18 +29656,10 @@ return Backbone.BrowserStorage;
}, },
onChatBoxAdded: function (item) { onChatBoxAdded: function (item) {
var view = this.get(item.get('id')); // Views aren't created here, since the core code doesn't
// Views aren't created here, since the core code doesn't have
// contain any views. Instead, they're created in overrides in // contain any views. Instead, they're created in overrides in
// converse-chatiew.js and/or converse-muc.js // plugins, such as in converse-chatview.js and converse-muc.js
if (view) { return this.get(item.get('id'));
// This is an optimization. We don't remove older views, so
// when one is available, we reuse it.
delete view.model; // Remove ref to old model to help garbage collection
view.model = item;
view.initialize();
}
return view;
}, },
removeChat: function (item) { removeChat: function (item) {
...@@ -30143,9 +30135,14 @@ return Backbone.BrowserStorage; ...@@ -30143,9 +30135,14 @@ return Backbone.BrowserStorage;
'initialize': function (settings, callback) { 'initialize': function (settings, callback) {
converse.initialize(settings, callback); converse.initialize(settings, callback);
}, },
'connection': {
'connected': function () {
return converse.connection && converse.connection.connected || false;
},
'disconnect': function () { 'disconnect': function () {
converse.connection.disconnect(); converse.connection.disconnect();
}, },
},
'user': { 'user': {
'logout': function () { 'logout': function () {
converse.logOut(); converse.logOut();
...@@ -30273,7 +30270,7 @@ return Backbone.BrowserStorage; ...@@ -30273,7 +30270,7 @@ return Backbone.BrowserStorage;
converse.connection.addHandler( converse.connection.addHandler(
handler, handler,
options.ns, options.ns,
options.name, name,
options.type, options.type,
options.id, options.id,
options.from, options.from,
...@@ -31581,6 +31578,7 @@ define('text!zh',[],function () { return '{\n "domain": "converse",\n "local ...@@ -31581,6 +31578,7 @@ define('text!zh',[],function () { return '{\n "domain": "converse",\n "local
}, },
onScroll: function (ev) { onScroll: function (ev) {
// XXX: This should go into converse-mam.js
if ($(ev.target).scrollTop() === 0 && this.model.messages.length) { if ($(ev.target).scrollTop() === 0 && this.model.messages.length) {
this.fetchArchivedMessages({ this.fetchArchivedMessages({
'before': this.model.messages.at(0).get('archive_id'), 'before': this.model.messages.at(0).get('archive_id'),
...@@ -31599,6 +31597,7 @@ define('text!zh',[],function () { return '{\n "domain": "converse",\n "local ...@@ -31599,6 +31597,7 @@ define('text!zh',[],function () { return '{\n "domain": "converse",\n "local
this.model.messages.fetch({ this.model.messages.fetch({
'add': true, 'add': true,
'success': function () { 'success': function () {
// XXX: This should go into converse-mam.js
if (!converse.features.findWhere({'var': Strophe.NS.MAM})) { if (!converse.features.findWhere({'var': Strophe.NS.MAM})) {
return; return;
} }
...@@ -31620,6 +31619,7 @@ define('text!zh',[],function () { return '{\n "domain": "converse",\n "local ...@@ -31620,6 +31619,7 @@ define('text!zh',[],function () { return '{\n "domain": "converse",\n "local
* Then, upon receiving them, call onMessage on the chat box, * Then, upon receiving them, call onMessage on the chat box,
* so that they are displayed inside it. * so that they are displayed inside it.
*/ */
// XXX: This should go into converse-mam.js
if (!converse.features.findWhere({'var': Strophe.NS.MAM})) { if (!converse.features.findWhere({'var': Strophe.NS.MAM})) {
converse.log("Attempted to fetch archived messages but this user's server doesn't support XEP-0313"); converse.log("Attempted to fetch archived messages but this user's server doesn't support XEP-0313");
return; return;
...@@ -34679,10 +34679,16 @@ Strophe.RSM.prototype = { ...@@ -34679,10 +34679,16 @@ Strophe.RSM.prototype = {
ChatBoxViews: { ChatBoxViews: {
onChatBoxAdded: function (item) { onChatBoxAdded: function (item) {
if (item.get('box_id') === 'controlbox') {
var view = this.get(item.get('id')); var view = this.get(item.get('id'));
if (!view && item.get('box_id') === 'controlbox') { if (view) {
view.model = item;
view.initialize();
return view;
} else {
view = new converse.ControlBoxView({model: item}); view = new converse.ControlBoxView({model: item});
return this.add(item.get('id'), view); return this.add(item.get('id'), view);
}
} else { } else {
return this._super.onChatBoxAdded.apply(this, arguments); return this._super.onChatBoxAdded.apply(this, arguments);
} }
...@@ -44778,10 +44784,6 @@ define("crypto.mode-ctr", ["crypto.cipher-core"], function(){}); ...@@ -44778,10 +44784,6 @@ define("crypto.mode-ctr", ["crypto.cipher-core"], function(){});
return chatbox; return chatbox;
}, },
onChatBoxAdded: function (item) {
this.trimChats(this._super.onChatBoxAdded.apply(this, arguments));
},
getChatBoxWidth: function (view) { getChatBoxWidth: function (view) {
if (!view.model.get('minimized') && view.$el.is(':visible')) { if (!view.model.get('minimized') && view.$el.is(':visible')) {
return view.$el.outerWidth(true); return view.$el.outerWidth(true);
...@@ -44789,6 +44791,12 @@ define("crypto.mode-ctr", ["crypto.cipher-core"], function(){}); ...@@ -44789,6 +44791,12 @@ define("crypto.mode-ctr", ["crypto.cipher-core"], function(){});
return 0; return 0;
}, },
getShownChats: function () {
return this.filter(function (view) {
return (!view.model.get('minimized') && view.$el.is(':visible'));
});
},
trimChats: function (newchat) { trimChats: function (newchat) {
/* This method is called when a newly created chat box will /* This method is called when a newly created chat box will
* be shown. * be shown.
...@@ -44797,7 +44805,14 @@ define("crypto.mode-ctr", ["crypto.cipher-core"], function(){}); ...@@ -44797,7 +44805,14 @@ define("crypto.mode-ctr", ["crypto.cipher-core"], function(){});
* another chat box. Otherwise it minimizes the oldest chat box * another chat box. Otherwise it minimizes the oldest chat box
* to create space. * to create space.
*/ */
if (converse.no_trimming || (this.model.length <= 1)) { var shown_chats = this.getShownChats();
if (converse.no_trimming || shown_chats.length <= 1) {
return;
}
if (this.getChatBoxWidth(shown_chats[0]) === $('body').outerWidth(true)) {
// If the chats shown are the same width as the body,
// then we're in responsive mode and the chats are
// fullscreen. In this case we don't trim.
return; return;
} }
var oldest_chat, boxes_width, view, var oldest_chat, boxes_width, view,
...@@ -44953,7 +44968,7 @@ define("crypto.mode-ctr", ["crypto.cipher-core"], function(){}); ...@@ -44953,7 +44968,7 @@ define("crypto.mode-ctr", ["crypto.cipher-core"], function(){});
render: function () { render: function () {
if (this.keys().length === 0) { if (this.keys().length === 0) {
this.$el.hide('fast', converse.chatboxviews.trimChats.bind(converse.chatboxviews)); this.$el.hide('fast', converse.chatboxviews.trimChats.bind(converse.chatboxviews));
} else if (this.keys().length === 1) { } else if (this.keys().length === 1 && !this.$el.is(':visible')) {
this.$el.show('fast', converse.chatboxviews.trimChats.bind(converse.chatboxviews)); this.$el.show('fast', converse.chatboxviews.trimChats.bind(converse.chatboxviews));
} }
return this.$el; return this.$el;
...@@ -123,6 +123,7 @@ ...@@ -123,6 +123,7 @@
}, },
onScroll: function (ev) { onScroll: function (ev) {
// XXX: This should go into converse-mam.js
if ($(ev.target).scrollTop() === 0 && this.model.messages.length) { if ($(ev.target).scrollTop() === 0 && this.model.messages.length) {
this.fetchArchivedMessages({ this.fetchArchivedMessages({
'before': this.model.messages.at(0).get('archive_id'), 'before': this.model.messages.at(0).get('archive_id'),
...@@ -141,6 +142,7 @@ ...@@ -141,6 +142,7 @@
this.model.messages.fetch({ this.model.messages.fetch({
'add': true, 'add': true,
'success': function () { 'success': function () {
// XXX: This should go into converse-mam.js
if (!converse.features.findWhere({'var': Strophe.NS.MAM})) { if (!converse.features.findWhere({'var': Strophe.NS.MAM})) {
return; return;
} }
...@@ -162,6 +164,7 @@ ...@@ -162,6 +164,7 @@
* Then, upon receiving them, call onMessage on the chat box, * Then, upon receiving them, call onMessage on the chat box,
* so that they are displayed inside it. * so that they are displayed inside it.
*/ */
// XXX: This should go into converse-mam.js
if (!converse.features.findWhere({'var': Strophe.NS.MAM})) { if (!converse.features.findWhere({'var': Strophe.NS.MAM})) {
converse.log("Attempted to fetch archived messages but this user's server doesn't support XEP-0313"); converse.log("Attempted to fetch archived messages but this user's server doesn't support XEP-0313");
return; return;
......
...@@ -186,10 +186,6 @@ ...@@ -186,10 +186,6 @@
return chatbox; return chatbox;
}, },
onChatBoxAdded: function (item) {
this.trimChats(this._super.onChatBoxAdded.apply(this, arguments));
},
getChatBoxWidth: function (view) { getChatBoxWidth: function (view) {
if (!view.model.get('minimized') && view.$el.is(':visible')) { if (!view.model.get('minimized') && view.$el.is(':visible')) {
return view.$el.outerWidth(true); return view.$el.outerWidth(true);
...@@ -197,6 +193,12 @@ ...@@ -197,6 +193,12 @@
return 0; return 0;
}, },
getShownChats: function () {
return this.filter(function (view) {
return (!view.model.get('minimized') && view.$el.is(':visible'));
});
},
trimChats: function (newchat) { trimChats: function (newchat) {
/* This method is called when a newly created chat box will /* This method is called when a newly created chat box will
* be shown. * be shown.
...@@ -205,7 +207,14 @@ ...@@ -205,7 +207,14 @@
* another chat box. Otherwise it minimizes the oldest chat box * another chat box. Otherwise it minimizes the oldest chat box
* to create space. * to create space.
*/ */
if (converse.no_trimming || (this.model.length <= 1)) { var shown_chats = this.getShownChats();
if (converse.no_trimming || shown_chats.length <= 1) {
return;
}
if (this.getChatBoxWidth(shown_chats[0]) === $('body').outerWidth(true)) {
// If the chats shown are the same width as the body,
// then we're in responsive mode and the chats are
// fullscreen. In this case we don't trim.
return; return;
} }
var oldest_chat, boxes_width, view, var oldest_chat, boxes_width, view,
...@@ -361,7 +370,7 @@ ...@@ -361,7 +370,7 @@
render: function () { render: function () {
if (this.keys().length === 0) { if (this.keys().length === 0) {
this.$el.hide('fast', converse.chatboxviews.trimChats.bind(converse.chatboxviews)); this.$el.hide('fast', converse.chatboxviews.trimChats.bind(converse.chatboxviews));
} else if (this.keys().length === 1) { } else if (this.keys().length === 1 && !this.$el.is(':visible')) {
this.$el.show('fast', converse.chatboxviews.trimChats.bind(converse.chatboxviews)); this.$el.show('fast', converse.chatboxviews.trimChats.bind(converse.chatboxviews));
} }
return this.$el; return this.$el;
......
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