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; 023import org.jivesoftware.smackx.forward.packet.Forwarded; 024import org.jivesoftware.smackx.rsm.packet.RSMSet; 025import org.jivesoftware.smackx.xdata.packet.DataForm; 026 027import org.jxmpp.jid.Jid; 028 029/** 030 * Factory that creates MAM objects. 031 * 032 * @since 4.5.0 033 */ 034public interface MamElementFactory { 035 036 /** 037 * Creates a new {@link MamElementFactory} for the parser based on the namespace of the parser. 038 * @param parser the XML parser to retrieve the MAM namespace from 039 * @return the factory suitable for the MAM namespace 040 */ 041 static MamElementFactory forParser(XmlPullParser parser) { 042 String namespace = parser.getNamespace(); 043 return MamVersion.fromNamespace(namespace).newElementFactory(); 044 } 045 046 /** 047 * Create a MAM result extension class. 048 * 049 * @param queryId id of the query 050 * @param id the message's archive UID 051 * @param forwarded the original message as it was received 052 * @return the result extension 053 */ 054 MamElements.MamResultExtension newResultExtension(String queryId, String id, Forwarded<Message> forwarded); 055 056 /** 057 * Create a MAM fin IQ class. 058 * 059 * @param queryId id of the query 060 * @param rsmSet the RSM set included in the {@code <fin/>} 061 * @param complete true if the results returned by the server are complete (no further paging in needed) 062 * @param stable false if the results returned by the sever are unstable (e.g. they might later change in sequence or content) 063 * @return the fin IQ 064 */ 065 MamFinIQ newFinIQ(String queryId, RSMSet rsmSet, boolean complete, boolean stable); 066 067 /** 068 * Create a new MAM preferences IQ. 069 * 070 * @param alwaysJids JIDs for which all messages are archived by default 071 * @param neverJids JIDs for which messages are never archived 072 * @param defaultBehavior default archive behavior 073 * @return the prefs IQ 074 */ 075 MamPrefsIQ newPrefsIQ(List<Jid> alwaysJids, List<Jid> neverJids, MamPrefsIQ.DefaultBehavior defaultBehavior); 076 077 /** 078 * Construct a new MAM {@code <prefs/>} IQ retrieval request (IQ type 'get'). 079 * 080 * @return the prefs IQ 081 */ 082 MamPrefsIQ newPrefsIQ(); 083 084 /** 085 * Create a new MAM Query IQ. 086 * 087 * @param queryId id of the query 088 * @param node pubsub node id when querying a pubsub node, null when not querying a pubsub node 089 * @param dataForm the dataform containing the query parameters 090 * @return the query IQ 091 */ 092 MamQueryIQ newQueryIQ(String queryId, String node, DataForm dataForm); 093 094}