Question

I wanna add a possibility to ejabberd-2.1.12 to be invisible in MUC via presence "invisible" (I know that in 3.x.x versions of ejabberd this will be deprecated, - I'll do that for site via http-bind).

so the task is: send non-directed presence "invisible" and in every room user connected change it's StateData.

so I modified ejabberd_c2s.erl and when user changes his non-directed presence, he sends to mod_muc_room.erl notification

function mod_muc_room.erl :

room_state() ->
 receive
    Msg ->  (any data about user, presence),
 room_state()
end.

so room knows that user changed his presence and it should change it's own StateData, but how can I get this value, modify and inject(replace) it to this room?

Was it helpful?

Solution

mod_muc_room uses the gen_fsm behaviour. You can tell since this line is near the top of the file:

-behaviour(gen_fsm).

To receive and handle a message sent to a gen_fsm process you wouldn't use receive directly, but rather add a new clause to the handle_info function.

For example, there is a clause that handles the {process_user_presence, From} message. It starts with:

handle_info({process_user_presence, From}, normal_state = _StateName, StateData) ->

and eventually ends up in something like:

{next_state, normal_state, StateData1}

where StateData1 is a modified form of StateData. This is how you modify the state of the room.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top