package asmack.org.jivesoftware.smackx; import asmack.org.jivesoftware.smack.Connection; import asmack.org.jivesoftware.smack.XMPPException; import asmack.org.jivesoftware.smack.packet.Message; import asmack.org.jivesoftware.smack.packet.Packet; import asmack.org.jivesoftware.smack.util.Cache; import asmack.org.jivesoftware.smack.util.StringUtils; import asmack.org.jivesoftware.smackx.packet.DiscoverItems; import asmack.org.jivesoftware.smackx.packet.MultipleAddresses; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class MultipleRecipientManager { private static Cache services = new Cache(100, 86400000); /* access modifiers changed from: private */ public static class PacketCopy extends Packet { private String text; public PacketCopy(String str) { this.text = str; } @Override // asmack.org.jivesoftware.smack.packet.Packet public String toXML() { return this.text; } } /* JADX WARNING: Removed duplicated region for block: B:20:0x0062 A[Catch:{ XMPPException -> 0x006a }] */ /* JADX WARNING: Removed duplicated region for block: B:21:0x0065 A[Catch:{ XMPPException -> 0x006a }] */ private static String getMultipleRecipienServiceAddress(Connection connection) { String serviceName = connection.getServiceName(); String str = (String) services.get(serviceName); if (str == null) { synchronized (services) { str = (String) services.get(serviceName); if (str == null) { try { if (!ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(serviceName).containsFeature("http://jabber.org/protocol/address")) { Iterator<DiscoverItems.Item> items = ServiceDiscoveryManager.getInstanceFor(connection).discoverItems(serviceName).getItems(); while (true) { if (items.hasNext()) { DiscoverItems.Item next = items.next(); if (ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(next.getEntityID(), next.getNode()).containsFeature("http://jabber.org/protocol/address")) { break; } } else { break; } } services.put(serviceName, str != null ? "" : str); } str = serviceName; services.put(serviceName, str != null ? "" : str); } catch (XMPPException e2) { e2.printStackTrace(); } } } } if ("".equals(str)) { return null; } return str; } public static MultipleRecipientInfo getMultipleRecipientInfo(Packet packet) { MultipleAddresses multipleAddresses = (MultipleAddresses) packet.getExtension("addresses", "http://jabber.org/protocol/address"); if (multipleAddresses == null) { return null; } return new MultipleRecipientInfo(multipleAddresses); } public static void reply(Connection connection, Message message, Message message2) throws XMPPException { MultipleRecipientInfo multipleRecipientInfo = getMultipleRecipientInfo(message); if (multipleRecipientInfo == null) { throw new XMPPException("Original message does not contain multiple recipient info"); } else if (multipleRecipientInfo.shouldNotReply()) { throw new XMPPException("Original message should not be replied"); } else if (multipleRecipientInfo.getReplyRoom() == null) { if (message.getThread() != null) { message2.setThread(message.getThread()); } MultipleAddresses.Address replyAddress = multipleRecipientInfo.getReplyAddress(); if (replyAddress == null || replyAddress.getJid() == null) { ArrayList arrayList = new ArrayList(); ArrayList arrayList2 = new ArrayList(); for (MultipleAddresses.Address address : multipleRecipientInfo.getTOAddresses()) { arrayList.add(address.getJid()); } for (MultipleAddresses.Address address2 : multipleRecipientInfo.getCCAddresses()) { arrayList2.add(address2.getJid()); } if (!arrayList.contains(message.getFrom()) && !arrayList2.contains(message.getFrom())) { arrayList.add(message.getFrom()); } String user = connection.getUser(); if (!arrayList.remove(user) && !arrayList2.remove(user)) { String parseBareAddress = StringUtils.parseBareAddress(user); arrayList.remove(parseBareAddress); arrayList2.remove(parseBareAddress); } String multipleRecipienServiceAddress = getMultipleRecipienServiceAddress(connection); if (multipleRecipienServiceAddress != null) { sendThroughService(connection, message2, arrayList, arrayList2, null, null, null, false, multipleRecipienServiceAddress); } else { sendToIndividualRecipients(connection, message2, arrayList, arrayList2, null); } } else { message2.setTo(replyAddress.getJid()); connection.sendPacket(message2); } } else { throw new XMPPException("Reply should be sent through a room"); } } public static void send(Connection connection, Packet packet, List list, List list2, List list3) throws XMPPException { send(connection, packet, list, list2, list3, null, null, false); } public static void send(Connection connection, Packet packet, List list, List list2, List list3, String str, String str2, boolean z) throws XMPPException { String multipleRecipienServiceAddress = getMultipleRecipienServiceAddress(connection); if (multipleRecipienServiceAddress != null) { sendThroughService(connection, packet, list, list2, list3, str, str2, z, multipleRecipienServiceAddress); } else if (z || ((str != null && str.trim().length() > 0) || (str2 != null && str2.trim().length() > 0))) { throw new XMPPException("Extended Stanza Addressing not supported by server"); } else { sendToIndividualRecipients(connection, packet, list, list2, list3); } } private static void sendThroughService(Connection connection, Packet packet, List list, List list2, List list3, String str, String str2, boolean z, String str3) { MultipleAddresses multipleAddresses = new MultipleAddresses(); if (list != null) { Iterator it2 = list.iterator(); while (it2.hasNext()) { multipleAddresses.addAddress("to", (String) it2.next(), null, null, false, null); } } if (list2 != null) { Iterator it3 = list2.iterator(); while (it3.hasNext()) { multipleAddresses.addAddress(MultipleAddresses.CC, (String) it3.next(), null, null, false, null); } } if (list3 != null) { Iterator it4 = list3.iterator(); while (it4.hasNext()) { multipleAddresses.addAddress(MultipleAddresses.BCC, (String) it4.next(), null, null, false, null); } } if (z) { multipleAddresses.setNoReply(); } else { if (str != null && str.trim().length() > 0) { multipleAddresses.addAddress(MultipleAddresses.REPLY_TO, str, null, null, false, null); } if (str2 != null && str2.trim().length() > 0) { multipleAddresses.addAddress(MultipleAddresses.REPLY_ROOM, str2, null, null, false, null); } } packet.setTo(str3); packet.addExtension(multipleAddresses); connection.sendPacket(packet); } private static void sendToIndividualRecipients(Connection connection, Packet packet, List list, List list2, List list3) { if (list != null) { Iterator it2 = list.iterator(); while (it2.hasNext()) { packet.setTo((String) it2.next()); connection.sendPacket(new PacketCopy(packet.toXML())); } } if (list2 != null) { Iterator it3 = list2.iterator(); while (it3.hasNext()) { packet.setTo((String) it3.next()); connection.sendPacket(new PacketCopy(packet.toXML())); } } if (list3 != null) { Iterator it4 = list3.iterator(); while (it4.hasNext()) { packet.setTo((String) it4.next()); connection.sendPacket(new PacketCopy(packet.toXML())); } } } }