Commit 4b9a1283 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Delete offline presence information when removing user account. JM-1442

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@10723 b35dd754-fafc-0310-a699-88a17e54d16e
parent c6e4fa01
...@@ -20,6 +20,8 @@ import org.jivesoftware.openfire.*; ...@@ -20,6 +20,8 @@ import org.jivesoftware.openfire.*;
import org.jivesoftware.openfire.auth.UnauthorizedException; import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.component.InternalComponentManager; import org.jivesoftware.openfire.component.InternalComponentManager;
import org.jivesoftware.openfire.container.BasicModule; import org.jivesoftware.openfire.container.BasicModule;
import org.jivesoftware.openfire.event.UserEventDispatcher;
import org.jivesoftware.openfire.event.UserEventListener;
import org.jivesoftware.openfire.handler.PresenceUpdateHandler; import org.jivesoftware.openfire.handler.PresenceUpdateHandler;
import org.jivesoftware.openfire.privacy.PrivacyList; import org.jivesoftware.openfire.privacy.PrivacyList;
import org.jivesoftware.openfire.privacy.PrivacyListManager; import org.jivesoftware.openfire.privacy.PrivacyListManager;
...@@ -41,10 +43,7 @@ import org.xmpp.packet.Presence; ...@@ -41,10 +43,7 @@ import org.xmpp.packet.Presence;
import java.sql.Connection; import java.sql.Connection;
import java.sql.*; import java.sql.*;
import java.util.ArrayList; import java.util.*;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
/** /**
...@@ -52,7 +51,7 @@ import java.util.concurrent.locks.Lock; ...@@ -52,7 +51,7 @@ import java.util.concurrent.locks.Lock;
* *
* @author Iain Shigeoka * @author Iain Shigeoka
*/ */
public class PresenceManagerImpl extends BasicModule implements PresenceManager { public class PresenceManagerImpl extends BasicModule implements PresenceManager, UserEventListener {
private static final String LOAD_OFFLINE_PRESENCE = private static final String LOAD_OFFLINE_PRESENCE =
"SELECT offlinePresence, offlineDate FROM ofPresence WHERE username=?"; "SELECT offlinePresence, offlineDate FROM ofPresence WHERE username=?";
...@@ -190,6 +189,15 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -190,6 +189,15 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
return; return;
} }
deleteOfflinePresenceFromDB(username);
// Remove data from cache.
offlinePresenceCache.remove(username);
lastActivityCache.remove(username);
}
}
private void deleteOfflinePresenceFromDB(String username) {
Connection con = null; Connection con = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
try { try {
...@@ -204,11 +212,6 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -204,11 +212,6 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
finally { finally {
DbConnectionManager.closeConnection(pstmt, con); DbConnectionManager.closeConnection(pstmt, con);
} }
// Remove data from cache.
offlinePresenceCache.remove(username);
lastActivityCache.remove(username);
}
} }
public void userUnavailable(Presence presence) { public void userUnavailable(Presence presence) {
...@@ -462,7 +465,20 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -462,7 +465,20 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
} }
} }
// ##################################################################### public void userCreated(User user, Map<String, Object> params) {
// Do nothing
}
public void userDeleting(User user, Map<String, Object> params) {
// Delete user information
deleteOfflinePresenceFromDB(user.getUsername());
}
public void userModified(User user, Map<String, Object> params) {
// Do nothing
}
// #####################################################################
// Module management // Module management
// ##################################################################### // #####################################################################
...@@ -485,6 +501,8 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -485,6 +501,8 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
super.start(); super.start();
// Use component manager for Presence Updates. // Use component manager for Presence Updates.
componentManager = InternalComponentManager.getInstance(); componentManager = InternalComponentManager.getInstance();
// Listen for user deletion events
UserEventDispatcher.addListener(this);
} }
...@@ -492,6 +510,8 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -492,6 +510,8 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
// Clear the caches when stopping the module. // Clear the caches when stopping the module.
offlinePresenceCache.clear(); offlinePresenceCache.clear();
lastActivityCache.clear(); lastActivityCache.clear();
// Stop listening for user deletion events
UserEventDispatcher.removeListener(this);
} }
/** /**
......
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