001/**
002 *
003 * Copyright © 2016-2021 Florian Schmaus and Frank Matheron
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.jivesoftware.smackx.mam.element;
018
019import java.util.List;
020
021import org.jivesoftware.smack.packet.Message;
022import org.jivesoftware.smack.xml.XmlPullParser;
023
024import org.jivesoftware.smackx.forward.packet.Forwarded;
025import org.jivesoftware.smackx.rsm.packet.RSMSet;
026import org.jivesoftware.smackx.xdata.packet.DataForm;
027
028import org.jxmpp.jid.Jid;
029
030/**
031 * Factory that creates MAM objects.
032 *
033 * @since 4.5.0
034 */
035public interface MamElementFactory {
036
037    /**
038     * Creates a new {@link MamElementFactory} for the parser based on the namespace of the parser.
039     * @param parser the XML parser to retrieve the MAM namespace from
040     * @return the factory suitable for the MAM namespace
041     */
042    static MamElementFactory forParser(XmlPullParser parser) {
043        String namespace = parser.getNamespace();
044        return MamVersion.fromNamespace(namespace).newElementFactory();
045    }
046
047    /**
048     * Create a MAM result extension class.
049     *
050     * @param queryId id of the query
051     * @param id the message's archive UID
052     * @param forwarded the original message as it was received
053     * @return the result extension
054     */
055    MamElements.MamResultExtension newResultExtension(String queryId, String id, Forwarded<Message> forwarded);
056
057    /**
058     * Create a MAM fin IQ class.
059     *
060     * @param queryId id of the query
061     * @param rsmSet the RSM set included in the {@code <fin/>}
062     * @param complete true if the results returned by the server are complete (no further paging in needed)
063     * @param stable false if the results returned by the sever are unstable (e.g. they might later change in sequence or content)
064     * @return the fin IQ
065     */
066    MamFinIQ newFinIQ(String queryId, RSMSet rsmSet, boolean complete, boolean stable);
067
068    /**
069     * Create a new MAM preferences IQ.
070     *
071     * @param alwaysJids JIDs for which all messages are archived by default
072     * @param neverJids JIDs for which messages are never archived
073     * @param defaultBehavior default archive behavior
074     * @return the prefs IQ
075     */
076    MamPrefsIQ newPrefsIQ(List<Jid> alwaysJids, List<Jid> neverJids, MamPrefsIQ.DefaultBehavior defaultBehavior);
077
078    /**
079     * Construct a new MAM {@code <prefs/>} IQ retrieval request (IQ type 'get').
080     *
081     * @return the prefs IQ
082     */
083    MamPrefsIQ newPrefsIQ();
084
085    /**
086     * Create a new MAM Query IQ.
087     *
088     * @param queryId id of the query
089     * @param node pubsub node id when querying a pubsub node, null when not querying a pubsub node
090     * @param dataForm the dataform containing the query parameters
091     * @return the query IQ
092     */
093    MamQueryIQ newQueryIQ(String queryId, String node, DataForm dataForm);
094
095}