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,20 +189,7 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
return;
}
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(DELETE_OFFLINE_PRESENCE);
pstmt.setString(1, username);
pstmt.execute();
}
catch (SQLException sqle) {
Log.error(sqle);
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
}
deleteOfflinePresenceFromDB(username);
// Remove data from cache.
offlinePresenceCache.remove(username);
......@@ -211,6 +197,23 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
}
}
private void deleteOfflinePresenceFromDB(String username) {
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(DELETE_OFFLINE_PRESENCE);
pstmt.setString(1, username);
pstmt.execute();
}
catch (SQLException sqle) {
Log.error(sqle);
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
}
}
public void userUnavailable(Presence presence) {
// Only save the last presence status and keep track of the time when the user went
// offline if this is an unavailable presence sent to THE SERVER and the presence belongs
......@@ -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