2014-09-11 09:49:16 +02:00
|
|
|
/**
|
|
|
|
*
|
2020-08-15 14:03:57 +02:00
|
|
|
* Copyright © 2014-2020 Florian Schmaus
|
2014-09-11 09:49:16 +02:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2020-08-15 14:03:57 +02:00
|
|
|
package org.jivesoftware.smack.sm.predicates.tcp;
|
2014-09-11 09:49:16 +02:00
|
|
|
|
2015-02-26 18:41:17 +01:00
|
|
|
import org.jivesoftware.smack.filter.StanzaFilter;
|
2015-02-05 11:17:27 +01:00
|
|
|
import org.jivesoftware.smack.packet.Stanza;
|
2014-09-11 09:49:16 +02:00
|
|
|
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
|
|
|
|
import org.jivesoftware.smack.util.StringUtils;
|
|
|
|
|
2015-04-06 10:45:12 +02:00
|
|
|
public final class OnceForThisStanza implements StanzaFilter {
|
2014-09-11 09:49:16 +02:00
|
|
|
|
|
|
|
private final String id;
|
|
|
|
private final XMPPTCPConnection connection;
|
|
|
|
|
2015-02-05 11:17:27 +01:00
|
|
|
public static void setup(XMPPTCPConnection connection, Stanza packet) {
|
2015-02-26 18:41:17 +01:00
|
|
|
StanzaFilter packetFilter = new OnceForThisStanza(connection, packet);
|
2014-09-11 09:49:16 +02:00
|
|
|
connection.addRequestAckPredicate(packetFilter);
|
|
|
|
}
|
|
|
|
|
2015-02-05 11:17:27 +01:00
|
|
|
private OnceForThisStanza(XMPPTCPConnection connection, Stanza packet) {
|
2014-09-11 09:49:16 +02:00
|
|
|
this.connection = connection;
|
2015-02-05 11:17:27 +01:00
|
|
|
this.id = packet.getStanzaId();
|
2014-09-11 09:49:16 +02:00
|
|
|
if (StringUtils.isNullOrEmpty(id)) {
|
|
|
|
throw new IllegalArgumentException("Stanza ID must be set");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-02-05 11:17:27 +01:00
|
|
|
public boolean accept(Stanza packet) {
|
|
|
|
String otherId = packet.getStanzaId();
|
2014-09-11 09:49:16 +02:00
|
|
|
if (StringUtils.isNullOrEmpty(otherId)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (id.equals(otherId)) {
|
|
|
|
connection.removeRequestAckPredicate(this);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|