1

I changed 'Subject' of a chat room but I am not getting this latest subject name. I am using 'disco#info' to get the room info. In response, I am getting room title that was set initially while creating the room but not the latest room subject. How can I get the latest room subject ?

akhileshnair
  • 1,437
  • 1
  • 12
  • 18

3 Answers3

6

Had to customize the Erlang module mod_muc_room.erl.

Did these changes in iq_disco_info_extras:

  1. Created a new function get_subject which gets the room subject from StateData.
  2. Added a new parameter in iq_disco_info_extras to get room subject and called the function RoomSubject = get_subject(StateData).
  3. Added a new RFIELD as ?RFIELD(<<"Room subject">>, <<"muc#roominfo_subject">>, RoomSubject),
  4. Compiled the module mod_muc_room.erl, which updated the mod_muc_room.beam file.

Tada...that worked like a piece of cake!

Now getting subject name in roominfo.

2240
  • 1,547
  • 2
  • 12
  • 30
akhileshnair
  • 1,437
  • 1
  • 12
  • 18
  • Since this answer is a little outdated (specifically step 3), If anyone is struggling to get it working, I have created a fork for these changes to the latest repo [here](https://github.com/processone/ejabberd/commit/c48e78579210880131b8d62cc7106951e73f8df0) – MMujtabaRoohani Oct 05 '22 at 08:00
2

In XMPP MUC protocol, Subject and title are two different things. The title is set via configuration form and can be displayed in service discovery. Subject is a dynamic topic that is send to participant when he joins the room. Subject is not send back in disco#info query. Only name and room_description are send back in discovery info.

Mickaël Rémond
  • 9,035
  • 1
  • 24
  • 44
  • I agree with you. But if i change the subject for the room, i am not getting it in disco#info. I am always getting the old subject. – akhileshnair Apr 11 '16 at 10:43
  • As I said, subject is not displayed in disco#info. You get name and room_description, but not subject. You are not getting old subject, you are getting a description, which is separate data. – Mickaël Rémond Apr 11 '16 at 10:51
  • As I said: "Subject is a dynamic topic that is send to participant when he joins the room." In other words, you need to join the room to get the subject. – Mickaël Rémond Apr 12 '16 at 07:49
1

In case anyone is still looking for this, here's a quick way to do this from something like an ejabberd plugin/module:

{ok,Room_PID} = mod_muc:find_online_room(<<"my_muc_room_name">>, <<"conference.my.server.com">>),    
{ok,Room_State} = p1_fsm:sync_send_all_state_event(Room_PID, get_state),    
Room_Subject_List = Room_State#state.subject,    
Room_Subject = hd(Room_Subject_List),    
Subject = Room_Subject#text.data,    
io:format("~ts~n", [Subject]).

If you're trying this from an erlang shell you brought up via "ejabberdctl debug", then you'll also want to pull in the record definitions for "state" and "text". To do that, create a textfile called something like "my_record_includes.hrl" with content something like the following (of course, you'll have to adjust the filepaths based on your ejabberd installation).

-include("/opt/ejabberd-19.05/lib/xmpp-1.3.4/include/jid.hrl").
-include("/opt/ejabberd-19.05/lib/xmpp-1.3.4/include/xmpp_codec.hrl").
-include("/opt/ejabberd-19.05/lib/ejabberd-19.05/include/mod_muc_room.hrl").

Once you have "my_record_includes.hrl" created, then use the shell "rr" command to import it like this:

> rr("my_record_includes.hrl").

[activity,address,addresses,adhoc_actions,adhoc_command,
 adhoc_note,avatar_data,avatar_info,avatar_meta,
 avatar_pointer,bind,block,block_item,block_list,bob_data,
 bookmark_conference,bookmark_storage,bookmark_url,
 bytestreams,caps,carbons_disable,carbons_enable,
 carbons_private,carbons_received,carbons_sent,chatstate,
 compress,compress_failure,compressed|...]

If you're doing this in an erlang shell, make sure you import those record definitions BEFORE you try executing the code to grab the room state and subject!

Also, be careful about doing this from a callback that is executed by the muc room's process itself. The call to p1_fsm:sync_send_all_state_event( ) sends a message to the room process, and that will time out if you're sending it to your own process and blocking. Do the query for the room state from another process!

Roy Wood
  • 318
  • 1
  • 3
  • 10