mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-09 00:59:39 +02:00
Bump Error Prone version to 2.3.4 and fix new bug patterns
This commit is contained in:
parent
1c0bdfae40
commit
d65f2c932e
19 changed files with 499 additions and 585 deletions
|
@ -25,7 +25,6 @@ import org.jivesoftware.smack.AsyncButOrdered;
|
|||
import org.jivesoftware.smack.ConnectionCreationListener;
|
||||
import org.jivesoftware.smack.Manager;
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.StanzaListener;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.XMPPConnectionRegistry;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
|
@ -68,23 +67,20 @@ public final class FallbackIndicationManager extends Manager {
|
|||
private final StanzaFilter fallbackIndicationElementFilter = new AndFilter(StanzaTypeFilter.MESSAGE,
|
||||
new StanzaExtensionFilter(FallbackIndicationElement.ELEMENT, FallbackIndicationElement.NAMESPACE));
|
||||
|
||||
private final StanzaListener fallbackIndicationElementListener = new StanzaListener() {
|
||||
@Override
|
||||
public void processStanza(Stanza packet) {
|
||||
Message message = (Message) packet;
|
||||
FallbackIndicationElement indicator = FallbackIndicationElement.fromMessage(message);
|
||||
String body = message.getBody();
|
||||
asyncButOrdered.performAsyncButOrdered(message.getFrom().asBareJid(), () -> {
|
||||
for (FallbackIndicationListener l : listeners) {
|
||||
l.onFallbackIndicationReceived(message, indicator, body);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
private void fallbackIndicationElementListener(Stanza packet) {
|
||||
Message message = (Message) packet;
|
||||
FallbackIndicationElement indicator = FallbackIndicationElement.fromMessage(message);
|
||||
String body = message.getBody();
|
||||
asyncButOrdered.performAsyncButOrdered(message.getFrom().asBareJid(), () -> {
|
||||
for (FallbackIndicationListener l : listeners) {
|
||||
l.onFallbackIndicationReceived(message, indicator, body);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private FallbackIndicationManager(XMPPConnection connection) {
|
||||
super(connection);
|
||||
connection.addAsyncStanzaListener(fallbackIndicationElementListener, fallbackIndicationElementFilter);
|
||||
connection.addAsyncStanzaListener(this::fallbackIndicationElementListener, fallbackIndicationElementFilter);
|
||||
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(FallbackIndicationElement.NAMESPACE);
|
||||
}
|
||||
|
||||
|
|
|
@ -307,7 +307,9 @@ public final class HttpFileUploadManager extends Manager {
|
|||
public URL uploadFile(InputStream inputStream, String fileName, long fileSize, UploadProgressListener listener) throws XMPPErrorException, InterruptedException, SmackException, IOException {
|
||||
Objects.requireNonNull(inputStream, "Input Stream cannot be null");
|
||||
Objects.requireNonNull(fileName, "Filename Stream cannot be null");
|
||||
Objects.requireNonNull(fileSize, "Filesize Stream cannot be null");
|
||||
if (fileSize < 0) {
|
||||
throw new IllegalArgumentException("File size cannot be negative");
|
||||
}
|
||||
final Slot slot = requestSlot(fileName, fileSize, "application/octet-stream");
|
||||
upload(inputStream, fileSize, slot, listener);
|
||||
return slot.getGetUrl();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2018 Paul Schaub
|
||||
* Copyright 2018 Paul Schaub, 2020 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -29,10 +29,6 @@ import org.jivesoftware.smack.filter.NotFilter;
|
|||
import org.jivesoftware.smack.filter.StanzaExtensionFilter;
|
||||
import org.jivesoftware.smack.filter.StanzaFilter;
|
||||
import org.jivesoftware.smack.filter.ToTypeFilter;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.MessageBuilder;
|
||||
import org.jivesoftware.smack.util.Consumer;
|
||||
import org.jivesoftware.smack.util.Predicate;
|
||||
|
||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||
import org.jivesoftware.smackx.sid.element.OriginIdElement;
|
||||
|
@ -62,14 +58,8 @@ public final class StableUniqueStanzaIdManager extends Manager {
|
|||
// Filter that filters for messages with an origin id
|
||||
private static final StanzaFilter ORIGIN_ID_FILTER = new StanzaExtensionFilter(OriginIdElement.ELEMENT, NAMESPACE);
|
||||
|
||||
// Listener for outgoing stanzas that adds origin-ids to outgoing stanzas.
|
||||
private static final Consumer<MessageBuilder> ADD_ORIGIN_ID_INTERCEPTOR = mb -> OriginIdElement.addOriginId(mb);
|
||||
|
||||
// We need a filter for outgoing messages that do not carry an origin-id already.
|
||||
private static final StanzaFilter ADD_ORIGIN_ID_FILTER = new AndFilter(OUTGOING_FILTER, new NotFilter(ORIGIN_ID_FILTER));
|
||||
private static final Predicate<Message> ADD_ORIGIN_ID_PREDICATE = m -> {
|
||||
return ADD_ORIGIN_ID_FILTER.accept(m);
|
||||
};
|
||||
|
||||
static {
|
||||
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
|
||||
|
@ -113,7 +103,7 @@ public final class StableUniqueStanzaIdManager extends Manager {
|
|||
* Start appending origin-id elements to outgoing stanzas and add the feature to disco.
|
||||
*/
|
||||
public synchronized void enable() {
|
||||
connection().addMessageInterceptor(ADD_ORIGIN_ID_INTERCEPTOR, ADD_ORIGIN_ID_PREDICATE);
|
||||
connection().addMessageInterceptor(OriginIdElement::addTo, ADD_ORIGIN_ID_FILTER::accept);
|
||||
ServiceDiscoveryManager.getInstanceFor(connection()).addFeature(NAMESPACE);
|
||||
}
|
||||
|
||||
|
@ -122,7 +112,7 @@ public final class StableUniqueStanzaIdManager extends Manager {
|
|||
*/
|
||||
public synchronized void disable() {
|
||||
ServiceDiscoveryManager.getInstanceFor(connection()).removeFeature(NAMESPACE);
|
||||
connection().removeMessageInterceptor(ADD_ORIGIN_ID_INTERCEPTOR);
|
||||
connection().removeMessageInterceptor(OriginIdElement::addTo);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -39,7 +39,7 @@ public class OriginIdElement extends StableAndUniqueIdElement {
|
|||
*
|
||||
* @param message message.
|
||||
* @return the added origin-id element.
|
||||
* @deprecated use {@link #addOriginId(MessageBuilder)} instead.
|
||||
* @deprecated use {@link #addTo(MessageBuilder)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
// TODO: Remove in Smack 4.5.
|
||||
|
@ -57,7 +57,7 @@ public class OriginIdElement extends StableAndUniqueIdElement {
|
|||
* @param messageBuilder the message builder to add an origin ID to.
|
||||
* @return the added origin-id element.
|
||||
*/
|
||||
public static OriginIdElement addOriginId(MessageBuilder messageBuilder) {
|
||||
public static OriginIdElement addTo(MessageBuilder messageBuilder) {
|
||||
OriginIdElement originId = new OriginIdElement();
|
||||
messageBuilder.addExtension(originId);
|
||||
// TODO: Find solution to have both the originIds stanzaId and a nice to look at incremental stanzaID.
|
||||
|
|
|
@ -78,7 +78,7 @@ public class StableUniqueStanzaIdTest extends SmackTestSuite {
|
|||
assertFalse(OriginIdElement.hasOriginId(message));
|
||||
assertFalse(StanzaIdElement.hasStanzaId(message));
|
||||
|
||||
OriginIdElement.addOriginId(messageBuilder);
|
||||
OriginIdElement.addTo(messageBuilder);
|
||||
|
||||
message = messageBuilder.build();
|
||||
assertTrue(OriginIdElement.hasOriginId(message));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue