Преглед изворни кода

Move CONNECTION_STATUS to constant.js

JC Brand пре 2 година
родитељ
комит
3d0e9a7374

+ 2 - 2
src/headless/shared/_converse.js

@@ -19,9 +19,9 @@ import { shouldClearCache } from '../utils/core.js';
  */
 const _converse = {
     log,
-    shouldClearCache, // TODO: Should be moved to utils with next major release
 
-    CONNECTION_STATUS,
+    shouldClearCache, // TODO: Should be moved to utils with next major release
+    CONNECTION_STATUS, // TODO: remove in next major release
     VERSION_NAME,
 
     templates: {},

+ 3 - 2
src/headless/shared/connection/index.js

@@ -2,10 +2,11 @@ import debounce from 'lodash-es/debounce';
 import log from "../../log.js";
 import sizzle from 'sizzle';
 import { BOSH_WAIT } from '../../shared/constants.js';
+import { CONNECTION_STATUS } from '../constants';
 import { Strophe } from 'strophe.js/src/core.js';
 import { _converse, api } from "../../core.js";
-import { getOpenPromise } from '@converse/openpromise';
 import { clearSession, tearDown } from "../../utils/core.js";
+import { getOpenPromise } from '@converse/openpromise';
 import { setUserJID, } from '../../utils/init.js';
 
 const i = Object.keys(Strophe.Status).reduce((max, k) => Math.max(max, Strophe.Status[k]), 0);
@@ -308,7 +309,7 @@ export class Connection extends Strophe.Connection {
      */
     onConnectStatusChanged (status, message) {
         const { __ } = _converse;
-        log.debug(`Status changed to: ${_converse.CONNECTION_STATUS[status]}`);
+        log.debug(`Status changed to: ${CONNECTION_STATUS[status]}`);
         if (status === Strophe.Status.ATTACHFAIL) {
             this.setConnectionStatus(status);
             this.worker_attach_promise?.resolve(false);

+ 2 - 1
src/plugins/controlbox/templates/loginform.js

@@ -1,5 +1,6 @@
 import 'shared/components/brand-heading.js';
 import tplSpinner from 'templates/spinner.js';
+import { CONNECTION_STATUS } from '@converse/headless/shared/constants';
 import { REPORTABLE_STATUSES, PRETTY_CONNECTION_STATUS, CONNECTION_STATUS_CSS_CLASS } from '../constants.js';
 import { __ } from 'i18n';
 import { _converse, api } from "@converse/headless/core";
@@ -139,6 +140,6 @@ export default (el) => {
                 <p class="feedback-subject">${ pretty_status }</p>
                 <p class="feedback-message ${ !conn_feedback_message ? 'hidden' : '' }">${conn_feedback_message}</p>
             </div>
-            ${ (_converse.CONNECTION_STATUS[connection_status] === 'CONNECTING') ? tplSpinner({'classes': 'hor_centered'}) : form_fields(el) }
+            ${ (CONNECTION_STATUS[connection_status] === 'CONNECTING') ? tplSpinner({'classes': 'hor_centered'}) : form_fields(el) }
         </form>`;
 }

+ 5 - 4
src/plugins/register/index.js

@@ -10,6 +10,7 @@ import './panel.js';
 import { __ } from 'i18n';
 import { _converse, api, converse } from '@converse/headless/core';
 import { setActiveForm } from './utils.js';
+import { CONNECTION_STATUS } from '@converse/headless/shared/constants';
 
 // Strophe methods for building stanzas
 const { Strophe } = converse.env;
@@ -35,10 +36,10 @@ converse.plugins.add('converse-register', {
     initialize () {
         const { router } = _converse;
 
-        _converse.CONNECTION_STATUS[Strophe.Status.REGIFAIL] = 'REGIFAIL';
-        _converse.CONNECTION_STATUS[Strophe.Status.REGISTERED] = 'REGISTERED';
-        _converse.CONNECTION_STATUS[Strophe.Status.CONFLICT] = 'CONFLICT';
-        _converse.CONNECTION_STATUS[Strophe.Status.NOTACCEPTABLE] = 'NOTACCEPTABLE';
+        CONNECTION_STATUS[Strophe.Status.REGIFAIL] = 'REGIFAIL';
+        CONNECTION_STATUS[Strophe.Status.REGISTERED] = 'REGISTERED';
+        CONNECTION_STATUS[Strophe.Status.CONFLICT] = 'CONFLICT';
+        CONNECTION_STATUS[Strophe.Status.NOTACCEPTABLE] = 'NOTACCEPTABLE';
 
         api.settings.extend({
             'allow_registration': true,

+ 2 - 1
src/plugins/register/panel.js

@@ -3,6 +3,7 @@ import tplFormInput from "templates/form_input.js";
 import tplFormUrl from "templates/form_url.js";
 import tplFormUsername from "templates/form_username.js";
 import tplRegisterPanel from "./templates/register_panel.js";
+import { CONNECTION_STATUS } from '@converse/headless/shared/constants';
 import { CustomElement } from 'shared/components/element.js';
 import { __ } from 'i18n';
 import { _converse, api, converse } from "@converse/headless/core.js";
@@ -219,7 +220,7 @@ class RegisterPanel extends CustomElement {
             ].includes(status_code)) {
 
             log.error(
-                `Problem during registration: Strophe.Status is ${_converse.CONNECTION_STATUS[status_code]}`
+                `Problem during registration: Strophe.Status is ${CONNECTION_STATUS[status_code]}`
             );
             this.abortRegistration();
         } else if (status_code === Strophe.Status.REGISTERED) {