powered by Jive Software

Private Messages not working in Conference

I am trying to send a private message to a user that is part of a conference, but I never get the PRIVATE_MESSAGE event in XIFF. I have looked at the source code and it appears that the only place the PRIVATE_MESSAGE event is dispatched is in handleEvent. However, it is in the else portion of the code which tests for whether the message came from the room … so it never dispatches the event. The comment on the code even indicates that it expects that the PRIVATE_MESSAGE might come from the conference, but it doesn’'t seem to expect the from field to indicate that it came from the room. Expecting it to come from a person directly maybe?

It seems to me this is a bug … I can fix by moving the code that dispatches the event, but I would like to know if anyone else has an opinion on this. Did the behavior of the server e.g. change? Maybe it used to fill in the from field with the JID of the sender rather than the room JID (e.g. testroom@conference.xyz.com/sender)?

As always, I’‘m nervous changing code I didn’'t write without a full understanding, but I may have no choice since it does not seem to work correctly. Thoughts? Suggestions?

Thanks.

Bill

There is more wrong here than just the from. It appears that XIFF expects

a) that the ‘‘from’’ field will be the user JID rather than the room id (e.g. testroom@conference.xyz.com/sender)

b) that the ‘‘to’’ field will be the room id (e.g. testroom@conference.xyz.com/receiver) rather than the user JID

What I am seeing from the server is just the opposite … the message has the ‘‘to’’ field set to the user JID (e.g. bill@xyz.com/someresource) and the ‘‘from’’ field set to the room id (e.g. testroom@conference.xyz.com/sender).

I moved the PRIVATE_MESSAGE code and it still doesn’'t work … looks like the code which reads

// It could be a private message via the conference

else if( isThisUser(msg.to) && msg.type == Message.CHAT_TYPE ) {

needs to be more like

// It could be a private message via the conference

else if( msg.to == userJID && msg.type == Message.CHAT_TYPE ) {

where userJID is of the form username@servername/resource. So far the only way I can see to do this is to retrieve the components from the connection and concatenate them myself … a JID of this form doesn’'t seem to be stored anywhere in Room.as.

I am about to make these changes and test, but as usual I would really appreciate if someone more familiar with the source code can validate what I am saying … my change may fix my current problem, but cause other issues down the road? Thoughts? Suggestions?

Thanks.

Bill

Well, I took the leap. I moved the code so that it is evaluated when the message comes from the room. And I changed the comparison to msg.to == userJID, where the value of userJID (an instance variable) is initialized when the current user’'s presence in the room is first detected and the active flag is set to true. It works.

I also checked XEP-0045 which specifies the expected behavior to be that demonstrated by the server. It appears to me that someone got it backwards in the XIFF code … but I’'m a little puzzled how this problem could not have affected anyone else but me. Is there no one else out there that has used private messaging from within a conference?

I am a little disappointed so far with the level of support in the forums. I know this is a free product so I don’'t have a lot of latitude to complain, but I have had much better experiences with a lot of other open source (free) projects.

In any event, here is the code I changed just in case some other unfortunate soul runs across a need for it.

private function handleEvent( eventObj:Object ):void

{

switch( eventObj.type )

{

case “message”:

var msg:Message = eventObj.data;

// Check to see that the message is from this room

if( isThisRoom( msg.from ) ) {

var e:RoomEvent;

if ( msg.type == Message.GROUPCHAT_TYPE ) {

// Check for a subject change

if( msg.subject != null ) {

mySubject = msg.subject;

e = new RoomEvent(RoomEvent.SUBJECT_CHANGE);

e.subject = msg.subject;

dispatchEvent(e);

}

else {

e = new RoomEvent(RoomEvent.GROUP_MESSAGE);

e.data = msg;

dispatchEvent(e);

}

} else if ( msg.type == Message.NORMAL_TYPE ) {

try

{

var form:Array = msg.getAllExtensionsByNS(FormExtension.NS)[0];

if (form) {

e = new RoomEvent(RoomEvent.CONFIGURE_ROOM);

e.data = form;

dispatchEvent(e);

}

}

catch (e:Error)

{

trace(“Error : null trapped. Resuming.”);

}

}

// I changed the following section

// It could be a private message via the conference

else if( msg.to == userJID && msg.type == Message.CHAT_TYPE ) {

e = new RoomEvent(RoomEvent.PRIVATE_MESSAGE);

e.data = msg;

dispatchEvent(e);

}

// I changed the above section

}

// Could be an decline to a previous invite

else {

try

{

var muc:MUCUserExtension = msg.getAllExtensionsByNS(MUCUserExtension.NS)[0];

if (muc && muc.type == MUCUserExtension.DECLINE_TYPE)

{

e = new RoomEvent(RoomEvent.DECLINED);

e.from = muc.reason;

e.reason = muc.reason;

e.data = msg;

dispatchEvent(e);

}

}

catch (err:Error)

{

trace(“Error : null trapped. Resuming.”);

}

}

break;

… rest of code omitted …

I also added the following code

private function updateRoomRoster( aPresence:Presence ):void

{

try

{

var userNickname:String = aPresence.from.split( “/” )[1];

var userExts:Array = aPresence.getAllExtensionsByNS(MUCUserExtension.NS);

var item:MUCItem = userExts[0].getAllItems()[0];

var e:RoomEvent;

if ( isThisUser( aPresence.from ) ) {

myAffiliation = item.affiliation;

myRole = item.role;

if (!isActive() && aPresence.type != Presence.UNAVAILABLE_TYPE) {

//trace("Room: becoming active: " + presence.getNode());

active = true;

// I added the line below

userJID = myConnection.username + “@” + myConnection.server + “/” + myConnection.resource;

// I added the line above

e = new RoomEvent(RoomEvent.ROOM_JOIN);

dispatchEvent(e);

}

}

… rest of code omitted …

And of course, I added userJID as an instance variable in the Room class.

Bill

billbailey1964,

thanks for posting your solution.

I got the sample issue: PRIVATE_MESSAGE event not dispatched in a conference. I am using xiffas3_beta1.

your patch pointed me to get it work. however, i have to put

( msg.to == userToJID && msg.type == Message.CHAT_TYPE ) check inside if( isThisRoom( msg.from ) ) section,

as i noticed PRIVATE_MESSAGE event always makes isThisRoom( msg.from ) true.

hope this would get fixed on next release.

thanks

Hi Waveland,

Do you know how to receive a message using the XIFF beta…?.. can you please share me some basic operations like

getting room list, getting user list, receiving private messages on private chat ?

thanks

Viv