Search in sources :

Example 46 with Jid

use of org.jxmpp.jid.Jid in project Smack by igniterealtime.

the class MultipleRecipientManager method sendThroughService.

private static void sendThroughService(XMPPConnection connection, Stanza packet, Collection<? extends Jid> to, Collection<? extends Jid> cc, Collection<? extends Jid> bcc, Jid replyTo, Jid replyRoom, boolean noReply, DomainBareJid serviceAddress) throws NotConnectedException, InterruptedException {
    // Create multiple recipient extension
    MultipleAddresses multipleAddresses = new MultipleAddresses();
    if (to != null) {
        for (Jid jid : to) {
            multipleAddresses.addAddress(MultipleAddresses.Type.to, jid, null, null, false, null);
        }
    }
    if (cc != null) {
        for (Jid jid : cc) {
            multipleAddresses.addAddress(MultipleAddresses.Type.to, jid, null, null, false, null);
        }
    }
    if (bcc != null) {
        for (Jid jid : bcc) {
            multipleAddresses.addAddress(MultipleAddresses.Type.bcc, jid, null, null, false, null);
        }
    }
    if (noReply) {
        multipleAddresses.setNoReply();
    } else {
        if (replyTo != null) {
            multipleAddresses.addAddress(MultipleAddresses.Type.replyto, replyTo, null, null, false, null);
        }
        if (replyRoom != null) {
            multipleAddresses.addAddress(MultipleAddresses.Type.replyroom, replyRoom, null, null, false, null);
        }
    }
    // Set the multiple recipient service address as the target address
    packet.setTo(serviceAddress);
    // Add extension to packet
    packet.addExtension(multipleAddresses);
    // Send the packet
    connection.sendStanza(packet);
}
Also used : MultipleAddresses(org.jivesoftware.smackx.address.packet.MultipleAddresses) Jid(org.jxmpp.jid.Jid) EntityFullJid(org.jxmpp.jid.EntityFullJid) DomainBareJid(org.jxmpp.jid.DomainBareJid) EntityBareJid(org.jxmpp.jid.EntityBareJid)

Example 47 with Jid

use of org.jxmpp.jid.Jid in project Smack by igniterealtime.

the class MultipleRecipientManager method sendToIndividualRecipients.

private static void sendToIndividualRecipients(XMPPConnection connection, Stanza packet, Collection<? extends Jid> to, Collection<? extends Jid> cc, Collection<? extends Jid> bcc) throws NotConnectedException, InterruptedException {
    if (to != null) {
        for (Jid jid : to) {
            packet.setTo(jid);
            connection.sendStanza(new PacketCopy(packet.toXML()));
        }
    }
    if (cc != null) {
        for (Jid jid : cc) {
            packet.setTo(jid);
            connection.sendStanza(new PacketCopy(packet.toXML()));
        }
    }
    if (bcc != null) {
        for (Jid jid : bcc) {
            packet.setTo(jid);
            connection.sendStanza(new PacketCopy(packet.toXML()));
        }
    }
}
Also used : Jid(org.jxmpp.jid.Jid) EntityFullJid(org.jxmpp.jid.EntityFullJid) DomainBareJid(org.jxmpp.jid.DomainBareJid) EntityBareJid(org.jxmpp.jid.EntityBareJid)

Example 48 with Jid

use of org.jxmpp.jid.Jid in project Smack by igniterealtime.

the class ChatManager method createChat.

/**
     * Creates a new {@link Chat} based on the message. May returns null if no chat could be
     * created, e.g. because the message comes without from.
     *
     * @param message
     * @return a Chat or null if none can be created
     */
private Chat createChat(Message message) {
    Jid from = message.getFrom();
    // are of no use in this case for ChatManager
    if (from == null) {
        return null;
    }
    EntityJid userJID = from.asEntityJidIfPossible();
    if (userJID == null) {
        LOGGER.warning("Message from JID without localpart: '" + message.toXML() + "'");
        return null;
    }
    String threadID = message.getThread();
    if (threadID == null) {
        threadID = nextID();
    }
    return createChat(userJID, threadID, false);
}
Also used : EntityJid(org.jxmpp.jid.EntityJid) EntityBareJid(org.jxmpp.jid.EntityBareJid) Jid(org.jxmpp.jid.Jid) EntityJid(org.jxmpp.jid.EntityJid)

Example 49 with Jid

use of org.jxmpp.jid.Jid in project Smack by igniterealtime.

the class SubscriptionPreApprovalTest method testPreApprovalNotSupported.

@Test(expected = FeatureNotSupportedException.class)
public void testPreApprovalNotSupported() throws Throwable {
    final Jid contactJID = JidCreate.from("preapproval@example.com");
    roster.preApprove(contactJID.asBareJid());
}
Also used : Jid(org.jxmpp.jid.Jid) BareJid(org.jxmpp.jid.BareJid) Test(org.junit.Test)

Example 50 with Jid

use of org.jxmpp.jid.Jid in project Smack by igniterealtime.

the class RosterUtil method ensureSubscribedTo.

public static void ensureSubscribedTo(final XMPPConnection connectionOne, final XMPPConnection connectionTwo, final Date deadline) throws NotLoggedInException, NotConnectedException, InterruptedException, TimeoutException {
    final Roster rosterOne = Roster.getInstanceFor(connectionOne);
    final BareJid jidTwo = connectionTwo.getUser().asBareJid();
    if (rosterOne.iAmSubscribedTo(jidTwo))
        return;
    final BareJid jidOne = connectionOne.getUser().asBareJid();
    final SubscribeListener subscribeListener = new SubscribeListener() {

        @Override
        public SubscribeAnswer processSubscribe(Jid from, Presence subscribeRequest) {
            if (from.equals(jidOne)) {
                return SubscribeAnswer.Approve;
            }
            return null;
        }
    };
    final Roster rosterTwo = Roster.getInstanceFor(connectionTwo);
    rosterTwo.addSubscribeListener(subscribeListener);
    try {
        rosterOne.sendSubscriptionRequest(jidTwo);
        waitUntilOtherEntityIsSubscribed(rosterTwo, jidOne, deadline);
    } finally {
        rosterTwo.removeSubscribeListener(subscribeListener);
    }
}
Also used : Jid(org.jxmpp.jid.Jid) BareJid(org.jxmpp.jid.BareJid) BareJid(org.jxmpp.jid.BareJid) Presence(org.jivesoftware.smack.packet.Presence)

Aggregations

Jid (org.jxmpp.jid.Jid)78 EntityBareJid (org.jxmpp.jid.EntityBareJid)18 ArrayList (java.util.ArrayList)15 HashMap (java.util.HashMap)14 Test (org.junit.Test)14 DomainBareJid (org.jxmpp.jid.DomainBareJid)14 EntityFullJid (org.jxmpp.jid.EntityFullJid)12 BareJid (org.jxmpp.jid.BareJid)11 IQ (org.jivesoftware.smack.packet.IQ)7 Presence (org.jivesoftware.smack.packet.Presence)7 MUCLightBlockingIQ (org.jivesoftware.smackx.muclight.element.MUCLightBlockingIQ)7 SmackException (org.jivesoftware.smack.SmackException)6 Message (org.jivesoftware.smack.packet.Message)6 WeakHashMap (java.util.WeakHashMap)4 XMPPConnection (org.jivesoftware.smack.XMPPConnection)4 Map (java.util.Map)3 SimpleResultSyncPoint (org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint)3 FeatureNotSupportedException (org.jivesoftware.smack.SmackException.FeatureNotSupportedException)3 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)3 Bytestream (org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream)3