1
votes

I am developing a messaging app for Android using ejabberd XMPP. App has a room chat feature (MUC). I have a question regarding MUC owner affiliation.

userA(Creator) creates a new room (MUC).
UserB joins the room and userA(Creator) grants ownership to userB.
userB revokes ownership of userA(Creator)
userA(Creator) is now none (this is the problem)

I want to know how to configure XMPP server to not allow any owner to revoke ownership of the user who created the room/MUC ?

https://xmpp.org/extensions/xep-0045.html

1
You may find some workarounds for your own custom use cases. But in the long run, you would end up in writing up a custom module on the server and you have to deviate from standard XMPP.Adinarayana Immidisetti

1 Answers

1
votes

You should implement a custom ejabberd module and use muc_process_iq hook. When someone tries to revoke ownership it sends an IQ stanza to MUC, You can catch it by above hook.
Your hook's callback function should be something like:

my_callback(IQ, MUCState) ->
    % check if it's for granting/revoking ownership
    % ...
    NewIQ. % or atom 'ignore'

But you do not have creator jid in MUCState because in XMPP it does not matter!
Actually there is a hack. Each affiliation can be set with a custom reason which is just a text inside <reason>...</reason> tag. You can access owners' affiliation reasons in MUCState.
Room creator (first owner) does not have reason in it's affiliation. So when someone is granting ownership, you can put something into 'reason' field (you need to do it in user scope, e.g. user_send_packet hook) and let MUC handle it and when someone is revoking ownership check if target owner has 'reason' filed or not in above function.
Also there is more advanced and standard approach to do it. You can change MUC config state and add creator jid and some changes in mod_muc_room.erl. So you can have creator's jid in MUCState in above function.