From 7199e63fd70813bf277d3321835b96634f2443d2 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Fri, 22 Jan 2021 15:45:44 +0100 Subject: [PATCH] Move converse-profile plugin into folder --- src/converse.js | 2 +- src/plugins/omemo.js | 2 +- src/plugins/profile.js | 110 ------------------ src/plugins/profile/index.js | 33 ++++++ src/plugins/profile/statusview.js | 78 +++++++++++++ .../profile}/templates/profile.js | 2 +- 6 files changed, 114 insertions(+), 113 deletions(-) delete mode 100644 src/plugins/profile.js create mode 100644 src/plugins/profile/index.js create mode 100644 src/plugins/profile/statusview.js rename src/{ => plugins/profile}/templates/profile.js (98%) diff --git a/src/converse.js b/src/converse.js index 3702364f5..4864fb7ed 100644 --- a/src/converse.js +++ b/src/converse.js @@ -23,7 +23,7 @@ import "./plugins/muc-views/index.js"; // Views related to MUC import "./plugins/headlines-view/index.js"; import "./plugins/notifications.js"; import "./plugins/omemo.js"; -import "./plugins/profile.js"; +import "./plugins/profile/index.js"; import "./plugins/push.js"; // XEP-0357 Push Notifications import "./plugins/register/index.js"; // XEP-0077 In-band registration import "./plugins/roomslist/index.js"; // Show currently open chat rooms diff --git a/src/plugins/omemo.js b/src/plugins/omemo.js index 2e1c25cbc..982ca6589 100644 --- a/src/plugins/omemo.js +++ b/src/plugins/omemo.js @@ -5,7 +5,7 @@ */ /* global libsignal */ -import "./profile.js"; +import "./profile/index.js"; import '../modals/user-details.js'; import log from "@converse/headless/log"; import { Collection } from "@converse/skeletor/src/collection"; diff --git a/src/plugins/profile.js b/src/plugins/profile.js deleted file mode 100644 index 2ef0cea99..000000000 --- a/src/plugins/profile.js +++ /dev/null @@ -1,110 +0,0 @@ -/** - * @module converse-profile - * @copyright The Converse.js contributors - * @license Mozilla Public License (MPLv2) - */ -import "../modals/chat-status.js"; -import "../modals/profile.js"; -import "./modal.js"; -import "@converse/headless/plugins/status"; -import "@converse/headless/plugins/vcard"; -import UserSettingsModal from "../modals/user-settings"; -import tpl_profile from "../templates/profile.js"; -import { __ } from '../i18n'; -import { _converse, api, converse } from "@converse/headless/core"; - - -converse.plugins.add('converse-profile', { - - dependencies: ["converse-status", "converse-modal", "converse-vcard", "converse-chatboxviews"], - - initialize () { - /* The initialize function gets called as soon as the plugin is - * loaded by converse.js's plugin machinery. - */ - - api.settings.extend({ - 'allow_adhoc_commands': true, - 'show_client_info': true - }); - - - _converse.XMPPStatusView = _converse.ViewWithAvatar.extend({ - tagName: "div", - events: { - "click a.show-profile": "showProfileModal", - "click a.change-status": "showStatusChangeModal", - "click .logout": "logOut" - }, - - initialize () { - this.listenTo(this.model, "change", this.render); - this.listenTo(this.model.vcard, "change", this.render); - }, - - toHTML () { - const chat_status = this.model.get('status') || 'offline'; - return tpl_profile(Object.assign( - this.model.toJSON(), - this.model.vcard.toJSON(), { - chat_status, - 'fullname': this.model.vcard.get('fullname') || _converse.bare_jid, - "showUserSettingsModal": ev => this.showUserSettingsModal(ev), - 'status_message': this.model.get('status_message') || - __("I am %1$s", this.getPrettyStatus(chat_status)), - })); - }, - - afterRender () { - this.renderAvatar(); - }, - - showProfileModal (ev) { - ev.preventDefault(); - api.modal.show(_converse.ProfileModal, {model: this.model}, ev); - }, - - showStatusChangeModal (ev) { - ev.preventDefault(); - api.modal.show(_converse.ChatStatusModal, {model: this.model}, ev); - }, - - showUserSettingsModal(ev) { - ev.preventDefault(); - api.modal.show(UserSettingsModal, {model: this.model, _converse}, ev); - }, - - logOut (ev) { - ev.preventDefault(); - const result = confirm(__("Are you sure you want to log out?")); - if (result === true) { - api.user.logout(); - } - }, - - getPrettyStatus (stat) { - if (stat === 'chat') { - return __('online'); - } else if (stat === 'dnd') { - return __('busy'); - } else if (stat === 'xa') { - return __('away for long'); - } else if (stat === 'away') { - return __('away'); - } else if (stat === 'offline') { - return __('offline'); - } else { - return __(stat) || __('online'); - } - } - }); - - - /******************** Event Handlers ********************/ - api.listen.on('controlBoxPaneInitialized', async view => { - await api.waitUntil('VCardsInitialized'); - _converse.xmppstatusview = new _converse.XMPPStatusView({'model': _converse.xmppstatus}); - view.el.insertAdjacentElement('afterBegin', _converse.xmppstatusview.render().el); - }); - } -}); diff --git a/src/plugins/profile/index.js b/src/plugins/profile/index.js new file mode 100644 index 000000000..4bf480e5f --- /dev/null +++ b/src/plugins/profile/index.js @@ -0,0 +1,33 @@ +/** + * @copyright The Converse.js contributors + * @license Mozilla Public License (MPLv2) + */ +import "modals/chat-status.js"; +import "modals/profile.js"; +import "../modal.js"; +import "@converse/headless/plugins/status"; +import "@converse/headless/plugins/vcard"; +import XMPPStatusView from './statusview.js'; +import { _converse, api, converse } from "@converse/headless/core"; + + +converse.plugins.add('converse-profile', { + + dependencies: ["converse-status", "converse-modal", "converse-vcard", "converse-chatboxviews"], + + initialize () { + api.settings.extend({ + 'allow_adhoc_commands': true, + 'show_client_info': true + }); + + _converse.XMPPStatusView = XMPPStatusView; + + /******************** Event Handlers ********************/ + api.listen.on('controlBoxPaneInitialized', async view => { + await api.waitUntil('VCardsInitialized'); + _converse.xmppstatusview = new _converse.XMPPStatusView({'model': _converse.xmppstatus}); + view.el.insertAdjacentElement('afterBegin', _converse.xmppstatusview.render().el); + }); + } +}); diff --git a/src/plugins/profile/statusview.js b/src/plugins/profile/statusview.js new file mode 100644 index 000000000..ff6c480f4 --- /dev/null +++ b/src/plugins/profile/statusview.js @@ -0,0 +1,78 @@ +import UserSettingsModal from "modals/user-settings"; +import ViewWithAvatar from 'shared/avatar.js'; +import tpl_profile from "./templates/profile.js"; +import { __ } from 'i18n'; +import { _converse, api } from "@converse/headless/core"; + + +const XMPPStatusView = ViewWithAvatar.extend({ + tagName: "div", + events: { + "click a.show-profile": "showProfileModal", + "click a.change-status": "showStatusChangeModal", + "click .logout": "logOut" + }, + + initialize () { + this.listenTo(this.model, "change", this.render); + this.listenTo(this.model.vcard, "change", this.render); + }, + + toHTML () { + const chat_status = this.model.get('status') || 'offline'; + return tpl_profile(Object.assign( + this.model.toJSON(), + this.model.vcard.toJSON(), { + chat_status, + 'fullname': this.model.vcard.get('fullname') || _converse.bare_jid, + "showUserSettingsModal": ev => this.showUserSettingsModal(ev), + 'status_message': this.model.get('status_message') || + __("I am %1$s", this.getPrettyStatus(chat_status)), + })); + }, + + afterRender () { + this.renderAvatar(); + }, + + showProfileModal (ev) { + ev.preventDefault(); + api.modal.show(_converse.ProfileModal, {model: this.model}, ev); + }, + + showStatusChangeModal (ev) { + ev.preventDefault(); + api.modal.show(_converse.ChatStatusModal, {model: this.model}, ev); + }, + + showUserSettingsModal(ev) { + ev.preventDefault(); + api.modal.show(UserSettingsModal, {model: this.model, _converse}, ev); + }, + + logOut (ev) { + ev.preventDefault(); + const result = confirm(__("Are you sure you want to log out?")); + if (result === true) { + api.user.logout(); + } + }, + + getPrettyStatus (stat) { + if (stat === 'chat') { + return __('online'); + } else if (stat === 'dnd') { + return __('busy'); + } else if (stat === 'xa') { + return __('away for long'); + } else if (stat === 'away') { + return __('away'); + } else if (stat === 'offline') { + return __('offline'); + } else { + return __(stat) || __('online'); + } + } +}); + +export default XMPPStatusView; diff --git a/src/templates/profile.js b/src/plugins/profile/templates/profile.js similarity index 98% rename from src/templates/profile.js rename to src/plugins/profile/templates/profile.js index 5e1682eb6..1b3fc2988 100644 --- a/src/templates/profile.js +++ b/src/plugins/profile/templates/profile.js @@ -1,4 +1,4 @@ -import { __ } from '../i18n'; +import { __ } from 'i18n'; import { api } from "@converse/headless/core"; import { html } from "lit-html";