aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamian Minkov <damencho@jitsi.org>2010-10-14 14:47:07 +0000
committerDamian Minkov <damencho@jitsi.org>2010-10-14 14:47:07 +0000
commit95add67b7ac0840482e51513b19d11425a478fda (patch)
treeccb979aeb6f29c594a107770720b490ed24f48f5
parentebfbac3d8d0120972f7f6a6ad6e266579d73aba2 (diff)
downloadjitsi-95add67b7ac0840482e51513b19d11425a478fda.zip
jitsi-95add67b7ac0840482e51513b19d11425a478fda.tar.gz
jitsi-95add67b7ac0840482e51513b19d11425a478fda.tar.bz2
Fix jabber creating missing groups on update when groups are created somewhere else.
Fix duplicating jabber groups with extra whitespace in its name. Displaying or hiding jabber roster items as suggested in XEP-0162.
-rw-r--r--src/net/java/sip/communicator/impl/protocol/jabber/ContactGroupJabberImpl.java4
-rw-r--r--src/net/java/sip/communicator/impl/protocol/jabber/ServerStoredContactListJabberImpl.java91
2 files changed, 75 insertions, 20 deletions
diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/ContactGroupJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/ContactGroupJabberImpl.java
index 1b4769c..286436e 100644
--- a/src/net/java/sip/communicator/impl/protocol/jabber/ContactGroupJabberImpl.java
+++ b/src/net/java/sip/communicator/impl/protocol/jabber/ContactGroupJabberImpl.java
@@ -112,7 +112,7 @@ public class ContactGroupJabberImpl
{
RosterEntry rEntry = groupMembers.next();
- if(rEntry.getType() == RosterPacket.ItemType.none)
+ if(!ServerStoredContactListJabberImpl.isEntryDisplayable(rEntry))
continue;
//only add the buddy if it doesn't already exist in some other group
@@ -445,7 +445,7 @@ public class ContactGroupJabberImpl
// to our roster and this contacts are with subscription none.
// if such already exist, remove it. This is typically our
// own contact
- if(item.getType() == RosterPacket.ItemType.none)
+ if(!ServerStoredContactListJabberImpl.isEntryDisplayable(item))
{
if(contact != null)
{
diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/ServerStoredContactListJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/ServerStoredContactListJabberImpl.java
index dcd6f0d..aadf798 100644
--- a/src/net/java/sip/communicator/impl/protocol/jabber/ServerStoredContactListJabberImpl.java
+++ b/src/net/java/sip/communicator/impl/protocol/jabber/ServerStoredContactListJabberImpl.java
@@ -302,14 +302,16 @@ public class ServerStoredContactListJabberImpl
{
Iterator<ContactGroup> contactGroups = rootGroup.subgroups();
+ // make sure we ignore any whitespaces
+ name = name.trim();
+
while(contactGroups.hasNext())
{
ContactGroupJabberImpl contactGroup
= (ContactGroupJabberImpl) contactGroups.next();
- if (contactGroup.getGroupName().equals(name))
+ if (contactGroup.getGroupName().trim().equals(name))
return contactGroup;
-
}
return null;
@@ -325,12 +327,15 @@ public class ServerStoredContactListJabberImpl
{
Iterator<ContactGroup> contactGroups = rootGroup.subgroups();
+ // make sure we ignore any whitespaces
+ name = name.trim();
+
while(contactGroups.hasNext())
{
ContactGroupJabberImpl contactGroup
= (ContactGroupJabberImpl) contactGroups.next();
- if (contactGroup.getNameCopy().equals(name))
+ if (contactGroup.getNameCopy().trim().equals(name))
return contactGroup;
}
@@ -762,7 +767,7 @@ public class ServerStoredContactListJabberImpl
// addressbook to the roster and those contacts are
// with subscription none. If such already exist,
// remove them. This is typically our own contact
- if(item.getType() == RosterPacket.ItemType.none)
+ if(!isEntryDisplayable(item))
{
if(contact != null)
{
@@ -922,6 +927,40 @@ public class ServerStoredContactListJabberImpl
}
/**
+ * Some roster entries are not supposed to be seen.
+ * Like some services automatically add contacts from their
+ * addressbook to the roster and those contacts are with subscription none.
+ * Best practices in XEP-0162.
+ * - subscription='both' or subscription='to'
+ * - ((subscription='none' or subscription='from') and ask='subscribe')
+ * - ((subscription='none' or subscription='from')
+ * and (name attribute or group child))
+ *
+ * @param entry the entry to check.
+ *
+ * @return is item to be hidden/ignored.
+ */
+ static boolean isEntryDisplayable(RosterEntry entry)
+ {
+ if(entry.getType() == RosterPacket.ItemType.both
+ || entry.getType() == RosterPacket.ItemType.to)
+ {
+ return true;
+ }
+ else if((entry.getType() == RosterPacket.ItemType.none
+ || entry.getType() == RosterPacket.ItemType.from)
+ && (RosterPacket.ItemStatus.SUBSCRIPTION_PENDING.equals(
+ entry.getStatus())
+ || (entry.getGroups() != null
+ && entry.getGroups().size() > 0)))
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
* Receives changes in roster.
*/
private class ChangeListener
@@ -973,27 +1012,43 @@ public class ServerStoredContactListJabberImpl
true,
true);
- boolean isUnfiledEntry = true;
+ if(entry.getGroups() == null || entry.getGroups().size() == 0)
+ {
+ // no parent group so its in the root group
+ rootGroup.addContact(contact);
+ fireContactAdded(rootGroup, contact);
+
+ return;
+ }
+
for (RosterGroup group : entry.getGroups())
{
ContactGroupJabberImpl parentGroup =
findContactGroup(group.getName());
+
if(parentGroup != null)
+ {
parentGroup.addContact(contact);
+ fireContactAdded(findContactGroup(contact), contact);
+ }
+ else
+ {
+ // create the group as it doesn't exist
+ ContactGroupJabberImpl newGroup =
+ new ContactGroupJabberImpl(
+ group, group.getEntries().iterator(),
+ ServerStoredContactListJabberImpl.this,
+ true);
+
+ rootGroup.addSubGroup(newGroup);
+
+ //tell listeners about the added group
+ fireGroupEvent(newGroup,
+ ServerStoredGroupEvent.GROUP_CREATED_EVENT);
+ }
- isUnfiledEntry = false;
- }
-
- ContactGroup parentGroup = findContactGroup(contact);
-
- // fire the event if and only we have parent group
- if(parentGroup != null && !isUnfiledEntry)
- fireContactAdded(findContactGroup(contact), contact);
-
- if(parentGroup == null && isUnfiledEntry)
- {
- rootGroup.addContact(contact);
- fireContactAdded(rootGroup, contact);
+ // as for now we only support contact only in one group
+ return;
}
}
}