See https://xmpp.org/extensions/xep-0045.html#message
Some duplication is avoided, but most importantly: it’s much much cleaner, easier to find, functions have been cleaned up (functools.partial usages are now hidden), etc.