erlang 不允许任何所有者撤销创建聊天室/MUC的用户的所有权- Ejabberd XMPP

mwngjboj  于 2022-12-08  发布在  Erlang
关注(0)|答案(1)|浏览(163)

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

jhiyze9q

jhiyze9q1#

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.

相关问题