1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-22 14:22:05 +01:00

Add Forwarded.extractMessagesFrom(Collection<Forwarded>)

This commit is contained in:
Florian Schmaus 2018-06-06 08:39:09 +02:00
parent f2ea3e0d5b
commit 5ae164f670

View file

@ -16,7 +16,12 @@
*/
package org.jivesoftware.smackx.forward.packet;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.util.XmlStringBuilder;
@ -112,4 +117,21 @@ public class Forwarded implements ExtensionElement {
public static Forwarded from(Stanza packet) {
return packet.getExtension(ELEMENT, NAMESPACE);
}
/**
* Extract messages in a collection of forwarded elements. Note that it is required that the {@link Forwarded} in
* the given collection only contain {@link Message} stanzas.
*
* @param forwardedCollection the collection to extract from.
* @return a list a the extracted messages.
* @since 4.3.0
*/
public static List<Message> extractMessagesFrom(Collection<Forwarded> forwardedCollection) {
List<Message> res = new ArrayList<>(forwardedCollection.size());
for (Forwarded forwarded : forwardedCollection) {
Message message = (Message) forwarded.forwardedPacket;
res.add(message);
}
return res;
}
}