public void broadcastPresence(Presence packet) {
if (routingTable == null) {
return;
}
// Get the privacy list of this user
PrivacyList list = null;
JID from = packet.getFrom();
if (from != null) {
// Try to use the active list of the session. If none was found then try to use
// the default privacy list of the session
ClientSession session = sessionManager.getSession(from);
if (session != null) {
list = session.getActiveList();
list = list == null ? session.getDefaultList() : list;
}
}
if (list == null) {
// No privacy list was found (based on the session) so check if there is a default list
list = PrivacyListManager.getInstance().getDefaultPrivacyList(username);
}
// Broadcast presence to subscribed entities
for (RosterItem item : rosterItems.values()) {
if (item.getSubStatus() == RosterItem.SUB_BOTH || item.getSubStatus() == RosterItem.SUB_FROM) {
packet.setTo(item.getJid());
if (list != null && list.shouldBlockPacket(packet)) {
// Outgoing presence notifications are blocked for this contact
continue;
}
JID searchNode = new JID(item.getJid().getNode(), item.getJid().getDomain(), null, true);
for (JID jid : routingTable.getRoutes(searchNode, null)) {
try {
routingTable.routePacket(jid, packet, false);
}
catch (Exception e) {
// Theoretically only happens if session has been closed.
Log.debug(e.getMessage(), e);
}
}
}
}
// Broadcast presence to shared contacts whose subscription status is FROM
for (String contact : implicitFrom.keySet()) {
if (contact.contains("@")) {
String node = contact.substring(0, contact.lastIndexOf("@"));
String domain = contact.substring(contact.lastIndexOf("@")+1);
node = JID.escapeNode(node);
contact = new JID(node, domain, null).toBareJID();
}
packet.setTo(contact);
if (list != null && list.shouldBlockPacket(packet)) {
// Outgoing presence notifications are blocked for this contact
continue;
}
for (JID jid: routingTable.getRoutes(new JID(contact), null)) {
try {