|
@@ -1,22 +1,34 @@
|
|
/**
|
|
/**
|
|
* @typedef {import('../chat/model.js').default} ChatBox
|
|
* @typedef {import('../chat/model.js').default} ChatBox
|
|
*/
|
|
*/
|
|
-import _converse from '../../shared/_converse.js';
|
|
|
|
-import log from "@converse/log";
|
|
|
|
import { Strophe } from 'strophe.js';
|
|
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 {string} jid
|
|
* @param {object} attrs
|
|
* @param {object} attrs
|
|
* @param {new (attrs: object, options: object) => ChatBox} Model
|
|
* @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());
|
|
jid = Strophe.getBareJidFromJid(jid.toLowerCase());
|
|
- Object.assign(attrs, {'jid': jid, 'id': jid});
|
|
|
|
|
|
+ Object.assign(attrs, { 'jid': jid, 'id': jid });
|
|
let chatbox;
|
|
let chatbox;
|
|
try {
|
|
try {
|
|
- chatbox = new Model(attrs, {'collection': _converse.state.chatboxes});
|
|
|
|
|
|
+ chatbox = new Model(attrs, { 'collection': _converse.state.chatboxes });
|
|
} catch (e) {
|
|
} catch (e) {
|
|
log.error(e);
|
|
log.error(e);
|
|
return null;
|
|
return null;
|