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);
}
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()));
}
}
}
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);
}
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());
}
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);
}
}
Aggregations