Fixes the order of chat room contacts to be ordered by presence status.

cusax-fix 4913
hristoterezov 12 years ago
parent 5898ddd57f
commit 3b5c887b80

@ -296,9 +296,24 @@ public void contactChanged(ContactChangedEvent event)
return;
ContactNode contactNode = ((UIContactImpl) uiContact).getContactNode();
if (contactNode != null)
{
nodeChanged(contactNode);
TreeNode parentNode = contactNode.getParent();
if(parentNode == null)
return;
int currentIndex = parentNode.getIndex(contactNode);
if(currentIndex != sourceContact.getIndex())
{
UIGroupImpl uiGroup = (UIGroupImpl)sourceUI.getUIGroup();
GroupNode groupNode = uiGroup.getGroupNode();
if (groupNode == null)
return;
groupNode.sort(treeModel);
}
}
}
/**

@ -38,8 +38,8 @@ public class ChatRoomQuery
/**
* List with the current results for the query.
*/
private List<ChatRoomSourceContact> contactResults
= new LinkedList<ChatRoomSourceContact>();
private Set<ChatRoomSourceContact> contactResults
= new TreeSet<ChatRoomSourceContact>();
/**
* MUC service.
@ -144,15 +144,16 @@ public void localUserPresenceChanged(
String eventType = evt.getEventType();
boolean existingContact = false;
SourceContact foundContact = null;
ChatRoomSourceContact foundContact = null;
synchronized (contactResults)
{
for(SourceContact contact : contactResults)
for(ChatRoomSourceContact contact : contactResults)
{
if(contact.getContactAddress().equals(sourceChatRoom.getName()))
{
existingContact = true;
foundContact = contact;
contactResults.remove(contact);
break;
}
}
@ -166,6 +167,10 @@ public void localUserPresenceChanged(
{
((ChatRoomSourceContact)foundContact).setPresenceStatus(
ChatRoomPresenceStatus.CHAT_ROOM_ONLINE);
synchronized (contactResults)
{
contactResults.add(foundContact);
}
fireContactChanged(foundContact);
}
else
@ -186,6 +191,10 @@ else if ((LocalUserChatRoomPresenceChangeEvent
((ChatRoomSourceContact)foundContact)
.setPresenceStatus(
ChatRoomPresenceStatus.CHAT_ROOM_OFFLINE);
synchronized (contactResults)
{
contactResults.add(foundContact);
}
fireContactChanged(foundContact);
}
}
@ -324,4 +333,20 @@ public void chatRoomProviderWrapperRemoved(ChatRoomProviderWrapper provider)
}
}
}
public synchronized int indexOf(ChatRoomSourceContact contact)
{
Iterator<ChatRoomSourceContact> it = contactResults.iterator();
int i = 0;
while(it.hasNext())
{
if(contact.equals(it.next()))
{
return i;
}
i++;
}
return -1;
}
}

@ -19,6 +19,10 @@
public class ChatRoomSourceContact
extends SortedGenericSourceContact
{
/**
* The parent contact query.
*/
private final ChatRoomQuery parentQuery;
/**
* The name of the chat room associated with the contact.
*/
@ -50,6 +54,7 @@ public ChatRoomSourceContact(String chatRoomName,
this.chatRoomName = chatRoomName;
this.chatRoomID = chatRoomID;
this.provider = pps;
this.parentQuery = query;
initContactProperties(getChatRoomStateByName());
@ -68,6 +73,7 @@ public ChatRoomSourceContact(ChatRoom chatRoom, ChatRoomQuery query)
this.chatRoomName = chatRoom.getName();
this.chatRoomID = chatRoom.getIdentifier();
this.provider = chatRoom.getParentProvider();
this.parentQuery = query;
initContactProperties(
(chatRoom.isJoined()?
@ -162,4 +168,16 @@ 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 parentQuery.indexOf(this);
}
}

@ -65,4 +65,10 @@ protected ChatRoomPresenceStatus(int status, String statusName)
super(status, statusName);
}
@Override
public boolean isOnline()
{
return getStatus() == CHAT_ROOM_ONLINE_THRESHOLD;
}
}

Loading…
Cancel
Save