xmppjs / xmpp.js

XMPP for JavaScript
ISC License
2.2k stars 374 forks source link

support of conditions in the middleware #843

Closed Slawutich closed 3 years ago

Slawutich commented 4 years ago

The main motivation is to get rid of the checks in the middleware handler. This pattern is traced in many parts of the code

for example https://github.com/xmppjs/xmpp.js/blob/f0dd463102143cdc3dacdcab7a1921bab0ff0cd7/packages/iq/callee.js#L109 https://github.com/xmppjs/xmpp.js/blob/f0dd463102143cdc3dacdcab7a1921bab0ff0cd7/packages/stream-features/index.js#L13

and also regularly have to write conditions in their logic

backward compatibility fully preserved

sonnyp commented 4 years ago

Thanks a lot.

This is something I had on my radar for a while. It's looking good, I'm slightly busy right now but I will take the time to review and release ASAP.

Slawutich commented 4 years ago

Very cool, thanks.

sonnyp commented 4 years ago

@Slawutich after giving it more thoughts, I'm not sure this is as useful as I thought it would.

For message and presence stanzas filtering by type and or child is either not what you want or not enough to be helpful.

For iq stanzas, https://github.com/xmppjs/xmpp.js/tree/master/packages/iq#callee already provides a convenient API

That's also more or less how prosody exposes it https://prosody.im/doc/developers/events#stanzas

What do you think? Can you elaborate on your use case?

sonnyp commented 3 years ago

Closing due to inactivity.