use of org.jivesoftware.smack.packet.MessageBuilder in project Smack by igniterealtime.
the class ChatConnectionTest method validateMessageTypeWithNoNormal1.
@Test
public void validateMessageTypeWithNoNormal1() {
cm.setNormalIncluded(false);
MessageBuilder incomingChat = createChatPacket("134", true);
incomingChat.ofType(Message.Type.chat);
processServerMessage(incomingChat.build());
assertNotNull(listener.getNewChat());
}
use of org.jivesoftware.smack.packet.MessageBuilder in project Smack by igniterealtime.
the class MultiUserChat method changeSubject.
/**
* Changes the subject within the room. As a default, only users with a role of "moderator"
* are allowed to change the subject in a room. Although some rooms may be configured to
* allow a mere participant or even a visitor to change the subject.
*
* @param subject the new room's subject to set.
* @throws XMPPErrorException if someone without appropriate privileges attempts to change the
* room subject will throw an error with code 403 (i.e. Forbidden)
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException if the XMPP connection is not connected.
* @throws InterruptedException if the calling thread was interrupted.
*/
public void changeSubject(final String subject) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MessageBuilder message = buildMessage();
message.setSubject(subject);
// Wait for an error or confirmation message back from the server.
StanzaFilter responseFilter = new AndFilter(fromRoomGroupchatFilter, new StanzaFilter() {
@Override
public boolean accept(Stanza packet) {
Message msg = (Message) packet;
return subject.equals(msg.getSubject());
}
});
StanzaCollector response = connection.createStanzaCollectorAndSend(responseFilter, message.build());
// Wait up to a certain number of seconds for a reply.
response.nextResultOrThrow();
}
use of org.jivesoftware.smack.packet.MessageBuilder in project Smack by igniterealtime.
the class OmemoClient method handleInput.
public void handleInput(String input) throws NotConnectedException, NotLoggedInException, InterruptedException, IOException {
String[] com = input.split(" ", 3);
switch(com[0]) {
case "/omemo":
if (com.length < 3) {
print("Usage: /omemo <contact-jid> <message>");
return;
}
BareJid recipient = JidCreate.bareFrom(com[1]);
String body = com[2];
MessageBuilder messageBuilder = connection.getStanzaFactory().buildMessageStanza();
try {
Message omemoMessage = omemoManager.encrypt(recipient, body).buildMessage(messageBuilder, recipient);
connection.sendStanza(omemoMessage);
} catch (UndecidedOmemoIdentityException e) {
print("Undecided Identities!\n" + Arrays.toString(e.getUndecidedDevices().toArray()));
} catch (CryptoFailedException | SmackException.NoResponseException e) {
LOGGER.log(Level.SEVERE, "Unexpected Exception", e);
}
break;
case "/trust":
print("Trust");
if (com.length != 2) {
print("Usage: /trust <contact-jid>");
}
BareJid contact = JidCreate.bareFrom(com[1]);
HashMap<OmemoDevice, OmemoFingerprint> devices;
try {
devices = omemoManager.getActiveFingerprints(contact);
} catch (CorruptedOmemoKeyException | CannotEstablishOmemoSessionException | SmackException.NoResponseException e) {
LOGGER.log(Level.SEVERE, "Unexpected Exception", e);
return;
}
for (OmemoDevice d : devices.keySet()) {
print("Trust (1) or distrust (2)?\n" + devices.get(d).blocksOf8Chars());
if (Integer.parseInt(scanner.nextLine()) == 1) {
omemoManager.trustOmemoIdentity(d, devices.get(d));
} else {
omemoManager.distrustOmemoIdentity(d, devices.get(d));
}
}
print("Done.");
break;
case "/purge":
try {
omemoManager.purgeDeviceList();
print("Purged.");
} catch (XMPPException.XMPPErrorException | SmackException.NoResponseException | PubSubException.NotALeafNodeException e) {
LOGGER.log(Level.SEVERE, "Unexpected Exception", e);
}
}
}
use of org.jivesoftware.smack.packet.MessageBuilder in project Smack by igniterealtime.
the class OXInstantMessagingManager method sendOxMessage.
/**
* Send an OX message to a {@link OpenPgpContact}. The message will be encrypted to all active keys of the contact,
* as well as all of our active keys. The message is also signed with our key.
*
* @param contact contact capable of OpenPGP for XMPP: Instant Messaging.
* @param body message body.
*
* @return {@link EncryptionResult} containing metadata about the messages encryption + signatures.
*
* @throws InterruptedException if the thread is interrupted
* @throws IOException IO is dangerous
* @throws SmackException.NotConnectedException if we are not connected
* @throws SmackException.NotLoggedInException if we are not logged in
* @throws PGPException PGP is brittle
*/
public EncryptionResult sendOxMessage(OpenPgpContact contact, CharSequence body) throws InterruptedException, IOException, SmackException.NotConnectedException, SmackException.NotLoggedInException, PGPException {
MessageBuilder messageBuilder = connection().getStanzaFactory().buildMessageStanza().to(contact.getJid());
Message.Body mBody = new Message.Body(null, body.toString());
EncryptionResult metadata = addOxMessage(messageBuilder, contact, Collections.<ExtensionElement>singletonList(mBody));
Message message = messageBuilder.build();
ChatManager.getInstanceFor(connection()).chatWith(contact.getJid().asEntityBareJidIfPossible()).send(message);
return metadata;
}
Aggregations