Commit 78f8f73f authored by JC Brand's avatar JC Brand

Get rid of `converse-uniview` plugin

Instead of overriding createChatBox, set 'hidden' flag via defaults
parent f79fd333
......@@ -32,6 +32,7 @@ Soon we'll deprecate the latter, so prepare now.
- #2201: added html to converse.env
- #2213: added CustomElement to converse.env
- #2220: fix rendering of emojis in case `use_system_emojis == false` (again).
- The plugin `converse-uniview` has been removed and its functionality merged into `converse-chatboxviews`
- Removed the mockups from the project. Recommended to use tests instead.
- The API method `api.settings.update` has been deprecated in favor of `api.settings.extend`.
- The API methods under the `api.user.status` namespace are now asynchronous and need to be `await`ed.
......
......@@ -3115,7 +3115,8 @@
"dependencies": {
"filesize": {
"version": "6.1.0",
"resolved": false
"resolved": "https://registry.npmjs.org/filesize/-/filesize-6.1.0.tgz",
"integrity": "sha512-LpCHtPQ3sFx67z+uh2HnSyWSLLu5Jxo21795uRDuar/EOuYWXib5EmPaGIBuSnRqH2IODiKA2k5re/K9OnN/Yg=="
},
"fs-extra": {
"version": "8.1.0",
......@@ -3171,20 +3172,22 @@
},
"localforage": {
"version": "1.7.3",
"resolved": false,
"resolved": "https://registry.npmjs.org/localforage/-/localforage-1.7.3.tgz",
"integrity": "sha512-1TulyYfc4udS7ECSBT2vwJksWbkwwTX8BzeUIiq8Y07Riy7bDAAnxDaPU/tWyOVmQAcWJIEIFP9lPfBGqVoPgQ==",
"requires": {
"lie": "3.1.1"
}
},
"pluggable.js": {
"version": "2.0.1",
"resolved": false,
"resolved": "https://registry.npmjs.org/pluggable.js/-/pluggable.js-2.0.1.tgz",
"integrity": "sha512-SBt6v6Tbp20Jf8hU0cpcc/+HBHGMY8/Q+yA6Ih0tBQE8tfdZ6U4PRG0iNvUUjLx/hVyOP53n0UfGBymlfaaXCg==",
"requires": {
"lodash": "^4.17.11"
}
},
"skeletor.js": {
"version": "0.0.1",
"version": "github:skeletorjs/skeletor#bf6d9c86f9fcf224fa9d9af5a25380b77aa4b561",
"from": "github:skeletorjs/skeletor#bf6d9c86f9fcf224fa9d9af5a25380b77aa4b561",
"requires": {
"lodash": "^4.17.14"
......@@ -3192,7 +3195,11 @@
},
"strophe.js": {
"version": "github:strophe/strophejs#c4a94e59877c06dc2395f4ccbd26f3fee67a4c9f",
"from": "strophe.js@github:strophe/strophejs#c4a94e59877c06dc2395f4ccbd26f3fee67a4c9f"
"from": "strophe.js@github:strophe/strophejs#c4a94e59877c06dc2395f4ccbd26f3fee67a4c9f",
"requires": {
"abab": "^2.0.3",
"xmldom": "^0.1.27"
}
},
"twemoji": {
"version": "12.1.5",
......
......@@ -109,6 +109,57 @@ const ChatBoxViews = Overview.extend({
});
function onChatBoxViewsInitialized () {
_converse.chatboxviews = new _converse.ChatBoxViews({
'model': _converse.chatboxes
});
/**
* Triggered once the _converse.ChatBoxViews view-colleciton has been initialized
* @event _converse#chatBoxViewsInitialized
* @example _converse.api.listen.on('chatBoxViewsInitialized', () => { ... });
*/
api.trigger('chatBoxViewsInitialized');
}
function hideChat (view) {
if (view.model.get('id') === 'controlbox') { return; }
u.safeSave(view.model, {'hidden': true});
view.hide();
}
function beforeShowingChatView (view) {
if (_converse.isUniView()) {
/* We only have one chat visible at any one
* time. So before opening a chat, we make sure all other
* chats are hidden.
*/
Object.values(_converse.chatboxviews.xget(view.model.get('id')))
.filter(v => !v.model.get('hidden'))
.forEach(hideChat);
if (view.model.get('hidden')) {
return new Promise(resolve => {
u.safeSave(
view.model,
{'hidden': false}, {
'success': resolve,
'failure': resolve
}
);
});
}
}
}
function calculateViewportHeightUnit () {
const vh = window.innerHeight * 0.01;
document.documentElement.style.setProperty('--vh', `${vh}px`);
}
converse.plugins.add('converse-chatboxviews', {
dependencies: ["converse-chatboxes", "converse-vcard"],
......@@ -135,29 +186,12 @@ converse.plugins.add('converse-chatboxviews', {
_converse.ChatBoxViews = ChatBoxViews;
/************************ BEGIN Event Handlers ************************/
api.listen.on('beforeShowingChatView', beforeShowingChatView);
api.listen.on('chatBoxesInitialized', onChatBoxViewsInitialized);
api.listen.on('cleanup', () => (delete _converse.chatboxviews));
api.listen.on('chatBoxesInitialized', () => {
_converse.chatboxviews = new _converse.ChatBoxViews({
'model': _converse.chatboxes
});
/**
* Triggered once the _converse.ChatBoxViews view-colleciton has been initialized
* @event _converse#chatBoxViewsInitialized
* @example _converse.api.listen.on('chatBoxViewsInitialized', () => { ... });
*/
api.trigger('chatBoxViewsInitialized');
});
api.listen.on('clearSession', () => _converse.chatboxviews.closeAllChatBoxes());
function calculateViewportHeightUnit () {
const vh = window.innerHeight * 0.01;
document.documentElement.style.setProperty('--vh', `${vh}px`);
}
api.listen.on('chatBoxViewsInitialized', () => calculateViewportHeightUnit());
window.addEventListener('resize', () => calculateViewportHeightUnit());
api.listen.on('chatBoxViewsInitialized', calculateViewportHeightUnit);
window.addEventListener('resize', calculateViewportHeightUnit);
/************************ END Event Handlers ************************/
......
......@@ -451,7 +451,11 @@ export const ChatBoxView = View.extend({
},
shouldShowOnTextMessage () {
return !u.isVisible(this.el);
if (_converse.isUniView()) {
return false;
} else {
return !u.isVisible(this.el);
}
},
/**
......
/**
* @module converse-uniview
* @description
* A plugin which ensures that only one chat (private or groupchat) is
* visible at any one time. All other ongoing chats are hidden and kept in the
* background.
*
* This plugin makes sense in mobile, embedded or fullscreen chat environments
* (as configured by the `view_mode` setting).
* @copyright 2020, the Converse.js contributors
* @license Mozilla Public License (MPLv2)
*/
import "converse-chatview";
import { converse } from "@converse/headless/converse-core";
const u = converse.env.utils;
function hideChat (view) {
if (view.model.get('id') === 'controlbox') { return; }
u.safeSave(view.model, {'hidden': true});
view.hide();
}
converse.plugins.add('converse-uniview', {
// It's possible however to make optional dependencies non-optional.
// If the setting "strict_plugin_dependencies" is set to true,
// an error will be raised if the plugin is not found.
dependencies: ['converse-chatboxes', 'converse-muc-views', 'converse-controlbox', 'converse-rosterview'],
overrides: {
// overrides mentioned here will be picked up by converse.js's
// plugin architecture they will replace existing methods on the
// relevant objects or classes.
//
// new functions which don't exist yet can also be added.
ChatBoxes: {
createChatBox (jid, attrs) {
/* Make sure new chat boxes are hidden by default. */
const { _converse } = this.__super__;
if (_converse.isUniView()) {
attrs = attrs || {};
attrs.hidden = true;
}
return this.__super__.createChatBox.call(this, jid, attrs);
}
},
ChatBox: {
maybeShow (force) {
force && u.safeSave(this, {'hidden': false});
const { _converse } = this.__super__;
if (_converse.isUniView() && this.get('hidden')) {
return;
} else {
return this.__super__.maybeShow.apply(this, arguments);
}
}
},
ChatBoxView: {
shouldShowOnTextMessage () {
const { _converse } = this.__super__;
if (_converse.isUniView()) {
return false;
} else {
return this.__super__.shouldShowOnTextMessage.apply(this, arguments);
}
}
}
},
initialize () {
/* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery.
*/
const { _converse } = this;
/************************ BEGIN Event Handlers ************************/
_converse.api.listen.on('beforeShowingChatView', (view) => {
/* We only have one chat visible at any one
* time. So before opening a chat, we make sure all other
* chats are hidden.
*/
if (_converse.isUniView()) {
Object.values(_converse.chatboxviews.xget(view.model.get('id')))
.filter(v => !v.model.get('hidden'))
.forEach(hideChat);
if (view.model.get('hidden')) {
return new Promise(resolve => {
u.safeSave(
view.model,
{'hidden': false}, {
'success': resolve,
'failure': resolve
}
);
});
}
}
});
/************************ END Event Handlers ************************/
}
});
......@@ -29,7 +29,6 @@ import "converse-register"; // XEP-0077 In-band registration
import "converse-roomslist"; // Show currently open chat rooms
import "converse-rosterview";
import "converse-singleton";
import "converse-uniview";
import "./components/converse.js";
/* END: Removable components */
......@@ -57,8 +56,7 @@ const WHITELISTED_PLUGINS = [
'converse-register',
'converse-roomslist',
'converse-rosterview',
'converse-singleton',
'converse-uniview'
'converse-singleton'
];
const initialize = converse.initialize;
......
......@@ -304,7 +304,7 @@ converse.plugins.add('converse-chat', {
return {
'bookmarked': false,
'chat_state': undefined,
'hidden': ['mobile', 'fullscreen'].includes(api.settings.get("view_mode")),
'hidden': _converse.isUniView(),
'message_type': 'chat',
'nickname': undefined,
'num_unread': 0,
......@@ -1133,8 +1133,13 @@ converse.plugins.add('converse-chat', {
});
},
maybeShow () {
return this.trigger("show");
maybeShow (force) {
force && u.safeSave(this, {'hidden': false});
if (_converse.isUniView() && this.get('hidden')) {
return;
} else {
return this.trigger("show");
}
},
/**
......
......@@ -370,7 +370,7 @@ converse.plugins.add('converse-muc', {
'num_unread_general': 0,
'bookmarked': false,
'chat_state': undefined,
'hidden': ['mobile', 'fullscreen'].includes(api.settings.get("view_mode")),
'hidden': _converse.isUniView(),
'message_type': 'groupchat',
'name': '',
'num_unread': 0,
......
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