Skip to content

Commit

Permalink
Fix message moderation, when not used as a component.
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnXLivingston committed Sep 19, 2023
1 parent e147b19 commit 1e0549e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.2.5

* Fix message moderation, when not used as a component.

## 0.2.4

* Fix CLI exit.
Expand Down
18 changes: 16 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xmppjs-chat-bot",
"version": "0.2.4",
"version": "0.2.5",
"description": "Server-side XMPP chat bot",
"engines": {
"node": ">= 14.4.0"
Expand Down Expand Up @@ -45,6 +45,7 @@
"@types/xmpp__component": "^0.13.0",
"@types/xmpp__connection": "^0.13.0",
"@types/xmpp__debug": "^0.13.0",
"@types/xmpp__id": "^0.13.0",
"@types/xmpp__jid": "^1.3.3",
"@types/xmpp__xml": "^0.13.1",
"@typescript-eslint/eslint-plugin": "^4.29.0",
Expand All @@ -62,6 +63,7 @@
"@xmpp/client": "^0.13.1",
"@xmpp/component": "^0.13.1",
"@xmpp/debug": "^0.13.0",
"@xmpp/id": "^0.13.1",
"@xmpp/jid": "^0.13.1",
"@xmpp/xml": "^0.13.1",
"commander": "^11.0.0"
Expand Down
8 changes: 5 additions & 3 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,11 @@ export class Bot {
attrs: object,
...children: Node[]
): Promise<void> {
attrs = Object.assign({
from: this.address?.toString()
}, attrs)
if (type !== 'iq') {
attrs = Object.assign({
from: this.address?.toString()
}, attrs)
}

const stanza = xml(type, attrs, ...children)
this.logger.debug('stanza to emit: ' + stanza.toString())
Expand Down
7 changes: 6 additions & 1 deletion src/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import EventEmitter from 'events'
import { JID } from '@xmpp/jid'
import xml from '@xmpp/xml'
import { RoomUser } from './user'
// eslint-disable-next-line @typescript-eslint/no-var-requires
const xmppid = require('@xmpp/id')

declare interface Room {
on: (
Expand Down Expand Up @@ -173,11 +175,14 @@ class Room extends EventEmitter {
...moderateChildren
)
)
// FIXME: use https://github.com/xmppjs/xmpp.js/blob/main/packages/iq/caller.js
// instead of hard coding a sendStanza.
await this.bot.sendStanza(
'iq',
{
type: 'set',
to: this.roomJID.toString()
to: this.roomJID.toString(),
id: xmppid()
},
applyTo
)
Expand Down

0 comments on commit 1e0549e

Please sign in to comment.