parent
8493b4f423
commit
5b46e27c41
45
converse.js
45
converse.js
|
@ -3019,19 +3019,18 @@
|
||||||
* If it doesn't exist, create it.
|
* If it doesn't exist, create it.
|
||||||
*/
|
*/
|
||||||
var chatbox = this.model.get(attrs.jid);
|
var chatbox = this.model.get(attrs.jid);
|
||||||
if (chatbox) {
|
if (!chatbox) {
|
||||||
if (chatbox.get('minimized')) {
|
|
||||||
chatbox.maximize();
|
|
||||||
} else {
|
|
||||||
chatbox.trigger('show');
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
chatbox = this.model.create(attrs, {
|
chatbox = this.model.create(attrs, {
|
||||||
'error': function (model, response) {
|
'error': function (model, response) {
|
||||||
converse.log(response.responseText);
|
converse.log(response.responseText);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (chatbox.get('minimized')) {
|
||||||
|
chatbox.maximize();
|
||||||
|
} else {
|
||||||
|
chatbox.trigger('show');
|
||||||
|
}
|
||||||
return chatbox;
|
return chatbox;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -3258,6 +3257,8 @@
|
||||||
|
|
||||||
openChat: function (ev) {
|
openChat: function (ev) {
|
||||||
if (ev && ev.preventDefault) { ev.preventDefault(); }
|
if (ev && ev.preventDefault) { ev.preventDefault(); }
|
||||||
|
// XXX: Can this.model.attributes be used here, instead of
|
||||||
|
// manually specifying all attributes?
|
||||||
return converse.chatboxviews.showChat({
|
return converse.chatboxviews.showChat({
|
||||||
'id': this.model.get('jid'),
|
'id': this.model.get('jid'),
|
||||||
'jid': this.model.get('jid'),
|
'jid': this.model.get('jid'),
|
||||||
|
@ -4636,6 +4637,20 @@
|
||||||
return contact.attributes;
|
return contact.attributes;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
'getChatBox': function (jid) {
|
||||||
|
var chatbox = converse.chatboxes.get(jid);
|
||||||
|
if (chatbox) {
|
||||||
|
return {
|
||||||
|
'attributes': chatbox.attributes,
|
||||||
|
'endOTR': chatbox.endOTR,
|
||||||
|
'get': chatbox.get,
|
||||||
|
'initiateOTR': chatbox.initiateOTR,
|
||||||
|
'maximize': chatbox.maximize,
|
||||||
|
'minimize': chatbox.minimize,
|
||||||
|
'set': chatbox.set
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
'getRID': function () {
|
'getRID': function () {
|
||||||
if (converse.expose_rid_and_sid && typeof converse.connection !== "undefined") {
|
if (converse.expose_rid_and_sid && typeof converse.connection !== "undefined") {
|
||||||
return converse.connection.rid || converse.connection._proto.rid;
|
return converse.connection.rid || converse.connection._proto.rid;
|
||||||
|
@ -4648,6 +4663,22 @@
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
|
'openChatBox': function (jid) {
|
||||||
|
var chatbox;
|
||||||
|
var contact = converse.roster.get(Strophe.getBareJidFromJid(jid));
|
||||||
|
if (contact) {
|
||||||
|
chatbox = converse.chatboxviews.showChat(contact.attributes);
|
||||||
|
return {
|
||||||
|
'attributes': chatbox.attributes,
|
||||||
|
'endOTR': chatbox.endOTR,
|
||||||
|
'get': chatbox.get,
|
||||||
|
'initiateOTR': chatbox.initiateOTR,
|
||||||
|
'maximize': chatbox.maximize,
|
||||||
|
'minimize': chatbox.minimize,
|
||||||
|
'set': chatbox.set
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
'once': function (evt, handler) {
|
'once': function (evt, handler) {
|
||||||
converse.once(evt, handler);
|
converse.once(evt, handler);
|
||||||
},
|
},
|
||||||
|
|
|
@ -8,6 +8,7 @@ Changelog
|
||||||
* Bugfix. Cannot read property "top" of undefined. [jcbrand]
|
* Bugfix. Cannot read property "top" of undefined. [jcbrand]
|
||||||
* Add new event, noResumeableSession, for when keepalive=true and there aren't
|
* Add new event, noResumeableSession, for when keepalive=true and there aren't
|
||||||
any prebind session tokens. [jcbrand]
|
any prebind session tokens. [jcbrand]
|
||||||
|
* Add 2 new API methods, getChatBox and openChatBox. [jcbrand]
|
||||||
|
|
||||||
0.8.3 (2014-09-22)
|
0.8.3 (2014-09-22)
|
||||||
------------------
|
------------------
|
||||||
|
|
|
@ -10,8 +10,10 @@
|
||||||
return describe("Converse", $.proxy(function(mock, test_utils) {
|
return describe("Converse", $.proxy(function(mock, test_utils) {
|
||||||
|
|
||||||
beforeEach($.proxy(function () {
|
beforeEach($.proxy(function () {
|
||||||
window.localStorage.clear();
|
test_utils.closeAllChatBoxes();
|
||||||
window.sessionStorage.clear();
|
test_utils.clearBrowserStorage();
|
||||||
|
converse.rosterview.model.reset();
|
||||||
|
test_utils.createContacts('current');
|
||||||
}, converse));
|
}, converse));
|
||||||
|
|
||||||
it("has an API method for retrieving the next RID", $.proxy(function () {
|
it("has an API method for retrieving the next RID", $.proxy(function () {
|
||||||
|
@ -46,12 +48,43 @@
|
||||||
|
|
||||||
it("has an API method for retrieving a buddy's attributes", $.proxy(function () {
|
it("has an API method for retrieving a buddy's attributes", $.proxy(function () {
|
||||||
var jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
var jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
||||||
expect(converse_api.getBuddy(jid)).toBeFalsy();
|
expect(converse_api.getBuddy('non-existing@jabber.org')).toBeFalsy();
|
||||||
test_utils.createContacts('current');
|
|
||||||
var attrs = converse_api.getBuddy(jid);
|
var attrs = converse_api.getBuddy(jid);
|
||||||
expect(typeof attrs).toBe('object');
|
expect(typeof attrs).toBe('object');
|
||||||
expect(attrs.fullname).toBe(mock.cur_names[0]);
|
expect(attrs.fullname).toBe(mock.cur_names[0]);
|
||||||
expect(attrs.jid).toBe(jid);
|
expect(attrs.jid).toBe(jid);
|
||||||
}, converse));
|
}, converse));
|
||||||
|
|
||||||
|
it("has an API method, openChatBox, for opening a chat box for a buddy", $.proxy(function () {
|
||||||
|
expect(converse_api.openChatBox('non-existing@jabber.org')).toBeFalsy(); // test on user that doesn't exist.
|
||||||
|
var jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
||||||
|
var box = converse_api.openChatBox(jid);
|
||||||
|
expect(box instanceof Object).toBeTruthy();
|
||||||
|
expect(box.get('box_id')).toBe(b64_sha1(jid));
|
||||||
|
var chatboxview = this.chatboxviews.get(jid);
|
||||||
|
expect(chatboxview.$el.is(':visible')).toBeTruthy();
|
||||||
|
}, converse));
|
||||||
|
|
||||||
|
it("will focus an already open chat box, if the openChatBox API method is called for it.", $.proxy(function () {
|
||||||
|
// Calling openChatBox on an already open chat will focus it.
|
||||||
|
var jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
||||||
|
var chatboxview = this.chatboxviews.get(jid);
|
||||||
|
spyOn(chatboxview, 'focus');
|
||||||
|
test_utils.openChatBoxFor(jid);
|
||||||
|
box = converse_api.openChatBox(jid);
|
||||||
|
expect(chatboxview.focus).toHaveBeenCalled();
|
||||||
|
expect(box.get('box_id')).toBe(b64_sha1(jid));
|
||||||
|
|
||||||
|
}, converse));
|
||||||
|
|
||||||
|
it("has an API method, getChatBox, for retrieving chat box", $.proxy(function () {
|
||||||
|
var jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
||||||
|
expect(converse_api.getChatBox(jid)).toBeFalsy();
|
||||||
|
test_utils.openChatBoxFor(jid);
|
||||||
|
var box = converse_api.getChatBox(jid);
|
||||||
|
expect(box instanceof Object).toBeTruthy();
|
||||||
|
expect(box.get('box_id')).toBe(b64_sha1(jid));
|
||||||
|
}, converse));
|
||||||
|
|
||||||
}, converse, mock, test_utils));
|
}, converse, mock, test_utils));
|
||||||
}));
|
}));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user