From 111b1f573909e3701eabfb836c14fd35112107e7 Mon Sep 17 00:00:00 2001 From: ubermanu <e.vodor@gmail.com> Date: Wed, 10 Mar 2021 14:38:43 +0100 Subject: [PATCH] move deferred into utils and some plugins into the plugins folder --- src/plugins/sib-custom-hats.js | 23 +++++++ src/plugins/sib-remove-notifications.js | 26 ++++++++ src/solid-xmpp-chat.js | 81 +++---------------------- src/utils.js | 10 +++ 4 files changed, 67 insertions(+), 73 deletions(-) create mode 100644 src/plugins/sib-custom-hats.js create mode 100644 src/plugins/sib-remove-notifications.js create mode 100644 src/utils.js diff --git a/src/plugins/sib-custom-hats.js b/src/plugins/sib-custom-hats.js new file mode 100644 index 0000000..334097d --- /dev/null +++ b/src/plugins/sib-custom-hats.js @@ -0,0 +1,23 @@ +/** + * Transform hats to custom values. + */ +converse.plugins.add('sib-custom-hats', { + overrides: { + getHats: function() { + const hat_conversions = { 'admin': 'Administrateur' }; + const hats = this.__super__.getHats.apply(this, arguments); + if (!hat_conversions) { + return hats; + } else { + const role_affiliations = Object.keys(hat_conversions); + return hats.map((hat) => { + if (role_affiliations.includes(hat.title)) { + return ({ title: hat_conversions[hat.title] }); + } else { + return hat; + } + }); + } + }, + }, +}); diff --git a/src/plugins/sib-remove-notifications.js b/src/plugins/sib-remove-notifications.js new file mode 100644 index 0000000..dd11271 --- /dev/null +++ b/src/plugins/sib-remove-notifications.js @@ -0,0 +1,26 @@ +/** + * Override converse's request permission with an empty function + * so that permission request for notifications don't happen. + */ +converse.plugins.add('sib-remove-notifications', { + overrides: { + requestPermission: function() { + }, + showMessageNotification: function() { + }, + showChatStateNotification: function() { + }, + showContactRequestNotification: function() { + }, + showFeedbackNotification: function() { + }, + handleChatStateNotification: function() { + }, + handleMessageNotification: function() { + }, + handleContactRequestNotification: function() { + }, + handleFeedback: function() { + }, + }, +}); diff --git a/src/solid-xmpp-chat.js b/src/solid-xmpp-chat.js index 95e2078..accf5e8 100644 --- a/src/solid-xmpp-chat.js +++ b/src/solid-xmpp-chat.js @@ -1,19 +1,13 @@ -import './conversejs/converse.min.js'; -import './conversejs/emojis.js'; -import './plugins/converse-rai.js'; import { Sib, store, StoreMixin } from 'https://cdn.skypack.dev/@startinblox/core@0.15'; +import { Deferred } from './utils.js'; import ComponentPath from './path.js'; -class Deferred { - constructor() { - this.promise = new Promise(((resolve, reject) => { - this.resolve = resolve; - this.reject = reject; - }).bind(this)); - this.then = this.promise.then.bind(this.promise); - this.catch = this.promise.catch.bind(this.promise); - } -} +import './conversejs/converse.min.js'; +import './conversejs/emojis.js'; + +import './plugins/converse-rai.js'; +import './plugins/sib-custom-hats.js'; +import './plugins/sib-remove-notifications.js'; export const SolidXMPPChat = { name: 'solid-xmpp-chat', @@ -314,65 +308,6 @@ export const SolidXMPPChat = { }, }); - // Transform hats to custom values - converse.plugins.add('custom-hats', { - overrides: { - getHats: function() { - const hat_conversions = { 'admin': 'Administrateur' }; - const _converse = this; - const hats = _converse.__super__.getHats.apply(this, arguments); - if (!hat_conversions) { - return hats; - } else { - const role_affiliations = Object.keys(hat_conversions); - const custom_hats = hats.map((hat) => { - if (role_affiliations.includes(hat.title)) { - return ({ title: hat_conversions[hat.title] }); - } else { - return hat; - } - }); - return custom_hats; - } - }, - }, - }); - //Highly experimental DO NOT USE -// converse.plugins.add('custom-storage', { -// overrides: { -// createStore: function () { -// const _converse = this; -// if (arguments.length > 1){ -// arguments[1] = "none"; -// } -// return _converse.__super__.createStore.apply(this, arguments); -// } -// } -// }); - //Override converse's request permission with an empty function - //so that permission request for notifications don't happen - converse.plugins.add('remove-notifications', { - overrides: { - requestPermission: function() { - }, - showMessageNotification: function() { - }, - showChatStateNotification: function() { - }, - showContactRequestNotification: function() { - }, - showFeedbackNotification: function() { - }, - handleChatStateNotification: function() { - }, - handleMessageNotification: function() { - }, - handleContactRequestNotification: function() { - }, - handleFeedback: function() { - }, - }, - }); // Initialize deferred resolution plugin converse.plugins.add('conversejs-sib-focused', { initialize() { @@ -463,7 +398,7 @@ export const SolidXMPPChat = { 'conversejs-changechat', 'conversejs-rai', 'custom-hats', - 'remove-notifications', + 'sib-remove-notifications', ], }); diff --git a/src/utils.js b/src/utils.js new file mode 100644 index 0000000..68e3bce --- /dev/null +++ b/src/utils.js @@ -0,0 +1,10 @@ +export class Deferred { + constructor() { + this.promise = new Promise(((resolve, reject) => { + this.resolve = resolve; + this.reject = reject; + }).bind(this)); + this.then = this.promise.then.bind(this.promise); + this.catch = this.promise.catch.bind(this.promise); + } +} -- GitLab