Explorar o código

move `onClearSession` to the more appropriate plugin

JC Brand hai 1 semana
pai
achega
19004844e2

+ 0 - 2
src/headless/plugins/chat/plugin.js

@@ -11,7 +11,6 @@ import {
     autoJoinChats,
     enableCarbons,
     handleMessageStanza,
-    onClearSession,
     routeToChat,
     registerMessageHandlers,
 } from './utils.js';
@@ -51,7 +50,6 @@ converse.plugins.add('converse-chat', {
 
         api.listen.on('chatBoxesFetched', autoJoinChats);
         api.listen.on('presencesInitialized', registerMessageHandlers);
-        api.listen.on('clearSession', onClearSession);
 
         api.listen.on('connected', () => enableCarbons());
         api.listen.on('reconnected', () => enableCarbons());

+ 1 - 14
src/headless/plugins/chat/utils.js

@@ -13,8 +13,7 @@ import converse from "../../shared/api/public.js";
 import log from "@converse/log";
 import { isArchived, isHeadline, isMUCPrivateMessage, isServerMessage, } from '../../shared/parsers';
 import { parseMessage } from './parsers.js';
-import { shouldClearCache } from '../../utils/session.js';
-import { CONTROLBOX_TYPE, PRIVATE_CHAT_TYPE } from "../../shared/constants.js";
+import { PRIVATE_CHAT_TYPE } from "../../shared/constants.js";
 
 const { Strophe, u } = converse.env;
 
@@ -30,18 +29,6 @@ export function routeToChat (event) {
     api.chats.open(jid);
 }
 
-export async function onClearSession () {
-    if (shouldClearCache(_converse)) {
-        const { chatboxes } = _converse.state;
-        await Promise.all(
-            chatboxes.map(/** @param {ChatBox} c */(c) => c.messages?.clearStore({ 'silent': true }))
-        );
-        chatboxes.clearStore(
-            { 'silent': true },
-            /** @param {Model} o */(o) => o.get('type') !== CONTROLBOX_TYPE);
-    }
-}
-
 /**
  * Given a stanza, determine whether it's a new
  * message, i.e. not a MAM archived one.

+ 2 - 0
src/headless/plugins/chatboxes/index.js

@@ -8,6 +8,7 @@ import api from '../../shared/api/index.js';
 import converse from "../../shared/api/public.js";
 import { isUniView } from '../../utils/session.js';
 import chatboxes_api from './api.js';
+import { onClearSession } from './utils.js';
 import "../emoji/index.js";
 
 const { Strophe } = converse.env;
@@ -54,6 +55,7 @@ converse.plugins.add('converse-chatboxes', {
 
         api.listen.on('presencesInitialized', (reconnecting) => chatboxes.onConnected(reconnecting));
         api.listen.on('reconnected', () => chatboxes.forEach(m => m.onReconnection()));
+        api.listen.on('clearSession', onClearSession);
 
         // XXX: Would be nice to keep track of the last open chat and to show that again.
         api.listen.on('chatBoxClosed', () => {

+ 17 - 5
src/headless/plugins/chatboxes/utils.js

@@ -1,22 +1,34 @@
 /**
  * @typedef {import('../chat/model.js').default} ChatBox
  */
-import _converse from '../../shared/_converse.js';
-import log from "@converse/log";
 import { Strophe } from 'strophe.js';
+import log from '@converse/log';
+import _converse from '../../shared/_converse.js';
+import { shouldClearCache } from '../../utils/session.js';
+import * as constants from '../../shared/constants.js';
 
+export async function onClearSession() {
+    if (shouldClearCache(_converse)) {
+        const { chatboxes } = _converse.state;
+        await Promise.all(chatboxes.map(/** @param {ChatBox} c */ (c) => c.messages?.clearStore({ 'silent': true })));
+        chatboxes.clearStore(
+            { silent: true },
+            /** @param {import('../../shared/chatbox').default} o */ (o) => o.get('type') !== constants.CONTROLBOX_TYPE
+        );
+    }
+}
 
 /**
  * @param {string} jid
  * @param {object} attrs
  * @param {new (attrs: object, options: object) => ChatBox} Model
  */
-export async function createChatBox (jid, attrs, Model) {
+export async function createChatBox(jid, attrs, Model) {
     jid = Strophe.getBareJidFromJid(jid.toLowerCase());
-    Object.assign(attrs, {'jid': jid, 'id': jid});
+    Object.assign(attrs, { 'jid': jid, 'id': jid });
     let chatbox;
     try {
-        chatbox = new Model(attrs, {'collection': _converse.state.chatboxes});
+        chatbox = new Model(attrs, { 'collection': _converse.state.chatboxes });
     } catch (e) {
         log.error(e);
         return null;

+ 0 - 1
src/headless/types/plugins/chat/utils.d.ts

@@ -1,5 +1,4 @@
 export function routeToChat(event: any): void;
-export function onClearSession(): Promise<void>;
 /**
  * Given a stanza, determine whether it's a new
  * message, i.e. not a MAM archived one.

+ 1 - 0
src/headless/types/plugins/chatboxes/utils.d.ts

@@ -1,3 +1,4 @@
+export function onClearSession(): Promise<void>;
 /**
  * @param {string} jid
  * @param {object} attrs

+ 1 - 1
src/plugins/controlbox/controlbox.js

@@ -64,7 +64,7 @@ class ControlBoxView extends CustomElement {
         if (api.settings.get('sticky_controlbox') || api.settings.get('view_mode') !== 'overlayed') {
             return;
         }
-        u.safeSave(this.model, { 'closed': true });
+        u.safeSave(this.model, { closed: true });
         api.trigger('controlBoxClosed', this);
         return this;
     }

+ 1 - 1
src/plugins/controlbox/utils.js

@@ -39,7 +39,7 @@ export function clearSession() {
     const { chatboxviews } = _converse.state;
     const view = chatboxviews?.get('controlbox');
     if (view) {
-        u.safeSave(view.model, { 'connected': false });
+        u.safeSave(view.model, { connected: false });
         if (view?.controlbox_pane) {
             view.controlbox_pane.remove();
             delete view.controlbox_pane;