mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-09 00:59:39 +02:00
Introduce StanzaBuilder
As first step to immutable Stanza types.
This commit is contained in:
parent
926c5892ad
commit
5db6191110
134 changed files with 2576 additions and 764 deletions
|
@ -43,6 +43,7 @@ import org.jivesoftware.smack.XMPPException;
|
|||
import org.jivesoftware.smack.filter.StanzaFilter;
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.MessageBuilder;
|
||||
import org.jivesoftware.smack.packet.Stanza;
|
||||
import org.jivesoftware.smack.util.Async;
|
||||
|
||||
|
@ -491,16 +492,17 @@ public final class OmemoManager extends Manager {
|
|||
throws SmackException.NotLoggedInException, CorruptedOmemoKeyException, InterruptedException,
|
||||
SmackException.NoResponseException, NoSuchAlgorithmException, SmackException.NotConnectedException,
|
||||
CryptoFailedException, CannotEstablishOmemoSessionException, IOException {
|
||||
Message message = new Message();
|
||||
message.setFrom(getOwnJid());
|
||||
message.setTo(recipient.getJid());
|
||||
XMPPConnection connection = connection();
|
||||
MessageBuilder message = connection.getStanzaFactory()
|
||||
.buildMessageStanza()
|
||||
.to(recipient.getJid());
|
||||
|
||||
OmemoElement element = getOmemoService().createRatchetUpdateElement(new LoggedInOmemoManager(this), recipient);
|
||||
message.addExtension(element);
|
||||
|
||||
// Set MAM Storage hint
|
||||
StoreHint.set(message);
|
||||
connection().sendStanza(message);
|
||||
connection.sendStanza(message.build());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.util.HashSet;
|
|||
import java.util.Set;
|
||||
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.MessageBuilder;
|
||||
|
||||
import org.jivesoftware.smackx.eme.element.ExplicitMessageEncryptionElement;
|
||||
import org.jivesoftware.smackx.hints.element.StoreHint;
|
||||
|
@ -123,22 +124,23 @@ public class OmemoMessage {
|
|||
* as well as an optional clear text hint as body, a MAM storage hint
|
||||
* and an EME hint about OMEMO encryption.
|
||||
*
|
||||
* @param messageBuilder a message builder which will be used to build the message.
|
||||
* @param recipient recipient for the to-field of the message.
|
||||
* @return Message TODO javadoc me please
|
||||
* @return the build message.
|
||||
*/
|
||||
public Message asMessage(Jid recipient) {
|
||||
public Message buildMessage(MessageBuilder messageBuilder, Jid recipient) {
|
||||
messageBuilder.ofType(Message.Type.chat).to(recipient);
|
||||
|
||||
Message messageStanza = new Message(recipient, Message.Type.chat);
|
||||
messageStanza.addExtension(getElement());
|
||||
messageBuilder.addExtension(getElement());
|
||||
|
||||
if (OmemoConfiguration.getAddOmemoHintBody()) {
|
||||
messageStanza.setBody(BODY_OMEMO_HINT);
|
||||
messageBuilder.setBody(BODY_OMEMO_HINT);
|
||||
}
|
||||
|
||||
StoreHint.set(messageStanza);
|
||||
messageStanza.addExtension(new ExplicitMessageEncryptionElement(OMEMO_NAMESPACE_V_AXOLOTL, OMEMO));
|
||||
StoreHint.set(messageBuilder);
|
||||
messageBuilder.addExtension(new ExplicitMessageEncryptionElement(OMEMO_NAMESPACE_V_AXOLOTL, OMEMO));
|
||||
|
||||
return messageStanza;
|
||||
return messageBuilder.build();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ import org.jivesoftware.smack.XMPPException;
|
|||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.Stanza;
|
||||
import org.jivesoftware.smack.packet.StanzaError;
|
||||
|
||||
import org.jivesoftware.smackx.carbons.packet.CarbonExtension;
|
||||
import org.jivesoftware.smackx.mam.MamManager;
|
||||
import org.jivesoftware.smackx.muc.MultiUserChat;
|
||||
|
@ -1343,10 +1344,13 @@ public abstract class OmemoService<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey,
|
|||
|
||||
OmemoManager manager = managerGuard.get();
|
||||
OmemoElement ratchetUpdate = createRatchetUpdateElement(managerGuard, contactsDevice);
|
||||
Message m = new Message();
|
||||
m.setTo(contactsDevice.getJid());
|
||||
m.addExtension(ratchetUpdate);
|
||||
manager.getConnection().sendStanza(m);
|
||||
|
||||
XMPPConnection connection = manager.getConnection();
|
||||
Message message = connection.getStanzaFactory().buildMessageStanza()
|
||||
.to(contactsDevice.getJid())
|
||||
.addExtension(ratchetUpdate)
|
||||
.build();
|
||||
connection.sendStanza(message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -27,6 +27,7 @@ import static org.junit.Assert.assertNotNull;
|
|||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
||||
|
||||
import org.jivesoftware.smackx.omemo.element.OmemoElement;
|
||||
import org.jivesoftware.smackx.omemo.exceptions.CryptoFailedException;
|
||||
import org.jivesoftware.smackx.omemo.internal.CipherAndAuthTag;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue