Commit e7ef387b authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Refactoring work (roster listeners can now indicate if contacts are persitent or transient)

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@5091 b35dd754-fafc-0310-a699-88a17e54d16e
parent bc82ceb1
...@@ -322,6 +322,9 @@ public class Roster implements Cacheable { ...@@ -322,6 +322,9 @@ public class Roster implements Cacheable {
org.xmpp.packet.Roster.Subscription.none, groups); org.xmpp.packet.Roster.Subscription.none, groups);
RosterItem rosterItem = new RosterItem(item); RosterItem rosterItem = new RosterItem(item);
// Fire event indicating that a roster item is about to be added
persistent = RosterEventDispatcher.addingContact(this, rosterItem, persistent);
// Check if we need to make the new roster item persistent // Check if we need to make the new roster item persistent
if (persistent) { if (persistent) {
rosterItemProvider.createItem(username, rosterItem); rosterItemProvider.createItem(username, rosterItem);
...@@ -998,7 +1001,7 @@ public class Roster implements Cacheable { ...@@ -998,7 +1001,7 @@ public class Roster implements Cacheable {
// Do not delete the item if deletedUser belongs to a public group since the // Do not delete the item if deletedUser belongs to a public group since the
// subcription status will change // subcription status will change
!(deletedGroup.isUser(deletedUser) && !(deletedGroup.isUser(deletedUser) &&
rosterManager.isGroupPublic(deletedGroup))) { RosterManager.isPulicSharedGroup(deletedGroup))) {
// Delete the roster item from the roster since it exists only because of this // Delete the roster item from the roster since it exists only because of this
// group which is being removed // group which is being removed
deleteRosterItem(deletedUser, false); deleteRosterItem(deletedUser, false);
...@@ -1007,7 +1010,7 @@ public class Roster implements Cacheable { ...@@ -1007,7 +1010,7 @@ public class Roster implements Cacheable {
// Remove the shared group from the item if deletedUser does not belong to a // Remove the shared group from the item if deletedUser does not belong to a
// public group // public group
if (!(deletedGroup.isUser(deletedUser) && if (!(deletedGroup.isUser(deletedUser) &&
rosterManager.isGroupPublic(deletedGroup))) { RosterManager.isPulicSharedGroup(deletedGroup))) {
item.removeSharedGroup(deletedGroup); item.removeSharedGroup(deletedGroup);
} }
// Get the groups of the deleted user // Get the groups of the deleted user
......
...@@ -66,6 +66,29 @@ public class RosterEventDispatcher { ...@@ -66,6 +66,29 @@ public class RosterEventDispatcher {
} }
} }
/**
* Notifies listeners that a contact is about to be added to a roster. New contacts
* may be persisted to the database or not. Listeners may indicate that contact about
* to be persisted should not be persisted. Only one listener is needed to return
* <tt>false</tt> so that the contact is not persisted.
*
* @param roster the roster that was updated.
* @param item the new roster item.
* @param persistent true if the new contact is going to be saved to the database.
* @return false if the contact should not be persisted to the database.
*/
public static boolean addingContact(Roster roster, RosterItem item, boolean persistent) {
boolean answer = persistent;
if (!listeners.isEmpty()) {
for (RosterEventListener listener : listeners) {
if (!listener.addingContact(roster, item, persistent)) {
answer = false;
}
}
}
return answer;
}
/** /**
* Notifies the listeners that a contact has been added to a roster. * Notifies the listeners that a contact has been added to a roster.
* *
......
...@@ -27,6 +27,19 @@ public interface RosterEventListener { ...@@ -27,6 +27,19 @@ public interface RosterEventListener {
*/ */
public void rosterLoaded(Roster roster); public void rosterLoaded(Roster roster);
/**
* Notification message indicating that a contact is about to be added to a roster. New
* contacts may be persisted to the database or not. Listeners may indicate that contact
* about to be persisted should not be persisted. Only one listener is needed to return
* <tt>false</tt> so that the contact is not persisted.
*
* @param roster the roster that was updated.
* @param item the new roster item.
* @param persistent true if the new contact is going to be saved to the database.
* @return false if the contact should not be persisted to the database.
*/
public boolean addingContact(Roster roster, RosterItem item, boolean persistent);
/** /**
* Notification message indicating that a contact has been added to a roster. * Notification message indicating that a contact has been added to a roster.
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment