Commit b84fb413 authored by JC Brand's avatar JC Brand

Trimmed chats can now be restored.

parent 38e06683
...@@ -886,7 +886,7 @@ ...@@ -886,7 +886,7 @@
events: { events: {
'click .close-chatbox-button': 'close', 'click .close-chatbox-button': 'close',
'click .toggle-chatbox-button': 'toggleChatBox', 'click .toggle-chatbox-button': 'toggle',
'keypress textarea.chat-textarea': 'keyPressed', 'keypress textarea.chat-textarea': 'keyPressed',
'click .toggle-smiley': 'toggleEmoticonMenu', 'click .toggle-smiley': 'toggleEmoticonMenu',
'click .toggle-smiley ul li': 'insertEmoticon', 'click .toggle-smiley ul li': 'insertEmoticon',
...@@ -1308,7 +1308,11 @@ ...@@ -1308,7 +1308,11 @@
this.renderToolbar().informOTRChange(); this.renderToolbar().informOTRChange();
} }
if (_.has(item.changed, 'trimmed')) { if (_.has(item.changed, 'trimmed')) {
this.trim(); if (item.get('trimmed')) {
this.trim();
} else {
this.grow();
}
} }
// TODO check for changed fullname as well // TODO check for changed fullname as well
}, },
...@@ -1327,7 +1331,13 @@ ...@@ -1327,7 +1331,13 @@
}, },
trim: function () { trim: function () {
this.$el.hide(); this.$el.hide('fast', converse.refreshWebkit);
},
grow: function () {
// the opposite of trim, i.e. restoring a trimmed chat box
this.$el.show();
this.model.trigger('grow', this.model);
}, },
saveToggleState: function () { saveToggleState: function () {
...@@ -1345,7 +1355,7 @@ ...@@ -1345,7 +1355,7 @@
return this; return this;
}, },
toggleChatBox: function (ev) { toggle: function (ev) {
var $target = $(ev.target), $count; var $target = $(ev.target), $count;
this.saveToggleState(); this.saveToggleState();
this.$el.children('.box-flyout').attr('style', ''); this.$el.children('.box-flyout').attr('style', '');
...@@ -1913,7 +1923,7 @@ ...@@ -1913,7 +1923,7 @@
className: 'chatroom', className: 'chatroom',
events: { events: {
'click .close-chatbox-button': 'close', 'click .close-chatbox-button': 'close',
'click .toggle-chatbox-button': 'toggleChatBox', 'click .toggle-chatbox-button': 'toggle',
'click .configure-chatroom-button': 'configureChatRoom', 'click .configure-chatroom-button': 'configureChatRoom',
'click .toggle-smiley': 'toggleEmoticonMenu', 'click .toggle-smiley': 'toggleEmoticonMenu',
'click .toggle-smiley ul li': 'insertEmoticon', 'click .toggle-smiley ul li': 'insertEmoticon',
...@@ -2530,6 +2540,10 @@ ...@@ -2530,6 +2540,10 @@
} }
this.trimChats(view); this.trimChats(view);
}, this); }, this);
this.model.on("grow", function (item) {
this.trimChats(this.get(item.get('id')));
}, this);
}, },
render: function () { render: function () {
...@@ -2586,7 +2600,7 @@ ...@@ -2586,7 +2600,7 @@
getOldestNonTrimmedChat: function () { getOldestNonTrimmedChat: function () {
// Get oldest view (which is not controlbox) // Get oldest view (which is not controlbox)
var i = 0; var i = 0;
var model = this.model.at(i); var model = this.model.sort().at(i);
while (model.get('id') === 'controlbox' || model.get('trimmed') === true) { while (model.get('id') === 'controlbox' || model.get('trimmed') === true) {
i++; i++;
model = this.model.at(i); model = this.model.at(i);
...@@ -2597,7 +2611,11 @@ ...@@ -2597,7 +2611,11 @@
showChat: function (attrs) { showChat: function (attrs) {
var chatbox = this.model.get(attrs.jid); var chatbox = this.model.get(attrs.jid);
if (chatbox) { if (chatbox) {
chatbox.trigger('show'); if (chatbox.get('trimmed')) {
chatbox.set({'trimmed': false});
} else {
chatbox.trigger('show');
}
} else { } else {
chatbox = this.model.create(attrs, { chatbox = this.model.create(attrs, {
'error': function (model, response) { 'error': function (model, response) {
...@@ -2632,8 +2650,11 @@ ...@@ -2632,8 +2650,11 @@
restore: function (ev) { restore: function (ev) {
ev.preventDefault(); ev.preventDefault();
this.model.set('trimmed', false);
this.$el.remove(); this.$el.remove();
this.model.set({
'time_opened': moment().format(),
'trimmed': false
});
return this; return this;
} }
}); });
......
...@@ -133,7 +133,7 @@ ...@@ -133,7 +133,7 @@
it("can be toggled by clicking a DOM element with class 'toggle-chatbox-button'", function () { it("can be toggled by clicking a DOM element with class 'toggle-chatbox-button'", function () {
var chatbox = utils.openChatBoxes(1)[0], var chatbox = utils.openChatBoxes(1)[0],
chatview = this.chatboxviews.get(chatbox.get('jid')); chatview = this.chatboxviews.get(chatbox.get('jid'));
spyOn(chatview, 'toggleChatBox').andCallThrough(); spyOn(chatview, 'toggle').andCallThrough();
spyOn(converse, 'emit'); spyOn(converse, 'emit');
// We need to rebind all events otherwise our spy won't be called // We need to rebind all events otherwise our spy won't be called
chatview.delegateEvents(); chatview.delegateEvents();
...@@ -143,7 +143,7 @@ ...@@ -143,7 +143,7 @@
}); });
waits(250); waits(250);
runs(function () { runs(function () {
expect(chatview.toggleChatBox).toHaveBeenCalled(); expect(chatview.toggle).toHaveBeenCalled();
expect(converse.emit).toHaveBeenCalledWith('onChatBoxToggled', jasmine.any(Object)); expect(converse.emit).toHaveBeenCalledWith('onChatBoxToggled', jasmine.any(Object));
expect(converse.emit.callCount, 2); expect(converse.emit.callCount, 2);
expect(chatview.$el.find('.chat-body').is(':visible')).toBeFalsy(); expect(chatview.$el.find('.chat-body').is(':visible')).toBeFalsy();
...@@ -154,7 +154,7 @@ ...@@ -154,7 +154,7 @@
}); });
waits(250); waits(250);
runs(function () { runs(function () {
expect(chatview.toggleChatBox).toHaveBeenCalled(); expect(chatview.toggle).toHaveBeenCalled();
expect(converse.emit).toHaveBeenCalledWith('onChatBoxToggled', jasmine.any(Object)); expect(converse.emit).toHaveBeenCalledWith('onChatBoxToggled', jasmine.any(Object));
expect(chatview.$el.find('.chat-body').is(':visible')).toBeTruthy(); expect(chatview.$el.find('.chat-body').is(':visible')).toBeTruthy();
expect(chatview.$el.find('.toggle-chatbox-button').hasClass('icon-minus')).toBeTruthy(); expect(chatview.$el.find('.toggle-chatbox-button').hasClass('icon-minus')).toBeTruthy();
......
...@@ -142,7 +142,7 @@ ...@@ -142,7 +142,7 @@
it("can be toggled by clicking a DOM element with class 'toggle-chatbox-button'", function () { it("can be toggled by clicking a DOM element with class 'toggle-chatbox-button'", function () {
var view = this.chatboxviews.get('lounge@muc.localhost'), var view = this.chatboxviews.get('lounge@muc.localhost'),
chatroom = view.model, $el; chatroom = view.model, $el;
spyOn(view, 'toggleChatBox').andCallThrough(); spyOn(view, 'toggle').andCallThrough();
spyOn(converse, 'emit'); spyOn(converse, 'emit');
view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
runs(function () { runs(function () {
...@@ -150,7 +150,7 @@ ...@@ -150,7 +150,7 @@
}); });
waits(250); waits(250);
runs(function () { runs(function () {
expect(view.toggleChatBox).toHaveBeenCalled(); expect(view.toggle).toHaveBeenCalled();
expect(converse.emit).toHaveBeenCalledWith('onChatBoxToggled', jasmine.any(Object)); expect(converse.emit).toHaveBeenCalledWith('onChatBoxToggled', jasmine.any(Object));
expect(converse.emit.callCount, 2); expect(converse.emit.callCount, 2);
expect(view.$el.find('.chat-body').is(':visible')).toBeFalsy(); expect(view.$el.find('.chat-body').is(':visible')).toBeFalsy();
...@@ -161,7 +161,7 @@ ...@@ -161,7 +161,7 @@
}); });
waits(250); waits(250);
runs(function () { runs(function () {
expect(view.toggleChatBox).toHaveBeenCalled(); expect(view.toggle).toHaveBeenCalled();
expect(converse.emit).toHaveBeenCalledWith('onChatBoxToggled', jasmine.any(Object)); expect(converse.emit).toHaveBeenCalledWith('onChatBoxToggled', jasmine.any(Object));
expect(view.$el.find('.chat-body').is(':visible')).toBeTruthy(); expect(view.$el.find('.chat-body').is(':visible')).toBeTruthy();
expect(view.$el.find('.toggle-chatbox-button').hasClass('icon-minus')).toBeTruthy(); expect(view.$el.find('.toggle-chatbox-button').hasClass('icon-minus')).toBeTruthy();
......
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