Commit b84fb413 authored by JC Brand's avatar JC Brand

Trimmed chats can now be restored.

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