Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
jcbrand committed Nov 22, 2023
1 parent 6417062 commit 64c413f
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 25 deletions.
6 changes: 0 additions & 6 deletions src/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
//
// Once the rest converse.js has been loaded, window.converse will be replaced
// with the full-fledged public API.
/**
* @typedef {module:shared.converse.ConversePrivateGlobal} ConversePrivateGlobal
*/

const plugins = {};

Expand Down Expand Up @@ -68,9 +65,6 @@ const converse = {
}
}

/**
* @typedef {Window & {converse: ConversePrivateGlobal} } window
*/
window['converse'] = converse;

/**
Expand Down
2 changes: 2 additions & 0 deletions src/headless/shared/_converse.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class ConversePrivateGlobal extends EventEmitter(Object) {

this.strict_plugin_dependencies = false;

this.pluggable = null;

this.templates = {};

this.promises = {
Expand Down
7 changes: 6 additions & 1 deletion src/headless/shared/api/public.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @typedef {module:shared-api-public.ConversePrivateGlobal} ConversePrivateGlobal
*/
import ConnectionFeedback from './../connection/feedback.js';
import URI from 'urijs';
import _converse from '../_converse.js';
Expand Down Expand Up @@ -25,6 +28,8 @@ import {
} from '../../utils/init.js';

