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' ;
6
6
7
7
const { u, stx, Stanza } = converse . env ;
8
8
@@ -14,9 +14,9 @@ const { u, stx, Stanza } = converse.env;
14
14
*/
15
15
export function rejectMessage ( stanza , text ) {
16
16
api . send (
17
- stx `<message to="${ stanza . getAttribute ( " from" ) } "
17
+ stx `<message to="${ stanza . getAttribute ( ' from' ) } "
18
18
type="error"
19
- id="${ stanza . getAttribute ( "id" ) } "
19
+ id="${ stanza . getAttribute ( 'id' ) } "
20
20
xmlns="jabber:client">
21
21
<error type="cancel">
22
22
<not-allowed xmlns="${ Strophe . NS . STANZAS } "/>
@@ -45,7 +45,7 @@ export function sendMarker(to_jid, id, type, msg_type) {
45
45
<message from="${ api . connection . get ( ) . jid } "
46
46
id="${ u . getUniqueId ( ) } "
47
47
to="${ to_jid } "
48
- type="${ msg_type ? msg_type : " chat" } "
48
+ type="${ msg_type ? msg_type : ' chat' } "
49
49
xmlns="jabber:client">
50
50
<${ Stanza . unsafeXML ( type ) } xmlns="${ Strophe . NS . MARKERS } " id="${ id } "/>
51
51
</message>` ;
@@ -76,15 +76,19 @@ export function sendReceiptStanza(to_jid, id) {
76
76
* @param {import("./types").ChatStateType } chat_state
77
77
*/
78
78
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' ) ;
81
89
if ( Array . isArray ( allowed ) && ! allowed . includes ( chat_state ) ) {
82
90
return ;
83
91
}
84
- if ( ! CHAT_STATES . includes ( chat_state ) ) {
85
- log . error ( `Invalid chat state: ${ chat_state } ` ) ;
86
- return ;
87
- }
88
92
api . send (
89
93
stx `<message id="${ u . getUniqueId ( ) } " to="${ jid } " type="chat" xmlns="jabber:client">
90
94
<${ Stanza . unsafeXML ( chat_state ) } xmlns="${ Strophe . NS . CHATSTATES } "/>
@@ -102,7 +106,7 @@ export function sendChatState(jid, chat_state) {
102
106
* @param {string } retraction_id - Unique ID for the retraction message
103
107
*/
104
108
export function sendRetractionMessage ( jid , message , retraction_id ) {
105
- const origin_id = message . get ( " origin_id" ) ;
109
+ const origin_id = message . get ( ' origin_id' ) ;
106
110
if ( ! origin_id ) {
107
111
throw new Error ( "Can't retract message without a XEP-0359 Origin ID" ) ;
108
112
}
0 commit comments