Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jcbrand/npm update #3355

Merged
merged 5 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18.15.0
v18.19.1
1 change: 0 additions & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ module.exports = function(config) {
{ pattern: 'dist/*.css.map', included: false },
{ pattern: "dist/emojis.js", served: true },
"src/shared/tests/tests.css",
"node_modules/lodash/lodash.min.js",
"dist/converse.js",
"dist/converse.css",
{ pattern: "dist/images/**/*.*", included: false },
Expand Down
2,232 changes: 835 additions & 1,397 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"@converse/headless": "file:src/headless",
"@types/webappsec-credential-management": "^0.6.8",
"@typescript-eslint/eslint-plugin": "^7.3.1",
"@typescript-eslint/parser": "^7.3.1",
"autoprefixer": "^10.4.5",
"babel-loader": "^9.1.0",
"bootstrap.native-loader": "2.0.0",
Expand Down Expand Up @@ -108,7 +109,6 @@
"sass-loader": "^13.1.0",
"style-loader": "^3.1.0",
"typescript": "^4.9.5",
"typescript-eslint-parser": "^22.0.0",
"uglify-js": "^3.17.4",
"webpack": "^5.90.3",
"webpack-cli": "^5.1.4",
Expand All @@ -121,7 +121,6 @@
"client-compress": "^2.2.2",
"dayjs": "^1.11.8",
"dompurify": "^3.0.8",
"dpdm": "^3.14.0",
"favico.js-slevomat": "^0.3.11",
"gifuct-js": "^2.1.2",
"jed": "1.1.1",
Expand Down
12 changes: 6 additions & 6 deletions src/headless/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import converse from './shared/api/public.js';

dayjs.extend(advancedFormat);

/* START: Removable components
* --------------------
* The following components may be removed if they're not needed.
*/
// START: Removable components
// ---------------------------
// The following components may be removed if they're not needed.
import './plugins/bookmarks/index.js'; // XEP-0199 XMPP Ping
import './plugins/bosh/index.js'; // XEP-0206 BOSH
import './plugins/caps/index.js'; // XEP-0115 Entity Capabilities
Expand All @@ -37,10 +36,11 @@ export { RosterContact, RosterContacts, Presence, Presences } from './plugins/ro
import './plugins/smacks/index.js'; // XEP-0198 Stream Management
export { XMPPStatus } from './plugins/status/index.js';
export { VCard, VCards } from './plugins/vcard/index.js'; // XEP-0054 VCard-temp
/* END: Removable components */
// ---------------------------
// END: Removable components

import log from './log.js';

import log from './log.js';
export { api, converse, _converse, i18n, log, u };

export default converse;
2 changes: 1 addition & 1 deletion src/headless/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"pluggable.js": "3.0.1",
"sizzle": "^2.3.5",
"sprintf-js": "^1.1.2",
"strophe.js": "2.0.0",
"strophe.js": "strophe/strophejs#d6cb60012fd243a1c3f1033e8acd6c80264d65cf",
"urijs": "^1.19.10"
},
"devDependencies": {}
Expand Down
13 changes: 6 additions & 7 deletions src/headless/plugins/chat/message.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/**
* @typedef {import('@converse/skeletor').Model} Model
*/
import sizzle from 'sizzle';
import ModelWithContact from './model-with-contact.js';
import _converse from '../../shared/_converse.js';
import api from '../../shared/api/index.js';
import converse from '../../shared/api/public.js';
import dayjs from 'dayjs';
import log from '../../log.js';
import { getOpenPromise } from '@converse/openpromise';
import { SUCCESS, FAILURE } from '../../shared/constants.js';

const { Strophe, sizzle, u } = converse.env;
import { Strophe, $iq } from 'strophe.js';
import { getUniqueId } from '../../utils/index.js';