/**
* @typedef {Window & {converse: ConversePrivateGlobal} } window
*
* ### The Public API
*
* This namespace contains public API methods which are are
Expand All @@ -37,7 +42,7 @@ import {
* @global
* @namespace converse
*/
export const converse = Object.assign(window.converse || {}, {
export const converse = Object.assign(/** @type {ConversePrivateGlobal} */(window).converse || {}, {

CHAT_STATES,

Expand Down
15 changes: 9 additions & 6 deletions src/headless/shared/api/send.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @typedef {import('strophe.js/src/builder.js').Builder} Strophe.Builder
*/
import _converse from '../_converse.js';
import log from '../../log.js';
import { Strophe, toStanza } from 'strophe.js';
Expand All @@ -7,8 +10,8 @@ export default {
/**
* Allows you to send XML stanzas.
* @method _converse.api.send
* @param { Element | Stanza } stanza
* @return { void }
* @param {Element|Strophe.Builder} stanza
* @return {void}
* @example
* const msg = converse.env.$msg({
* 'from': 'juliet@example.com/balcony',
Expand Down Expand Up @@ -41,12 +44,12 @@ export default {
/**
* Send an IQ stanza
* @method _converse.api.sendIQ
* @param { Element } stanza
* @param { number } [timeout] - The default timeout value is taken from
* @param {Element|Strophe.Builder} stanza
* @param {number} [timeout] - The default timeout value is taken from
* the `stanza_timeout` configuration setting.
* @param { Boolean } [reject=true] - Whether an error IQ should cause the promise
* @param {boolean} [reject=true] - Whether an error IQ should cause the promise
* to be rejected. If `false`, the promise will resolve instead of being rejected.
* @returns { Promise } A promise which resolves (or potentially rejected) once we
* @returns {Promise} A promise which resolves (or potentially rejected) once we
* receive a `result` or `error` stanza or once a timeout is reached.
* If the IQ stanza being sent is of type `result` or `error`, there's
* nothing to wait for, so an already resolved promise is returned.
Expand Down
2 changes: 1 addition & 1 deletion src/headless/shared/connection/feedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Feedback extends Model {
initialize () {
super.initialize();
const { api } = _converse;
this.on('change', () => api.trigger('connfeedback', _converse.connfeedback));
this.on('change', () => api.trigger('connfeedback', _converse.state.connfeedback));
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/headless/shared/connection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class Connection extends Strophe.Connection {
this.reconnecting = true;
await tearDown();

const conn_status = _converse.connfeedback.get('connection_status');
const conn_status = _converse.state.connfeedback.get('connection_status');
if (conn_status === Strophe.Status.CONNFAIL) {
this.switchTransport();
} else if (conn_status === Strophe.Status.AUTHFAIL && api.settings.get("authentication") === ANONYMOUS) {
Expand Down Expand Up @@ -246,7 +246,7 @@ export class Connection extends Strophe.Connection {

setConnectionStatus (status, message) {
this.status = status;
_converse.connfeedback.set({'connection_status': status, message });
_converse.state.connfeedback.set({'connection_status': status, message });
}

async finishDisconnection () {
Expand Down Expand Up @@ -393,7 +393,7 @@ export class Connection extends Strophe.Connection {

hasResumed () {
if (api.settings.get("connection_options")?.worker || this.isType('bosh')) {
return _converse.connfeedback.get('connection_status') === Strophe.Status.ATTACHED;
return _converse.state.connfeedback.get('connection_status') === Strophe.Status.ATTACHED;
} else {
// Not binding means that the session was resumed.
return !this.do_bind;
Expand Down
2 changes: 1 addition & 1 deletion src/headless/shared/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { sprintf } from 'sprintf-js';
* @namespace i18n
*/
export default {
// eslint-disable-next-line @typescript-eslint/no-empty-function
initialize () {},

/**
Expand All @@ -18,7 +19,6 @@ export default {
* @method __
* @private
* @memberOf i18n
* @param { String } str
*/
__ (...args) {
return sprintf(...args);
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/controlbox/controlbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class ControlBox extends CustomElement {
}

setModel () {
this.model = _converse.chatboxes.get('controlbox');
this.listenTo(_converse.connfeedback, 'change:connection_status', () => this.requestUpdate());
this.model = _converse.state.chatboxes.get('controlbox');
this.listenTo(_converse.state.connfeedback, 'change:connection_status', () => this.requestUpdate());
this.listenTo(this.model, 'change:active-form', () => this.requestUpdate());
this.listenTo(this.model, 'change:connected', () => this.requestUpdate());
this.listenTo(this.model, 'change:closed', () => !this.model.get('closed') && this.afterShown());
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/controlbox/loginform.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { CustomElement } from 'shared/components/element.js';
import { _converse, api, converse } from '@converse/headless';
import { updateSettingsWithFormData, validateJID } from './utils.js';

const { Strophe, u } = converse.env;
const { Strophe } = converse.env;


class LoginForm extends CustomElement {

initialize () {
this.listenTo(_converse.connfeedback, 'change', () => this.requestUpdate());
this.listenTo(_converse.state.connfeedback, 'change', () => this.requestUpdate());
this.handler = () => this.requestUpdate()
}

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/controlbox/templates/controlbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { Strophe } = converse.env;


function whenNotConnected (o) {
const connection_status = _converse.connfeedback.get('connection_status');
const connection_status = _converse.state.connfeedback.get('connection_status');
if ([Strophe.Status.RECONNECTING, Strophe.Status.CONNECTING].includes(connection_status)) {
return tplSpinner();
}
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/controlbox/templates/loginform.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,14 @@ const form_fields = (el) => {
};

export default (el) => {
const connection_status = _converse.connfeedback.get('connection_status');
const { connfeedback } = _converse.state;
const connection_status = connfeedback.get('connection_status');
let feedback_class, pretty_status;
if (REPORTABLE_STATUSES.includes(connection_status)) {
pretty_status = PRETTY_CONNECTION_STATUS[connection_status];
feedback_class = CONNECTION_STATUS_CSS_CLASS[connection_status];
}
const conn_feedback_message = _converse.connfeedback.get('message');
const conn_feedback_message = connfeedback.get('message');
return html` <converse-brand-heading></converse-brand-heading>
<form id="converse-login" class="converse-form" method="post" @submit=${el.onLoginFormSubmitted}>
<div class="conn-feedback fade-in ${!pretty_status ? 'hidden' : feedback_class}">
Expand Down

0 comments on commit 64c413f

Please sign in to comment.