Commit 6ef0536e authored by JC Brand's avatar JC Brand

Some work on using es6 promises

parent 9a9eae3f
......@@ -3,6 +3,7 @@
} (this, function (jasmine, mock, converse, roomslist, test_utils) {
var _ = converse.env._;
var $msg = converse.env.$msg;
var Promise = converse.env.Promise;
describe("The converse-roomslist plugin", function () {
......@@ -77,61 +78,69 @@
expect(_converse.chatboxes.length).toBe(1);
}));
it("shows unread messages directed at the user", mock.initConverse(
it("shows unread messages directed at the user", mock.initConverseWithAsync(
{ whitelisted_plugins: ['converse-roomslist'],
allow_bookmarks: false // Makes testing easier, otherwise we
// have to mock stanza traffic.
}, function (_converse) {
var room_jid = 'kitchen@conference.shakespeare.lit';
test_utils.openAndEnterChatRoom(
_converse, 'kitchen', 'conference.shakespeare.lit', 'romeo');
var view = _converse.chatboxviews.get(room_jid);
view.model.set({'minimized': true});
var contact_jid = mock.cur_names[5].replace(/ /g,'.').toLowerCase() + '@localhost';
var nick = mock.chatroom_names[0];
view.handleMUCMessage(
$msg({
from: room_jid+'/'+nick,
id: (new Date()).getTime(),
to: 'dummy@localhost',
type: 'groupchat'
}).c('body').t('foo').tree());
// If the user isn't mentioned, the counter doesn't get incremented, but the text of the room is bold
var room_el = _converse.rooms_list_view.el.querySelector(".available-chatroom");
expect(_.includes(room_el.classList, 'unread-msgs'));
// If the user is mentioned, the counter also gets updated
view.handleMUCMessage(
$msg({
from: room_jid+'/'+nick,
id: (new Date()).getTime(),
to: 'dummy@localhost',
type: 'groupchat'
}).c('body').t('romeo: Your attention is required').tree()
);
var indicator_el = _converse.rooms_list_view.el.querySelector(".msgs-indicator");
expect(indicator_el.textContent).toBe('1');
view.handleMUCMessage(
$msg({
from: room_jid+'/'+nick,
id: (new Date()).getTime(),
to: 'dummy@localhost',
type: 'groupchat'
}).c('body').t('romeo: and another thing...').tree()
);
indicator_el = _converse.rooms_list_view.el.querySelector(".msgs-indicator");
expect(indicator_el.textContent).toBe('2');
// When the chat gets maximized again, the unread indicators are removed
view.model.set({'minimized': false});
indicator_el = _converse.rooms_list_view.el.querySelector(".msgs-indicator");
expect(_.isNull(indicator_el));
room_el = _converse.rooms_list_view.el.querySelector(".available-chatroom");
expect(_.includes(room_el.classList, 'unread-msgs')).toBeFalsy();
}, function (done, _converse) {
test_utils.waitUntil(function () {
return !_.isUndefined(_converse.rooms_list_view)
}, 500)
.then(function () {
var room_jid = 'kitchen@conference.shakespeare.lit';
test_utils.openAndEnterChatRoom(
_converse, 'kitchen', 'conference.shakespeare.lit', 'romeo');
var view = _converse.chatboxviews.get(room_jid);
view.model.set({'minimized': true});
var contact_jid = mock.cur_names[5].replace(/ /g,'.').toLowerCase() + '@localhost';
var nick = mock.chatroom_names[0];
view.handleMUCMessage(
$msg({
from: room_jid+'/'+nick,
id: (new Date()).getTime(),
to: 'dummy@localhost',
type: 'groupchat'
}).c('body').t('foo').tree());
// If the user isn't mentioned, the counter doesn't get incremented, but the text of the room is bold
var room_el = _converse.rooms_list_view.el.querySelector(
".available-chatroom"
);
expect(_.includes(room_el.classList, 'unread-msgs'));
// If the user is mentioned, the counter also gets updated
view.handleMUCMessage(
$msg({
from: room_jid+'/'+nick,
id: (new Date()).getTime(),
to: 'dummy@localhost',
type: 'groupchat'
}).c('body').t('romeo: Your attention is required').tree()
);
var indicator_el = _converse.rooms_list_view.el.querySelector(".msgs-indicator");
expect(indicator_el.textContent).toBe('1');
view.handleMUCMessage(
$msg({
from: room_jid+'/'+nick,
id: (new Date()).getTime(),
to: 'dummy@localhost',
type: 'groupchat'
}).c('body').t('romeo: and another thing...').tree()
);
indicator_el = _converse.rooms_list_view.el.querySelector(".msgs-indicator");
expect(indicator_el.textContent).toBe('2');
// When the chat gets maximized again, the unread indicators are removed
view.model.set({'minimized': false});
indicator_el = _converse.rooms_list_view.el.querySelector(".msgs-indicator");
expect(_.isNull(indicator_el));
room_el = _converse.rooms_list_view.el.querySelector(".available-chatroom");
expect(_.includes(room_el.classList, 'unread-msgs')).toBeFalsy();
done();
});
}));
});
}));
......@@ -23,7 +23,7 @@ require.config({
"backbone.browserStorage": "node_modules/backbone.browserStorage/backbone.browserStorage",
"backbone.overview": "node_modules/backbone.overview/backbone.overview",
"eventemitter": "node_modules/otr/build/dep/eventemitter",
"es6-promise": "node_modules/es6-promise/dist/es6-promise",
"es6-promise": "node_modules/es6-promise/dist/es6-promise.auto",
"jquery": "node_modules/jquery/dist/jquery",
"jquery.noconflict": "src/jquery.noconflict",
"jquery.browser": "node_modules/jquery.browser/dist/jquery.browser",
......
......@@ -10,7 +10,8 @@
* in XEP-0048.
*/
(function (root, factory) {
define(["utils",
define(["jquery.noconflict",
"utils",
"converse-core",
"converse-muc",
"tpl!chatroom_bookmark_form",
......@@ -20,6 +21,7 @@
],
factory);
}(this, function (
$,
utils,
converse,
muc,
......@@ -29,8 +31,7 @@
tpl_bookmarks_list
) {
const $ = converse.env.jQuery,
{ Backbone, Strophe, $iq, b64_sha1, sizzle, _ } = converse.env;
const { Backbone, Promise, Strophe, $iq, b64_sha1, sizzle, _ } = converse.env;
converse.plugins.add('converse-bookmarks', {
overrides: {
......@@ -488,8 +489,11 @@
_converse.emit('bookmarksInitialized');
});
};
$.when(_converse.api.waitUntil('chatBoxesFetched'),
_converse.api.waitUntil('roomsPanelRendered')).then(initBookmarks);
Promise.all([
_converse.api.waitUntil('chatBoxesFetched'),
_converse.api.waitUntil('roomsPanelRendered')
]).then(initBookmarks);
const afterReconnection = function () {
if (!_converse.allow_bookmarks) {
......
......@@ -8,6 +8,7 @@
(function (root, factory) {
define([
"jquery.noconflict",
"converse-core",
"tpl!chatbox",
"tpl!new_day",
......@@ -19,6 +20,7 @@
"tpl!spinner"
], factory);
}(this, function (
$,
converse,
tpl_chatbox,
tpl_new_day,
......@@ -30,8 +32,7 @@
tpl_spinner
) {
"use strict";
const $ = converse.env.jQuery,
{ $msg, Backbone, Strophe, _, moment, utils } = converse.env;
const { $msg, Backbone, Strophe, _, moment, utils } = converse.env;
const KEY = {
ENTER: 13,
......
......@@ -7,7 +7,8 @@
/*global define */
(function (root, factory) {
define(["converse-core",
define(["jquery.noconflict",
"converse-core",
"tpl!add_contact_dropdown",
"tpl!add_contact_form",
"tpl!change_status_message",
......@@ -25,6 +26,7 @@
"converse-rosterview"
], factory);
}(this, function (
$,
converse,
tpl_add_contact_dropdown,
tpl_add_contact_form,
......@@ -44,13 +46,7 @@
const USERS_PANEL_ID = 'users';
const CHATBOX_TYPE = 'chatbox';
// Strophe methods for building stanzas
const { Strophe } = converse.env,
{ Backbone } = converse.env,
{ utils } = converse.env;
// Other necessary globals
const $ = converse.env.jQuery,
{ _, fp, moment } = converse.env;
const { Strophe, Backbone, utils, _, fp, moment } = converse.env;
converse.plugins.add('converse-controlbox', {
......
This diff is collapsed.
......@@ -7,17 +7,16 @@
/*global define, window */
(function (root, factory) {
define([
define(["jquery.noconflict",
"converse-core",
"tpl!dragresize",
"converse-chatview",
"converse-muc", // XXX: would like to remove this
"converse-controlbox"
], factory);
}(this, function (converse, tpl_dragresize) {
}(this, function ($, converse, tpl_dragresize) {
"use strict";
const $ = converse.env.jQuery,
{ _ } = converse.env;
const { _ } = converse.env;
function renderDragResizeHandles (_converse, view) {
const flyout = view.el.querySelector('.box-flyout');
......
......@@ -16,8 +16,7 @@
], factory);
}(this, function (converse, tpl_brand_heading) {
"use strict";
const $ = converse.env.jQuery,
{ Strophe, _ } = converse.env;
const { Strophe, _ } = converse.env;
function createBrandHeadingElement () {
const div = document.createElement('div');
......
......@@ -9,16 +9,15 @@
// XEP-0059 Result Set Management
(function (root, factory) {
define([
define(["jquery.noconflict",
"converse-core",
"converse-chatview", // Could be made a soft dependency
"converse-muc", // Could be made a soft dependency
"strophe.rsm"
], factory);
}(this, function (converse) {
}(this, function ($, converse) {
"use strict";
const $ = converse.env.jQuery,
{ Strophe, $iq, _, moment } = converse.env;
const { Strophe, $iq, _, moment } = converse.env;
const RSM_ATTRIBUTES = ['max', 'first', 'last', 'after', 'before', 'index', 'count'];
// XEP-0313 Message Archive Management
......
......@@ -7,7 +7,8 @@
/*global define, window */
(function (root, factory) {
define(["converse-core",
define(["jquery.noconflict",
"converse-core",
"tpl!chatbox_minimize",
"tpl!toggle_chats",
"tpl!trimmed_chat",
......@@ -17,6 +18,7 @@
"converse-muc"
], factory);
}(this, function (
$,
converse,
tpl_chatbox_minimize,
tpl_toggle_chats,
......@@ -25,8 +27,7 @@
) {
"use strict";
const $ = converse.env.jQuery,
{ _ , utils, Backbone, b64_sha1, moment } = converse.env;
const { _ , utils, Backbone, b64_sha1, moment } = converse.env;
converse.plugins.add('converse-minimize', {
overrides: {
......
......@@ -11,6 +11,7 @@
*/
(function (root, factory) {
define([
"jquery.noconflict",
"converse-core",
"tpl!chatarea",
"tpl!chatroom",
......@@ -34,6 +35,7 @@
"converse-chatview"
], factory);
}(this, function (
$,
converse,
tpl_chatarea,
tpl_chatroom,
......@@ -61,7 +63,6 @@
const CHATROOMS_TYPE = 'chatroom';
const { Strophe, Backbone, $iq, $build, $msg, $pres, b64_sha1, sizzle, utils, _, fp, moment } = converse.env;
const $ = converse.env.jQuery;
// Add Strophe Namespaces
Strophe.addNamespace('MUC_ADMIN', Strophe.NS.MUC + "#admin");
......
......@@ -11,15 +11,15 @@
*/
(function (root, factory) {
define(["converse-chatview",
define(["jquery.noconflict",
"converse-chatview",
"tpl!toolbar_otr",
'otr'
], factory);
}(this, function (converse, tpl_toolbar_otr, otr) {
}(this, function ($, converse, tpl_toolbar_otr, otr) {
"use strict";
const { Strophe, utils, b64_sha1, _ } = converse.env;
const $ = converse.env.jQuery;
const HAS_CSPRNG = ((!_.isUndefined(crypto)) &&
((_.isFunction(crypto.randomBytes)) || (_.isFunction(crypto.getRandomValues))
......
......@@ -10,7 +10,8 @@
* as specified in XEP-0077.
*/
(function (root, factory) {
define(["converse-core",
define(["jquery.noconflict",
"converse-core",
"tpl!form_username",
"tpl!register_panel",
"tpl!register_tab",
......@@ -20,6 +21,7 @@
"converse-controlbox"
], factory);
}(this, function (
$,
converse,
tpl_form_username,
tpl_register_panel,
......@@ -33,7 +35,6 @@
// Strophe methods for building stanzas
const { Strophe, Backbone, utils, $iq, _ } = converse.env;
const $ = converse.env.jQuery;
// Add Strophe Namespaces
Strophe.addNamespace('REGISTER', 'jabber:iq:register');
......
......@@ -10,15 +10,15 @@
* rooms in the "Rooms Panel" of the ControlBox.
*/
(function (root, factory) {
define(["utils",
define(["jquery.noconflict",
"utils",
"converse-core",
"converse-muc",
"tpl!rooms_list",
"tpl!rooms_list_item"
], factory);
}(this, function (utils, converse, muc, tpl_rooms_list, tpl_rooms_list_item) {
const $ = converse.env.jQuery,
{ Backbone, b64_sha1, sizzle, _ } = converse.env;
}(this, function ($, utils, converse, muc, tpl_rooms_list, tpl_rooms_list_item) {
const { Backbone, Promise, b64_sha1, sizzle, _ } = converse.env;
converse.plugins.add('converse-roomslist', {
initialize () {
......@@ -161,15 +161,18 @@
);
};
$.when(_converse.api.waitUntil('chatBoxesFetched'),
_converse.api.waitUntil('roomsPanelRendered')).then(
function () {
if (_converse.allow_bookmarks) {
_converse.api.waitUntil('bookmarksInitialized').then(initRoomsListView);
} else {
initRoomsListView();
}
});
Promise.all([
_converse.api.waitUntil('chatBoxesFetched'),
_converse.api.waitUntil('roomsPanelRendered')
]).then(() => {
if (_converse.allow_bookmarks) {
_converse.api.waitUntil('bookmarksInitialized').then(
initRoomsListView
);
} else {
initRoomsListView();
}
});
const afterReconnection = function () {
if (_.isUndefined(_converse.rooms_list_view)) {
......
......@@ -7,7 +7,8 @@
/*global define */
(function (root, factory) {
define(["converse-core",
define(["jquery.noconflict",
"converse-core",
"tpl!group_header",
"tpl!pending_contact",
"tpl!requesting_contact",
......@@ -16,6 +17,7 @@
"tpl!roster_item"
], factory);
}(this, function (
$,
converse,
tpl_group_header,
tpl_pending_contact,
......@@ -24,8 +26,7 @@
tpl_roster_filter,
tpl_roster_item) {
"use strict";
const $ = converse.env.jQuery,
{ Backbone, utils, Strophe, $iq, b64_sha1, sizzle, _ } = converse.env;
const { Backbone, utils, Strophe, $iq, b64_sha1, sizzle, _ } = converse.env;
converse.plugins.add('converse-rosterview', {
......
......@@ -7,11 +7,10 @@
/*global define */
(function (root, factory) {
define(["converse-core", "strophe.vcard"], factory);
}(this, function (converse) {
define(["jquery.noconflict", "converse-core", "strophe.vcard"], factory);
}(this, function ($, converse) {
"use strict";
const { Strophe, _, moment } = converse.env,
$ = converse.env.jQuery;
const { Strophe, _, moment } = converse.env;
converse.plugins.add('converse-vcard', {
......
......@@ -3,6 +3,7 @@
define([
"jquery.noconflict",
"sizzle",
"es6-promise",
"jquery.browser",
"lodash.noconflict",
"locales",
......@@ -18,7 +19,9 @@
"tpl!form_captcha"
], factory);
}(this, function (
$, sizzle, dummy, _,
$, sizzle,
Promise,
dummy, _,
locales,
moment,
Strophe,
......@@ -524,7 +527,16 @@
utils.isPersistableModel = function (model) {
return model.collection && model.collection.browserStorage;
}
};
utils.getWrappedPromise = function () {
const wrapper = {};
wrapper.promise = new Promise((resolve, reject) => {
wrapper.resolve = resolve;
wrapper.reject = reject;
})
return wrapper;
};
utils.safeSave = function (model, attributes) {
if (utils.isPersistableModel(model)) {
......
(function (root, factory) {
define("mock", ['converse'], factory);
}(this, function (converse_api) {
define("mock", ['jquery.noconflict', 'converse'], factory);
}(this, function ($, converse_api) {
var _ = converse_api.env._;
var Strophe = converse_api.env.Strophe;
var $iq = converse_api.env.$iq;
......@@ -101,6 +101,7 @@
'debug': false
}, settings || {}));
converse.ChatBoxViews.prototype.trimChat = function () {};
$.fx.off = true;
return converse;
}
......
(function (root, factory) {
define(['converse', 'es6-promise', 'mock', 'wait-until-promise'], factory);
}(this, function (converse_api, Promise, mock, waitUntilPromise) {
define(['jquery.noconflict', 'converse', 'es6-promise', 'mock', 'wait-until-promise'], factory);
}(this, function ($, converse_api, Promise, mock, waitUntilPromise) {
var _ = converse_api.env._;
var $ = converse_api.env.jQuery;
var $msg = converse_api.env.$msg;
var $pres = converse_api.env.$pres;
var $iq = converse_api.env.$iq;
......
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