mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-22 10:37:59 +01:00
Add Forwarded.extractMessagesFrom(Collection<Forwarded>)
This commit is contained in:
parent
f2ea3e0d5b
commit
5ae164f670
1 changed files with 22 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue