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.*;
import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.component.InternalComponentManager;
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.privacy.PrivacyList;
import org.jivesoftware.openfire.privacy.PrivacyListManager;
......@@ -41,10 +43,7 @@ import org.xmpp.packet.Presence;
import java.sql.Connection;
import java.sql.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.*;
import java.util.concurrent.locks.Lock;
/**
......@@ -52,7 +51,7 @@ import java.util.concurrent.locks.Lock;
*
* @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 =
"SELECT offlinePresence, offlineDate FROM ofPresence WHERE username=?";
......@@ -190,6 +189,15 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
return;
}
deleteOfflinePresenceFromDB(username);
// Remove data from cache.
offlinePresenceCache.remove(username);
lastActivityCache.remove(username);
}
}
private void deleteOfflinePresenceFromDB(String username) {
Connection con = null;
PreparedStatement pstmt = null;
try {
......@@ -204,11 +212,6 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
finally {
DbConnectionManager.closeConnection(pstmt, con);
}
// Remove data from cache.
offlinePresenceCache.remove(username);
lastActivityCache.remove(username);
}
}
public void userUnavailable(Presence presence) {
......@@ -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
// #####################################################################
......@@ -485,6 +501,8 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
super.start();
// Use component manager for Presence Updates.
componentManager = InternalComponentManager.getInstance();
// Listen for user deletion events
UserEventDispatcher.addListener(this);
}
......@@ -492,6 +510,8 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
// Clear the caches when stopping the module.
offlinePresenceCache.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