Skip to content

Commit 4e006c0

Browse files
committed
Avoid sending out a chat state message without a to attribute
1 parent 2e1f799 commit 4e006c0

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

src/headless/shared/actions.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import log from "@converse/log";
2-
import { Strophe } from "strophe.js";
3-
import api from "./api/index.js";
4-
import converse from "./api/public.js";
5-
import {CHAT_STATES, MARKER_TYPES} from "./constants.js";
1+
import log from '@converse/log';
2+
import { Strophe } from 'strophe.js';
3+
import api from './api/index.js';
4+
import converse from './api/public.js';
5+
import { CHAT_STATES, MARKER_TYPES } from './constants.js';
66

77
const { u, stx, Stanza } = converse.env;
88

@@ -14,9 +14,9 @@ const { u, stx, Stanza } = converse.env;
1414
*/
1515
export function rejectMessage(stanza, text) {
1616
api.send(
17-
stx`<message to="${stanza.getAttribute("from")}"
17+
stx`<message to="${stanza.getAttribute('from')}"
1818
type="error"
19-
id="${stanza.getAttribute("id")}"
19+
id="${stanza.getAttribute('id')}"
2020
xmlns="jabber:client">
2121
<error type="cancel">
2222
<not-allowed xmlns="${Strophe.NS.STANZAS}"/>
@@ -45,7 +45,7 @@ export function sendMarker(to_jid, id, type, msg_type) {
4545
<message from="${api.connection.get().jid}"
4646
id="${u.getUniqueId()}"
4747
to="${to_jid}"
48-
type="${msg_type ? msg_type : "chat"}"
48+
type="${msg_type ? msg_type : 'chat'}"
4949
xmlns="jabber:client">
5050
<${Stanza.unsafeXML(type)} xmlns="${Strophe.NS.MARKERS}" id="${id}"/>
5151
</message>`;
@@ -76,15 +76,19 @@ export function sendReceiptStanza(to_jid, id) {
7676
* @param {import("./types").ChatStateType} chat_state
7777
*/
7878
export function sendChatState(jid, chat_state) {
79-
if (api.settings.get("send_chat_state_notifications") && chat_state) {
80-
const allowed = api.settings.get("send_chat_state_notifications");
79+
if (!jid) {
80+
log.error(`sendChatState called with no JID`);
81+
return;
82+
} else if (!CHAT_STATES.includes(chat_state)) {
83+
log.error(`Invalid chat state: ${chat_state}`);
84+
return;
85+
}
86+
87+
if (api.settings.get('send_chat_state_notifications') && chat_state) {
88+
const allowed = api.settings.get('send_chat_state_notifications');
8189
if (Array.isArray(allowed) && !allowed.includes(chat_state)) {
8290
return;
8391
}
84-
if (!CHAT_STATES.includes(chat_state)) {
85-
log.error(`Invalid chat state: ${chat_state}`);
86-
return;
87-
}
8892
api.send(
8993
stx`<message id="${u.getUniqueId()}" to="${jid}" type="chat" xmlns="jabber:client">
9094
<${Stanza.unsafeXML(chat_state)} xmlns="${Strophe.NS.CHATSTATES}"/>
@@ -102,7 +106,7 @@ export function sendChatState(jid, chat_state) {
102106
* @param {string} retraction_id - Unique ID for the retraction message
103107
*/
104108
export function sendRetractionMessage(jid, message, retraction_id) {
105-
const origin_id = message.get("origin_id");
109+
const origin_id = message.get('origin_id');
106110
if (!origin_id) {
107111
throw new Error("Can't retract message without a XEP-0359 Origin ID");
108112
}

0 commit comments

Comments
 (0)