Handles protocol events for destroyed rooms and displaying the reason if any.

ice4sip
Damian Minkov 12 years ago
parent 709643c711
commit 4cc318de6e

@ -132,6 +132,7 @@ service.gui.CHAT_ROOM_REQUIRES_PASSWORD=The {0} chat room has requested a passwo
service.gui.CHAT_ROOMS=Chat rooms
service.gui.CHAT_ROOM=Chat room
service.gui.CHAT_ROOM_SUBJECT_CHANGED={0} has changed the subject to {1}
service.gui.CHAT_ROOM_ALTERNATE_ADDRESS=You can continue conversation in the following chat room: {0}
service.gui.CHOOSE_CONTACT=Choose contact
service.gui.CHOOSE_NUMBER=Choose number
service.gui.CHOOSE_ACCOUNT=Please select one of the listed accounts.

@ -22,6 +22,9 @@
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.service.protocol.globalstatus.*;
import net.java.sip.communicator.util.*;
import net.java.sip.communicator.util.Logger;
import org.jitsi.util.*;
import org.jdesktop.swingworker.SwingWorker;
import org.osgi.framework.*;
@ -563,8 +566,52 @@ else if (LocalUserChatRoomPresenceChangeEvent
{
if(chatRoomWrapper != null)
{
GuiActivator.getUIService()
.closeChatRoomWindow(chatRoomWrapper);
if(StringUtils.isNullOrEmpty(evt.getReason()))
{
GuiActivator.getUIService()
.closeChatRoomWindow(chatRoomWrapper);
}
else
{
// send some system messages informing for the
// reason of leaving
ChatWindowManager chatWindowManager
= GuiActivator.getUIService().getChatWindowManager();
ChatPanel chatPanel = chatWindowManager.getMultiChat(
sourceChatRoom, false);
if(chatPanel != null)
{
chatPanel.addMessage(
sourceChatRoom.getName(),
null,
new Date(),
Chat.SYSTEM_MESSAGE,
evt.getReason(),
OperationSetBasicInstantMessaging.DEFAULT_MIME_TYPE,
null,
null);
// print and the alternate address
if(!StringUtils.isNullOrEmpty(
evt.getAlternateAddress()))
{
chatPanel.addMessage(
sourceChatRoom.getName(),
null,
new Date(),
Chat.SYSTEM_MESSAGE,
GuiActivator.getResources().getI18NString(
"service.gui.CHAT_ROOM_ALTERNATE_ADDRESS",
new String[]{evt.getAlternateAddress()}),
OperationSetBasicInstantMessaging
.DEFAULT_MIME_TYPE,
null,
null);
}
}
}
// Need to refresh the chat room's list in order to change
// the state of the chat room to offline.

@ -813,6 +813,14 @@ public ChatRoomMemberJabberImpl smackParticipantToScMember(String participant)
* Leave this chat room.
*/
public void leave()
{
this.leave(null, null);
}
/**
* Leave this chat room.
*/
private void leave(String reason, String alternateAddress)
{
OperationSetBasicTelephonyJabberImpl basicTelephony
= (OperationSetBasicTelephonyJabberImpl) provider
@ -883,8 +891,11 @@ public void leave()
if(connection != null)
connection.removePacketListener(invitationRejectionListeners);
opSetMuc.fireLocalUserPresenceEvent(this,
LocalUserChatRoomPresenceChangeEvent.LOCAL_USER_LEFT, null);
opSetMuc.fireLocalUserPresenceEvent(
this,
LocalUserChatRoomPresenceChangeEvent.LOCAL_USER_LEFT,
reason,
alternateAddress);
}
/**
@ -2757,6 +2768,23 @@ private void processOwnPresence(Presence presence)
{
setLocalUserRole(jitsiRole, true);
}
if(!presence.isAvailable()
&& "none".equalsIgnoreCase(affiliation)
&& "none".equalsIgnoreCase(role))
{
MUCUser.Destroy destroy = mucUser.getDestroy();
if(destroy == null)
{
// the room is unavailable to us, there is no
// message we will just leave
leave();
}
else
{
leave(destroy.getReason(), destroy.getJid());
}
}
}
}
}

@ -164,12 +164,32 @@ public void fireLocalUserPresenceEvent(
ChatRoom chatRoom,
String eventType,
String reason)
{
this.fireLocalUserPresenceEvent(chatRoom, eventType, reason, null);
}
/**
* Delivers a <tt>LocalUserChatRoomPresenceChangeEvent</tt> to all
* registered <tt>LocalUserChatRoomPresenceListener</tt>s.
*
* @param chatRoom the <tt>ChatRoom</tt> which has been joined, left, etc.
* @param eventType the type of this event; one of LOCAL_USER_JOINED,
* LOCAL_USER_LEFT, etc.
* @param reason the reason
* @param alternateAddress address of the new room, if old is destroyed.
*/
public void fireLocalUserPresenceEvent(
ChatRoom chatRoom,
String eventType,
String reason,
String alternateAddress)
{
LocalUserChatRoomPresenceChangeEvent evt
= new LocalUserChatRoomPresenceChangeEvent( this,
chatRoom,
eventType,
reason);
reason,
alternateAddress);
LocalUserChatRoomPresenceListener[] listeners;
synchronized (presenceListeners)

@ -72,6 +72,12 @@ public class LocalUserChatRoomPresenceChangeEvent
*/
private String reason = null;
/**
* An optional String indicating new address for the room, normally
* send when room is destroyed.
*/
private String alternateAddress = null;
/**
* Creates a <tt>ChatRoomLocalUserPresenceChangeEvent</tt> representing that
* a change in local participant presence in the source chat room has
@ -87,12 +93,33 @@ public LocalUserChatRoomPresenceChangeEvent(OperationSetMultiUserChat source,
ChatRoom chatRoom,
String eventType,
String reason)
{
this(source, chatRoom, eventType, reason, null);
}
/**
* Creates a <tt>ChatRoomLocalUserPresenceChangeEvent</tt> representing that
* a change in local participant presence in the source chat room has
* occured.
*
* @param source the <tt>OperationSetMultiUserChat</tt>, which produced this
* event
* @param chatRoom the <tt>ChatRoom</tt> that this event is about
* @param eventType the type of this event.
* @param reason the reason explaining why this event might have occurred
*/
public LocalUserChatRoomPresenceChangeEvent(OperationSetMultiUserChat source,
ChatRoom chatRoom,
String eventType,
String reason,
String alternateAddress)
{
super(source);
this.chatRoom = chatRoom;
this.eventType = eventType;
this.reason = reason;
this.alternateAddress = alternateAddress;
}
/**
@ -139,6 +166,16 @@ public String getEventType()
return eventType;
}
/**
* An optional String indicating new address for the room, normally
* send when room is destroyed.
* @return alternate address for the destroyed room.
*/
public String getAlternateAddress()
{
return alternateAddress;
}
/**
* Returns a String representation of this event.
*

Loading…
Cancel
Save