mirror of https://github.com/sipwise/jitsi.git
that lists the existing chat rooms.cusax-fix
parent
bea81426ee
commit
cfa777aadf
@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.impl.gui.main.chatroomslist;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
import net.java.sip.communicator.impl.gui.*;
|
||||
import net.java.sip.communicator.impl.gui.main.contactlist.*;
|
||||
import net.java.sip.communicator.impl.gui.utils.*;
|
||||
import net.java.sip.communicator.service.contactsource.*;
|
||||
import net.java.sip.communicator.service.gui.*;
|
||||
import net.java.sip.communicator.service.muc.*;
|
||||
|
||||
/**
|
||||
* A dialog that lists the existing chat rooms on the server.
|
||||
*
|
||||
* @author Hristo Terezov
|
||||
*/
|
||||
public class ServerChatRoomsChoiceDialog
|
||||
extends OneChoiceInviteDialog
|
||||
{
|
||||
|
||||
/**
|
||||
* Generated serial id.
|
||||
*/
|
||||
private static final long serialVersionUID = 428358553225114162L;
|
||||
|
||||
/**
|
||||
* The contact source that generates the list of chat rooms.
|
||||
*/
|
||||
private ContactSourceService contactSource;
|
||||
|
||||
/**
|
||||
* Creates new instance of <tt>ServerChatRoomsChoiceDialog</tt>.
|
||||
*
|
||||
* @param title the title of the window.
|
||||
* @param pps the protocol provider service associated with the list of chat
|
||||
* rooms.
|
||||
*/
|
||||
public ServerChatRoomsChoiceDialog(String title,
|
||||
ChatRoomProviderWrapper pps)
|
||||
{
|
||||
super(title);
|
||||
contactList.setDefaultFilter(new SearchFilter(contactList));
|
||||
contactList.removeAllContactSources();
|
||||
contactSource = GuiActivator.getMUCService()
|
||||
.getServerChatRoomsContactSourceForProvider(pps);
|
||||
contactList.addContactSource(
|
||||
contactSource);
|
||||
|
||||
setInfoText(GuiActivator.getResources().getI18NString(
|
||||
"service.gui.SERVER_CHAT_ROOMS_DIALOG_TEXT"));
|
||||
|
||||
contactList.applyDefaultFilter();
|
||||
this.setMinimumSize(new Dimension(300, 300));
|
||||
addOkButtonListener(new ActionListener()
|
||||
{
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
UIContact uiContact = getSelectedContact();
|
||||
|
||||
if (uiContact != null)
|
||||
{
|
||||
ChatRoomTableDialog.setChatRoomField(
|
||||
uiContact.getDisplayName());
|
||||
}
|
||||
|
||||
setVisible(false);
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
addCancelButtonListener(new ActionListener()
|
||||
{
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
setVisible(false);
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles provider change.
|
||||
*
|
||||
* @param provider the provider.
|
||||
*/
|
||||
public void changeProtocolProvider(ChatRoomProviderWrapper provider)
|
||||
{
|
||||
contactList.removeContactSource(contactSource);
|
||||
contactSource = GuiActivator.getMUCService()
|
||||
.getServerChatRoomsContactSourceForProvider(provider);
|
||||
contactList.addContactSource(contactSource);
|
||||
contactList.applyDefaultFilter();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,136 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license. See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.impl.muc;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import net.java.sip.communicator.service.contactsource.*;
|
||||
import net.java.sip.communicator.service.muc.*;
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
|
||||
/**
|
||||
* Basic source contact for the chat rooms.
|
||||
*
|
||||
* @author Hristo Terezov
|
||||
*/
|
||||
public class BaseChatRoomSourceContact
|
||||
extends SortedGenericSourceContact
|
||||
{
|
||||
/**
|
||||
* The name of the chat room associated with the contact.
|
||||
*/
|
||||
private String chatRoomName;
|
||||
|
||||
/**
|
||||
* The ID of the chat room associated with the contact.
|
||||
*/
|
||||
private String chatRoomID;
|
||||
|
||||
/**
|
||||
* The protocol provider of the chat room associated with the contact.
|
||||
*/
|
||||
private ProtocolProviderService provider;
|
||||
|
||||
/**
|
||||
* Contsructs new chat room source contact.
|
||||
* @param chatRoomName the name of the chat room associated with the room.
|
||||
* @param chatRoomID the id of the chat room associated with the room.
|
||||
* @param query the query associated with the contact.
|
||||
* @param pps the protocol provider of the contact.
|
||||
* @param isAutoJoin the auto join state.
|
||||
*/
|
||||
public BaseChatRoomSourceContact(String chatRoomName,
|
||||
String chatRoomID, ContactQuery query, ProtocolProviderService pps)
|
||||
{
|
||||
super(query, query.getContactSource(), chatRoomName,
|
||||
generateDefaultContactDetails(chatRoomName));
|
||||
|
||||
this.chatRoomName = chatRoomName;
|
||||
this.chatRoomID = chatRoomID;
|
||||
this.provider = pps;
|
||||
|
||||
initContactProperties(ChatRoomPresenceStatus.CHAT_ROOM_OFFLINE);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the given presence status and the name of the chat room associated
|
||||
* with the contact.
|
||||
* @param status the presence status to be set.
|
||||
*/
|
||||
protected void initContactProperties(PresenceStatus status)
|
||||
{
|
||||
setPresenceStatus(status);
|
||||
setContactAddress(chatRoomName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the default contact details for
|
||||
* <tt>BaseChatRoomSourceContact</tt> instances.
|
||||
*
|
||||
* @param chatRoomName the name of the chat room associated with the contact
|
||||
* @return list of default <tt>ContactDetail</tt>s for the contact.
|
||||
*/
|
||||
private static List<ContactDetail> generateDefaultContactDetails(
|
||||
String chatRoomName)
|
||||
{
|
||||
ContactDetail contactDetail
|
||||
= new ContactDetail(chatRoomName);
|
||||
List<Class<? extends OperationSet>> supportedOpSets
|
||||
= new ArrayList<Class<? extends OperationSet>>();
|
||||
|
||||
supportedOpSets.add(OperationSetMultiUserChat.class);
|
||||
contactDetail.setSupportedOpSets(supportedOpSets);
|
||||
|
||||
List<ContactDetail> contactDetails
|
||||
= new ArrayList<ContactDetail>();
|
||||
|
||||
contactDetails.add(contactDetail);
|
||||
return contactDetails;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the id of the chat room associated with the contact.
|
||||
*
|
||||
* @return the chat room id.
|
||||
*/
|
||||
public String getChatRoomID()
|
||||
{
|
||||
return chatRoomID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the chat room associated with the contact.
|
||||
*
|
||||
* @return the chat room name
|
||||
*/
|
||||
public String getChatRoomName()
|
||||
{
|
||||
return chatRoomName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the provider of the chat room associated with the contact.
|
||||
*
|
||||
* @return the provider
|
||||
*/
|
||||
public ProtocolProviderService getProvider()
|
||||
{
|
||||
return provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of this source contact in its parent group.
|
||||
*
|
||||
* @return the index of this contact in its parent
|
||||
*/
|
||||
@Override
|
||||
public int getIndex()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license. See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.impl.muc;
|
||||
|
||||
import net.java.sip.communicator.service.contactsource.*;
|
||||
import net.java.sip.communicator.service.muc.*;
|
||||
|
||||
/**
|
||||
* Contact source service for the existing chat rooms on the server.
|
||||
*
|
||||
* @author Hristo Terezov
|
||||
*/
|
||||
public class ServerChatRoomContactSourceService
|
||||
implements ContactSourceService
|
||||
{
|
||||
private ChatRoomProviderWrapper provider = null;
|
||||
public ServerChatRoomContactSourceService(ChatRoomProviderWrapper pps)
|
||||
{
|
||||
provider = pps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of this contact source.
|
||||
*
|
||||
* @return the type of this contact source
|
||||
*/
|
||||
public int getType()
|
||||
{
|
||||
return DEFAULT_TYPE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a user-friendly string that identifies this contact source.
|
||||
*
|
||||
* @return the display name of this contact source
|
||||
*/
|
||||
public String getDisplayName()
|
||||
{
|
||||
return MUCActivator.getResources().getI18NString(
|
||||
"service.gui.SERVER_CHAT_ROOMS");
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries this contact source for the given <tt>queryString</tt>.
|
||||
*
|
||||
* @param queryString the string to search for
|
||||
* @return the created query
|
||||
*/
|
||||
@Override
|
||||
public ContactQuery queryContactSource(String queryString)
|
||||
{
|
||||
return queryContactSource(queryString, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries this contact source for the given <tt>queryString</tt>.
|
||||
*
|
||||
* @param queryString the string to search for
|
||||
* @param contactCount the maximum count of result contacts
|
||||
* @return the created query
|
||||
*/
|
||||
@Override
|
||||
public ContactQuery queryContactSource(String queryString, int contactCount)
|
||||
{
|
||||
if (queryString == null)
|
||||
queryString = "";
|
||||
|
||||
ServerChatRoomQuery contactQuery
|
||||
= new ServerChatRoomQuery(queryString, this, provider);
|
||||
|
||||
contactQuery.start();
|
||||
|
||||
|
||||
return contactQuery;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the contact source in the result list.
|
||||
*
|
||||
* @return the index of the contact source in the result list
|
||||
*/
|
||||
@Override
|
||||
public int getIndex()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,261 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license. See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.impl.muc;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.regex.*;
|
||||
|
||||
import net.java.sip.communicator.service.contactsource.*;
|
||||
import net.java.sip.communicator.service.muc.*;
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
import net.java.sip.communicator.util.Logger;
|
||||
|
||||
/**
|
||||
* The <tt>ServerChatRoomQuery</tt> is a query over the
|
||||
* <tt>ServerChatRoomContactSourceService</tt>.
|
||||
*
|
||||
* @author Hristo Terezov
|
||||
*/
|
||||
public class ServerChatRoomQuery
|
||||
extends AsyncContactQuery<ContactSourceService>
|
||||
implements ChatRoomProviderWrapperListener
|
||||
{
|
||||
/**
|
||||
* The query string.
|
||||
*/
|
||||
private String queryString;
|
||||
|
||||
/**
|
||||
* List with the current results for the query.
|
||||
*/
|
||||
private List<BaseChatRoomSourceContact> contactResults
|
||||
= new ArrayList<BaseChatRoomSourceContact>();
|
||||
|
||||
/**
|
||||
* MUC service.
|
||||
*/
|
||||
private MUCServiceImpl mucService;
|
||||
|
||||
/**
|
||||
* The number of contact query listeners.
|
||||
*/
|
||||
private int contactQueryListenersCount = 0;
|
||||
|
||||
/**
|
||||
* The provider associated with the query.
|
||||
*/
|
||||
private ChatRoomProviderWrapper provider = null;
|
||||
|
||||
/**
|
||||
* Creates an instance of <tt>ChatRoomQuery</tt> by specifying
|
||||
* the parent contact source, the query string to match and the maximum
|
||||
* result contacts to return.
|
||||
*
|
||||
* @param contactSource the parent contact source
|
||||
* @param queryString the query string to match
|
||||
* @param provider the provider associated with the query
|
||||
* @param count the maximum result contact count
|
||||
*/
|
||||
public ServerChatRoomQuery(String queryString,
|
||||
ServerChatRoomContactSourceService contactSource,
|
||||
ChatRoomProviderWrapper provider)
|
||||
{
|
||||
super(contactSource,
|
||||
Pattern.compile(queryString, Pattern.CASE_INSENSITIVE
|
||||
| Pattern.LITERAL), true);
|
||||
this.queryString = queryString;
|
||||
|
||||
mucService = MUCActivator.getMUCService();
|
||||
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds listeners for the query
|
||||
*/
|
||||
private void initListeners()
|
||||
{
|
||||
mucService.addChatRoomProviderWrapperListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void run()
|
||||
{
|
||||
if(provider == null)
|
||||
{
|
||||
Iterator<ChatRoomProviderWrapper> chatRoomProviders
|
||||
= mucService.getChatRoomProviders();
|
||||
while (chatRoomProviders.hasNext())
|
||||
{
|
||||
ChatRoomProviderWrapper provider = chatRoomProviders.next();
|
||||
providerAdded(provider, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
providerAdded(provider, true);
|
||||
}
|
||||
|
||||
if (getStatus() != QUERY_CANCELED)
|
||||
setStatus(QUERY_COMPLETED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles adding a chat room provider.
|
||||
* @param provider the provider.
|
||||
* @param addQueryResult indicates whether we should add the chat room to
|
||||
* the query results or fire an event without adding it to the results.
|
||||
*/
|
||||
private void providerAdded(ChatRoomProviderWrapper provider,
|
||||
boolean addQueryResult)
|
||||
{
|
||||
List<String> chatRoomNames
|
||||
= MUCActivator.getMUCService().getExistingChatRooms(provider);
|
||||
if(chatRoomNames == null)
|
||||
return;
|
||||
for(String chatRoomName : chatRoomNames)
|
||||
{
|
||||
addChatRoom( provider.getProtocolProvider(), chatRoomName,
|
||||
chatRoomName, addQueryResult);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds found result to the query results.
|
||||
*
|
||||
* @param pps the protocol provider associated with the found chat room.
|
||||
* @param chatRoomName the name of the chat room.
|
||||
* @param chatRoomID the id of the chat room.
|
||||
* @param addQueryResult indicates whether we should add the chat room to
|
||||
* the query results or fire an event without adding it to the results.
|
||||
* @param isAutoJoin the auto join state of the contact.
|
||||
*/
|
||||
private void addChatRoom(ProtocolProviderService pps,
|
||||
String chatRoomName, String chatRoomID, boolean addQueryResult)
|
||||
{
|
||||
if((queryString == null
|
||||
|| ((chatRoomName.contains(
|
||||
queryString)
|
||||
|| chatRoomID.contains(queryString)
|
||||
))) && isMatching(chatRoomID, pps))
|
||||
{
|
||||
BaseChatRoomSourceContact contact
|
||||
= new BaseChatRoomSourceContact(chatRoomName, chatRoomID, this,
|
||||
pps);
|
||||
synchronized (contactResults)
|
||||
{
|
||||
contactResults.add(contact);
|
||||
}
|
||||
|
||||
if(addQueryResult)
|
||||
{
|
||||
addQueryResult(contact, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
fireContactReceived(contact, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void chatRoomProviderWrapperAdded(ChatRoomProviderWrapper provider)
|
||||
{
|
||||
providerAdded(provider, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void chatRoomProviderWrapperRemoved(ChatRoomProviderWrapper provider)
|
||||
{
|
||||
LinkedList<BaseChatRoomSourceContact> tmpContactResults;
|
||||
synchronized (contactResults)
|
||||
{
|
||||
tmpContactResults
|
||||
= new LinkedList<BaseChatRoomSourceContact>(contactResults);
|
||||
|
||||
for(BaseChatRoomSourceContact contact : tmpContactResults)
|
||||
{
|
||||
if(contact.getProvider().equals(provider.getProtocolProvider()))
|
||||
{
|
||||
contactResults.remove(contact);
|
||||
fireContactRemoved(contact);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clears any listener we used.
|
||||
*/
|
||||
private void clearListeners()
|
||||
{
|
||||
mucService.removeChatRoomProviderWrapperListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels this <tt>ContactQuery</tt>.
|
||||
*
|
||||
* @see ContactQuery#cancel()
|
||||
*/
|
||||
public void cancel()
|
||||
{
|
||||
clearListeners();
|
||||
|
||||
super.cancel();
|
||||
}
|
||||
|
||||
/**
|
||||
* If query has status changed to cancel, let's clear listeners.
|
||||
* @param status {@link ContactQuery#QUERY_CANCELED},
|
||||
* {@link ContactQuery#QUERY_COMPLETED}
|
||||
*/
|
||||
public void setStatus(int status)
|
||||
{
|
||||
if(status == QUERY_CANCELED)
|
||||
clearListeners();
|
||||
|
||||
super.setStatus(status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addContactQueryListener(ContactQueryListener l)
|
||||
{
|
||||
super.addContactQueryListener(l);
|
||||
contactQueryListenersCount++;
|
||||
if(contactQueryListenersCount == 1)
|
||||
{
|
||||
initListeners();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeContactQueryListener(ContactQueryListener l)
|
||||
{
|
||||
super.removeContactQueryListener(l);
|
||||
contactQueryListenersCount--;
|
||||
if(contactQueryListenersCount == 0)
|
||||
{
|
||||
clearListeners();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the contact should be added to results or not.
|
||||
* @param chatRoomID the chat room id associated with the contact.
|
||||
* @param pps the provider of the chat room contact.
|
||||
* @return <tt>true</tt> if the result should be added to the results and
|
||||
* <tt>false</tt> if not.
|
||||
*/
|
||||
public boolean isMatching(String chatRoomID, ProtocolProviderService pps)
|
||||
{
|
||||
Logger.getLogger(getClass()).info("QQQQQQQQQQQQQQQQQQQQQQ " + chatRoomID + ' ' + (MUCActivator.getMUCService().findChatRoomWrapperFromChatRoomID(
|
||||
chatRoomID, pps) == null));
|
||||
return (MUCActivator.getMUCService().findChatRoomWrapperFromChatRoomID(
|
||||
chatRoomID, pps) == null);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue