Commit 546f70f9 authored by Derek DeMoro's avatar Derek DeMoro Committed by derek

Refactoring changes


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@613 b35dd754-fafc-0310-a699-88a17e54d16e
parent 6793c5d1
...@@ -702,7 +702,7 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -702,7 +702,7 @@ public class MUCRoomImpl implements MUCRoom {
} }
public void sendPrivateMessage(Message message, MUCRole senderRole) throws NotFoundException { public void sendPrivateMessage(Message message, MUCRole senderRole) throws NotFoundException {
String resource = message.setTo().getResource(); String resource = message.getTo().getResource();
MUCRole occupant = occupants.get(resource.toLowerCase()); MUCRole occupant = occupants.get(resource.toLowerCase());
if (occupant != null) { if (occupant != null) {
message.setFrom(senderRole.getRoleAddress()); message.setFrom(senderRole.getRoleAddress());
...@@ -1558,8 +1558,13 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -1558,8 +1558,13 @@ public class MUCRoomImpl implements MUCRoom {
// of the room // of the room
for (MUCRole occupant : occupants.values()) { for (MUCRole occupant : occupants.values()) {
if (occupant.getAffiliation() > MUCRole.MEMBER) { if (occupant.getAffiliation() > MUCRole.MEMBER) {
presences.add(kickOccupant(jid, null, try {
LocaleUtils.getLocalizedString("muc.roomIsNowMembersOnly"))); presences.add(kickOccupant(occupant.getRoleAddress(), null,
LocaleUtils.getLocalizedString("muc.roomIsNowMembersOnly")));
}
catch (NotAllowedException e) {
e.printStackTrace();
}
} }
} }
} }
......
...@@ -11,9 +11,22 @@ ...@@ -11,9 +11,22 @@
package org.jivesoftware.messenger.spi; package org.jivesoftware.messenger.spi;
import java.util.*; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.jivesoftware.messenger.*; import org.jivesoftware.messenger.Component;
import org.jivesoftware.messenger.ComponentManager;
import org.jivesoftware.messenger.PacketDeliverer;
import org.jivesoftware.messenger.PresenceManager;
import org.jivesoftware.messenger.RoutingTable;
import org.jivesoftware.messenger.Session;
import org.jivesoftware.messenger.SessionManager;
import org.jivesoftware.messenger.XMPPServer;
import org.jivesoftware.messenger.auth.UnauthorizedException; import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.container.BasicModule; import org.jivesoftware.messenger.container.BasicModule;
import org.jivesoftware.messenger.container.Container; import org.jivesoftware.messenger.container.Container;
...@@ -25,8 +38,8 @@ import org.jivesoftware.util.Cache; ...@@ -25,8 +38,8 @@ import org.jivesoftware.util.Cache;
import org.jivesoftware.util.JiveConstants; import org.jivesoftware.util.JiveConstants;
import org.jivesoftware.util.LocaleUtils; import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.xmpp.packet.Presence;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.Presence;
/** /**
* Simple in memory implementation of the PresenceManager interface. * Simple in memory implementation of the PresenceManager interface.
...@@ -102,7 +115,7 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -102,7 +115,7 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
List presences = new ArrayList(); List presences = new ArrayList();
while (iter.hasNext()) { while (iter.hasNext()) {
Presence presence = (Presence)iter.next(); Presence presence = (Presence) iter.next();
if (presence.isAvailable()) { if (presence.isAvailable()) {
presences.add(presence); presences.add(presence);
...@@ -114,13 +127,17 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -114,13 +127,17 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
{ {
Collections.sort(presences, new Comparator() { Collections.sort(presences, new Comparator() {
public int compare(Object object1, Object object2) { public int compare(Object object1, Object object2) {
Presence presence1 = (Presence)object1; Presence presence1 = (Presence) object1;
Presence presence2 = (Presence)object2; Presence presence2 = (Presence) object2;
Session presence1Session = sessionManager.getSession(presence1.getFrom());
Session presence2Session = sessionManager.getSession(presence2.getFrom());
if (ascending) { if (ascending) {
return presence1.getLoginTime().compareTo(presence2.getLoginTime()); return presence1Session.getCreationDate().compareTo(presence2Session.getCreationDate());
} }
else { else {
return presence2.getLoginTime().compareTo(presence1.getLoginTime()); return presence2Session.getCreationDate().compareTo(presence1Session.getCreationDate());
} }
} }
}); });
...@@ -130,17 +147,15 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -130,17 +147,15 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
{ {
Collections.sort(presences, new Comparator() { Collections.sort(presences, new Comparator() {
public int compare(Object object1, Object object2) { public int compare(Object object1, Object object2) {
Presence presence1 = (Presence)object1; Presence presence1 = (Presence) object1;
Presence presence2 = (Presence)object2; Presence presence2 = (Presence) object2;
String presenceUser1 = ""; String presenceUser1 = "";
String presenceUser2 = ""; String presenceUser2 = "";
try { try {
presenceUser1 = presenceUser1 =
userManager.getUser(presence1.getFrom().getNode() userManager.getUser(presence1.getFrom().getNode()).getUsername();
).getUsername();
presenceUser2 = presenceUser2 =
userManager.getUser(presence2.getFrom().getNode() userManager.getUser(presence2.getFrom().getNode()).getUsername();
).getUsername();
} }
catch (UserNotFoundException e) { catch (UserNotFoundException e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e); Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
...@@ -164,7 +179,7 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -164,7 +179,7 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
List<User> users = new ArrayList<User>(); List<User> users = new ArrayList<User>();
for (int i = 0; i < presences.size(); i++) { for (int i = 0; i < presences.size(); i++) {
Presence presence = (Presence)presences.get(i); Presence presence = (Presence) presences.get(i);
try { try {
users.add(userManager.getUser(presence.getFrom().getNode())); users.add(userManager.getUser(presence.getFrom().getNode()));
} }
...@@ -230,7 +245,8 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -230,7 +245,8 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
try { try {
return sessionManager.getSessionCount(user.getUsername()) > 0; return sessionManager.getSessionCount(user.getUsername()) > 0;
} }
catch (UnauthorizedException ue) { } catch (UnauthorizedException ue) {
}
return false; return false;
} }
...@@ -239,17 +255,15 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -239,17 +255,15 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
return null; return null;
} }
Presence presence = null; Presence presence = null;
try {
for (Session session : sessionManager.getSessions(user.getUsername())) { for (Session session : sessionManager.getSessions(user.getUsername())) {
if (presence == null) { if (presence == null) {
presence = session.getPresence(); presence = session.getPresence();
} }
else if (presence.getShow().ordinal() > session.getPresence().getShow().ordinal()) { else if (presence.getShow().ordinal() > session.getPresence().getShow().ordinal()) {
presence = session.getPresence(); presence = session.getPresence();
}
} }
} }
catch (UnauthorizedException ue) { }
return presence; return presence;
} }
...@@ -258,12 +272,10 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -258,12 +272,10 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
return null; return null;
} }
List<Presence> presences = new ArrayList<Presence>(); List<Presence> presences = new ArrayList<Presence>();
try {
for (Session session : sessionManager.getSessions(user.getUsername())) { for (Session session : sessionManager.getSessions(user.getUsername())) {
presences.add(session.getPresence()); presences.add(session.getPresence());
}
} }
catch (UnauthorizedException ue) { }
return Collections.unmodifiableCollection(presences); return Collections.unmodifiableCollection(presences);
} }
...@@ -274,7 +286,7 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -274,7 +286,7 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
// search the current lists for the presence // search the current lists for the presence
Iterator onlineUsers = this.onlineUsers.values().iterator(); Iterator onlineUsers = this.onlineUsers.values().iterator();
while (onlineUsers.hasNext()) { while (onlineUsers.hasNext()) {
Presence presence = (Presence)onlineUsers.next(); Presence presence = (Presence) onlineUsers.next();
if (presence.getID().equals(presenceID)) { if (presence.getID().equals(presenceID)) {
return presence; return presence;
...@@ -282,7 +294,7 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -282,7 +294,7 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
} }
Iterator guestUsers = onlineGuests.values().iterator(); Iterator guestUsers = onlineGuests.values().iterator();
while (guestUsers.hasNext()) { while (guestUsers.hasNext()) {
Presence presence = (Presence)guestUsers.next(); Presence presence = (Presence) guestUsers.next();
if (presence.getID().equals(presenceID)) { if (presence.getID().equals(presenceID)) {
return presence; return presence;
...@@ -318,7 +330,7 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -318,7 +330,7 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
component.processPacket(presence); component.processPacket(presence);
} }
else { else {
Presence presence = (Presence)foreignUserCache.get(probee.toBareJID()); Presence presence = (Presence) foreignUserCache.get(probee.toBareJID());
if (presence != null) { if (presence != null) {
Presence presencePacket = presence.createCopy(); Presence presencePacket = presence.createCopy();
presencePacket.setFrom(probee); presencePacket.setFrom(probee);
...@@ -335,7 +347,7 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -335,7 +347,7 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
} }
} }
} }
catch (UnauthorizedException e) { catch (Exception e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e); Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
} }
} }
...@@ -358,7 +370,7 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -358,7 +370,7 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
} }
else { else {
Presence presence = Presence presence =
(Presence)foreignUserCache.get(probee.toBareJID()); (Presence) foreignUserCache.get(probee.toBareJID());
if (presence != null) { if (presence != null) {
Presence presencePacket = presence.createCopy(); Presence presencePacket = presence.createCopy();
presencePacket.setFrom(probee); presencePacket.setFrom(probee);
...@@ -371,7 +383,7 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -371,7 +383,7 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
} }
} }
} }
catch (UnauthorizedException e) { catch (Exception e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e); Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
} }
} }
......
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