/**
* Represents a (non-MUC) message.
Expand All @@ -23,7 +23,7 @@ class Message extends ModelWithContact {

defaults () {
return {
'msgid': u.getUniqueId(),
'msgid': getUniqueId(),
'time': new Date().toISOString(),
'is_ephemeral': false
};
Expand Down Expand Up @@ -80,7 +80,7 @@ class Message extends ModelWithContact {
const is_ephemeral = this.isEphemeral();
if (is_ephemeral) {
const timeout = typeof is_ephemeral === "number" ? is_ephemeral : 10000;
this.ephemeral_timer = window.setTimeout(() => this.safeDestroy(), timeout);
this.ephemeral_timer = setTimeout(() => this.safeDestroy(), timeout);
}
}

Expand Down Expand Up @@ -192,8 +192,7 @@ class Message extends ModelWithContact {
sendSlotRequestStanza () {
if (!this.file) return Promise.reject(new Error('file is undefined'));

const iq = converse.env
.$iq({
const iq = $iq({
'from': _converse.session.get('jid'),
'to': this.get('slot_request_url'),
'type': 'get'
Expand Down
24 changes: 15 additions & 9 deletions src/headless/plugins/chat/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,17 +485,17 @@ class ChatBox extends ModelWithContact {
*/
setChatState (state, options) {
if (this.chat_state_timeout !== undefined) {
window.clearTimeout(this.chat_state_timeout);
clearTimeout(this.chat_state_timeout);
delete this.chat_state_timeout;
}
if (state === COMPOSING) {
this.chat_state_timeout = window.setTimeout(
this.chat_state_timeout = setTimeout(
this.setChatState.bind(this),
_converse.TIMEOUTS.PAUSED,
PAUSED
);
} else if (state === PAUSED) {
this.chat_state_timeout = window.setTimeout(
this.chat_state_timeout = setTimeout(
this.setChatState.bind(this),
_converse.TIMEOUTS.INACTIVE,
INACTIVE
Expand Down Expand Up @@ -1015,7 +1015,7 @@ class ChatBox extends ModelWithContact {
return;
}
const data = item.dataforms.where({'FORM_TYPE': {'value': Strophe.NS.HTTPUPLOAD, 'type': "hidden"}}).pop();
const max_file_size = window.parseInt((data?.attributes || {})['max-file-size']?.value);
const max_file_size = parseInt((data?.attributes || {})['max-file-size']?.value, 10);
const slot_request_url = item?.id;

if (!slot_request_url) {
Expand All @@ -1036,12 +1036,18 @@ class ChatBox extends ModelWithContact {
*/
file = await api.hook('beforeFileUpload', this, file);

if (!window.isNaN(max_file_size) && file.size > max_file_size) {
if (!isNaN(max_file_size) && file.size > max_file_size) {
const size = filesize(max_file_size);
const message = Array.isArray(size)
? __('The size of your file, %1$s, exceeds the maximum allowed by your server.', file.name)
: __(
'The size of your file, %1$s, exceeds the maximum allowed by your server, which is %2$s.',
file.name, size
);
return this.createMessage({
'message': __('The size of your file, %1$s, exceeds the maximum allowed by your server, which is %2$s.',
file.name, filesize(max_file_size)),
'type': 'error',
'is_ephemeral': true
message,
type: 'error',
is_ephemeral: true
});
} else {
const initial_attrs = await this.getOutgoingMessageAttributes();
Expand Down
2 changes: 1 addition & 1 deletion src/headless/plugins/muc/muc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2256,7 +2256,7 @@ class MUC extends ChatBox {
const actors_per_traffic_state = converse.MUC_TRAFFIC_STATES_LIST.reduce(reducer, {});
const actors_per_role_change = converse.MUC_ROLE_CHANGES_LIST.reduce(reducer, {});
this.notifications.set(Object.assign(actors_per_chat_state, actors_per_traffic_state, actors_per_role_change));
window.setTimeout(() => this.removeNotification(actor, state), 10000);
setTimeout(() => this.removeNotification(actor, state), 10000);
}

handleMetadataFastening (attrs) {
Expand Down
11 changes: 4 additions & 7 deletions src/headless/plugins/roster/contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ class RosterContacts extends Collection {
* Register a handler for roster IQ "set" stanzas, which update
* roster contacts.
*/
// eslint-disable-next-line class-methods-use-this
registerRosterHandler () {
// Register a handler for roster IQ "set" stanzas, which update
// roster contacts.
api.connection.get().addHandler(iq => {
api.connection.get().addHandler((iq) => {
_converse.state.roster.onRosterPush(iq);
return true;
}, Strophe.NS.ROSTER, 'iq', "set");
Expand All @@ -50,14 +49,12 @@ class RosterContacts extends Collection {
* Register a handler for RosterX message stanzas, which are
* used to suggest roster contacts to a user.
*/
// eslint-disable-next-line class-methods-use-this
registerRosterXHandler () {
let t = 0;
const connection = api.connection.get();
connection.addHandler(
function (msg) {
const { roster } = _converse.state;
window.setTimeout(function () {
connection.addHandler((msg) => {
setTimeout(() => {
const { roster } = _converse.state;
api.connection.get().flush();
roster.subscribeToSuggestedItems(msg);
}, t);
Expand Down
4 changes: 2 additions & 2 deletions src/headless/plugins/status/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export function registerIntervalHandler () {
window.addEventListener('keypress', onUserActivity);
window.addEventListener('mousemove', onUserActivity);
window.addEventListener(getUnloadEvent(), onUserActivity, {'once': true, 'passive': true});
everySecondTrigger = window.setInterval(onEverySecond, 1000);
everySecondTrigger = setInterval(onEverySecond, 1000);
}

export function tearDown () {
Expand All @@ -158,7 +158,7 @@ export function tearDown () {
window.removeEventListener('mousemove', onUserActivity);
window.removeEventListener(getUnloadEvent(), onUserActivity);
if (everySecondTrigger) {
window.clearInterval(everySecondTrigger);
clearInterval(everySecondTrigger);
everySecondTrigger = null;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/headless/plugins/vcard/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ export async function getVCard (jid) {
} catch (error) {
return {
jid,
error,
vcard: isElement(error) ? error : null,
stanza: isElement(error) ? error : null,
error: isElement(error) ? null : error,
vcard_error: (new Date()).toISOString()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/headless/shared/api/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const api = {

password = password || api.settings.get("password");
const credentials = (jid && password) ? { jid, password } : null;
attemptNonPreboundSession(credentials, automatic);
await attemptNonPreboundSession(credentials, automatic);
},

/**
Expand Down
4 changes: 2 additions & 2 deletions src/headless/shared/connection/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import events_api from '../api/events.js';
import { Connection, MockConnection } from './index.js';
import { PREBIND } from '../constants.js';
import { Strophe } from 'strophe.js';
import { getConnectionServiceURL, setUpXMLLogging } from './utils.js';
import { getConnectionServiceURL, setStropheLogLevel } from './utils.js';
import { isSameDomain } from '../../utils/jid.js';
import { isTestEnv } from '../../utils/session.js';
import { settings_api } from '../settings/api.js';
Expand Down Expand Up @@ -40,7 +40,7 @@ export default {
})
);

setUpXMLLogging(connection);
setStropheLogLevel();
/**
* Triggered once the `Connection` constructor has been initialized, which
* will be responsible for managing the connection to the XMPP server.
Expand Down
2 changes: 1 addition & 1 deletion src/headless/shared/connection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class Connection extends Strophe.Connection {
async onDomainDiscovered (response) {
const { api } = _converse;
const text = await response.text();
const xrd = (new window.DOMParser()).parseFromString(text, "text/xml").firstElementChild;
const xrd = (new DOMParser()).parseFromString(text, "text/xml").firstElementChild;
if (xrd.nodeName != "XRD" || xrd.namespaceURI != "http://docs.oasis-open.org/ns/xri/xrd-1.0") {
return log.warn("Could not discover XEP-0156 connection methods");
}
Expand Down
10 changes: 5 additions & 5 deletions src/headless/shared/connection/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ export function generateResource () {
return `/converse.js-${Math.floor(Math.random() * 139749528).toString()}`;
}

export function setUpXMLLogging (connection) {
export function setStropheLogLevel () {
const level = settings_api.get('loglevel');
Strophe.setLogLevel(Strophe.LogLevel[level.toUpperCase()]);

const lmap = {};
lmap[Strophe.LogLevel.DEBUG] = 'debug';
lmap[Strophe.LogLevel.INFO] = 'info';
lmap[Strophe.LogLevel.WARN] = 'warn';
lmap[Strophe.LogLevel.ERROR] = 'error';
lmap[Strophe.LogLevel.FATAL] = 'fatal';

Strophe.log = (level, msg) => log.log(msg, lmap[level]);
Strophe.log = (l, msg) => log.log(msg, lmap[l]);
Strophe.error = (msg) => log.error(msg);

connection.xmlInput = (body) => log.debug(body.outerHTML, 'color: darkgoldenrod');
connection.xmlOutput = (body) => log.debug(body.outerHTML, 'color: darkcyan');
}

export function getConnectionServiceURL () {
Expand Down
62 changes: 32 additions & 30 deletions src/headless/tests/eventemitter.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,60 @@
/*global mock */

const container = {};

describe("The _converse Event Emitter", function() {

it("allows you to subscribe to emitted events", mock.initConverse((_converse) => {
window.callback = function () {};
spyOn(window, 'callback');
_converse.on('connected', window.callback);
container.callback = function () {};
spyOn(container, 'callback');
_converse.on('connected', container.callback);
_converse.api.trigger('connected');
expect(window.callback).toHaveBeenCalled();
expect(container.callback).toHaveBeenCalled();
_converse.api.trigger('connected');
expect(window.callback.calls.count(), 2);
expect(container.callback.calls.count(), 2);
_converse.api.trigger('connected');
expect(window.callback.calls.count(), 3);
expect(container.callback.calls.count(), 3);
}));

it("allows you to listen once for an emitted event", mock.initConverse((_converse) => {
window.callback = function () {};
spyOn(window, 'callback');
_converse.once('connected', window.callback);
container.callback = function () {};
spyOn(container, 'callback');
_converse.once('connected', container.callback);
_converse.api.trigger('connected');
expect(window.callback).toHaveBeenCalled();
expect(container.callback).toHaveBeenCalled();
_converse.api.trigger('connected');
expect(window.callback.calls.count(), 1);
expect(container.callback.calls.count(), 1);
_converse.api.trigger('connected');
expect(window.callback.calls.count(), 1);
expect(container.callback.calls.count(), 1);
}));

it("allows you to stop listening or subscribing to an event", mock.initConverse((_converse) => {
window.callback = function () {};
window.anotherCallback = function () {};
window.neverCalled = function () {};
container.callback = function () {};
container.anotherCallback = function () {};
container.neverCalled = function () {};

spyOn(window, 'callback');
spyOn(window, 'anotherCallback');
spyOn(window, 'neverCalled');
_converse.on('connected', window.callback);
_converse.on('connected', window.anotherCallback);
spyOn(container, 'callback');
spyOn(container, 'anotherCallback');
spyOn(container, 'neverCalled');
_converse.on('connected', container.callback);
_converse.on('connected', container.anotherCallback);

_converse.api.trigger('connected');
expect(window.callback).toHaveBeenCalled();
expect(window.anotherCallback).toHaveBeenCalled();
expect(container.callback).toHaveBeenCalled();
expect(container.anotherCallback).toHaveBeenCalled();

_converse.off('connected', window.callback);
_converse.off('connected', container.callback);

_converse.api.trigger('connected');
expect(window.callback.calls.count(), 1);
expect(window.anotherCallback.calls.count(), 2);
expect(container.callback.calls.count(), 1);
expect(container.anotherCallback.calls.count(), 2);

_converse.once('connected', window.neverCalled);
_converse.off('connected', window.neverCalled);
_converse.once('connected', container.neverCalled);
_converse.off('connected', container.neverCalled);

_converse.api.trigger('connected');
expect(window.callback.calls.count(), 1);
expect(window.anotherCallback.calls.count(), 3);
expect(window.neverCalled).not.toHaveBeenCalled();
expect(container.callback.calls.count(), 1);
expect(container.anotherCallback.calls.count(), 3);
expect(container.neverCalled).not.toHaveBeenCalled();
}));
});
Loading
Loading