Search in sources :

Example 1 with DataForm

use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.

the class MamManager method pageBefore.

/**
     * Obtain page before the first message saved (specific chat).
     * <p>
     * Note that the messageUid is the XEP-0313 UID and <b>not</> the stanza ID of the message.
     * </p>
     *
     * @param chatJid
     * @param messageUid the UID of the message of which messages before should be received.
     * @param max
     * @return the MAM query result
     * @throws XMPPErrorException
     * @throws NotLoggedInException
     * @throws NotConnectedException
     * @throws InterruptedException
     * @throws NoResponseException
     */
public MamQueryResult pageBefore(Jid chatJid, String messageUid, int max) throws XMPPErrorException, NotLoggedInException, NotConnectedException, InterruptedException, NoResponseException {
    RSMSet rsmSet = new RSMSet(null, messageUid, -1, -1, null, max, null, -1);
    DataForm dataForm = getNewMamForm();
    addWithJid(chatJid, dataForm);
    return page(null, dataForm, rsmSet);
}
Also used : RSMSet(org.jivesoftware.smackx.rsm.packet.RSMSet) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm)

Example 2 with DataForm

use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.

the class MamManager method getNewMamForm.

private static DataForm getNewMamForm() {
    FormField field = new FormField(FormField.FORM_TYPE);
    field.setType(FormField.Type.hidden);
    field.addValue(MamElements.NAMESPACE);
    DataForm form = new DataForm(DataForm.Type.submit);
    form.addField(field);
    return form;
}
Also used : DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) FormField(org.jivesoftware.smackx.xdata.FormField)

Example 3 with DataForm

use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.

the class MamManager method queryArchive.

/**
     * Query an message archive like a MUC archive or a pubsub node archive, addressed by an archiveAddress, applying
     * filters: max count, start date, end date, from/to JID and with additional fields. When archiveAddress is null the
     * default, the server will be requested.
     * 
     * @param node The Pubsub node name, can be null
     * @param max
     * @param start
     * @param end
     * @param withJid
     * @param additionalFields
     * @return the MAM query result
     * @throws NoResponseException
     * @throws XMPPErrorException
     * @throws NotConnectedException
     * @throws InterruptedException
     * @throws NotLoggedInException
     */
public MamQueryResult queryArchive(String node, Integer max, Date start, Date end, Jid withJid, List<FormField> additionalFields) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotLoggedInException {
    DataForm dataForm = null;
    String queryId = UUID.randomUUID().toString();
    if (start != null || end != null || withJid != null || additionalFields != null) {
        dataForm = getNewMamForm();
        addStart(start, dataForm);
        addEnd(end, dataForm);
        addWithJid(withJid, dataForm);
        addAdditionalFields(additionalFields, dataForm);
    }
    MamQueryIQ mamQueryIQ = new MamQueryIQ(queryId, node, dataForm);
    mamQueryIQ.setType(IQ.Type.set);
    mamQueryIQ.setTo(archiveAddress);
    addResultsLimit(max, mamQueryIQ);
    return queryArchive(mamQueryIQ);
}
Also used : DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) MamQueryIQ(org.jivesoftware.smackx.mam.element.MamQueryIQ)

Example 4 with DataForm

use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.

the class MamQueryIQProvider method parse.

@Override
public MamQueryIQ parse(XmlPullParser parser, int initialDepth) throws Exception {
    DataForm dataForm = null;
    String queryId = parser.getAttributeValue("", "queryid");
    String node = parser.getAttributeValue("", "node");
    outerloop: while (true) {
        final int eventType = parser.next();
        final String name = parser.getName();
        switch(eventType) {
            case XmlPullParser.START_TAG:
                switch(name) {
                    case DataForm.ELEMENT:
                        dataForm = DataFormProvider.INSTANCE.parse(parser);
                        break;
                }
                break;
            case XmlPullParser.END_TAG:
                if (parser.getDepth() == initialDepth) {
                    break outerloop;
                }
                break;
        }
    }
    return new MamQueryIQ(queryId, node, dataForm);
}
Also used : DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) MamQueryIQ(org.jivesoftware.smackx.mam.element.MamQueryIQ)

Example 5 with DataForm

use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.

the class Workgroup method joinQueue.

/**
     * <p>Joins the workgroup queue to wait to be routed to an agent. After joining
     * the queue, queue status events will be sent to indicate the user's position and
     * estimated time left in the queue. Once joining the queue, there are three ways
     * the user can leave the queue: <ul>
     * <p/>
     * <li>The user is routed to an agent, which triggers a GroupChat invitation.
     * <li>The user asks to leave the queue by calling the {@link #departQueue} method.
     * <li>A server error occurs, or an administrator explicitly removes the user
     * from the queue.
     * </ul>
     * <p/>
     * A user cannot request to join the queue again if already in the queue. Therefore,
     * this method will throw an IllegalStateException if the user is already in the queue.<p>
     * <p/>
     * Some servers may be configured to require certain meta-data in order to
     * join the queue.<p>
     * <p/>
     * The server tracks the conversations that a user has with agents over time. By
     * default, that tracking is done using the user's JID. However, this is not always
     * possible. For example, when the user is logged in anonymously using a web client.
     * In that case the user ID might be a randomly generated value put into a persistent
     * cookie or a username obtained via the session. When specified, that userID will
     * be used instead of the user's JID to track conversations. The server will ignore a
     * manually specified userID if the user's connection to the server is not anonymous.
     *
     * @param metadata metadata to create a dataform from.
     * @param userID   String that represents the ID of the user when using anonymous sessions
     *                 or <tt>null</tt> if a userID should not be used.
     * @throws XMPPException if an error occured joining the queue. An error may indicate
     *                       that a connection failure occured or that the server explicitly rejected the
     *                       request to join the queue.
     * @throws SmackException 
     * @throws InterruptedException 
     */
public void joinQueue(Map<String, Object> metadata, Jid userID) throws XMPPException, SmackException, InterruptedException {
    // If already in the queue ignore the join request.
    if (inQueue) {
        throw new IllegalStateException("Already in queue " + workgroupJID);
    }
    // Build dataform from metadata
    Form form = new Form(DataForm.Type.submit);
    Iterator<String> iter = metadata.keySet().iterator();
    while (iter.hasNext()) {
        String name = iter.next();
        String value = metadata.get(name).toString();
        FormField field = new FormField(name);
        field.setType(FormField.Type.text_single);
        form.addField(field);
        form.setAnswer(name, value);
    }
    joinQueue(form, userID);
}
Also used : DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) WorkgroupForm(org.jivesoftware.smackx.workgroup.ext.forms.WorkgroupForm) Form(org.jivesoftware.smackx.xdata.Form) FormField(org.jivesoftware.smackx.xdata.FormField)

Aggregations

DataForm (org.jivesoftware.smackx.xdata.packet.DataForm)65 FormField (org.jivesoftware.smackx.xdata.FormField)23 Test (org.junit.jupiter.api.Test)13 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)12 Feature (com.xabber.xmpp.ssn.Feature)7 MamQueryIQ (org.jivesoftware.smackx.mam.element.MamQueryIQ)7 Date (java.util.Date)5 MamQueryArgs (org.jivesoftware.smackx.mam.MamManager.MamQueryArgs)5 OtrMode (com.xabber.xmpp.archive.OtrMode)4 LoggingValue (com.xabber.xmpp.ssn.LoggingValue)4 ArrayList (java.util.ArrayList)4 TreeSet (java.util.TreeSet)4 FillableForm (org.jivesoftware.smackx.xdata.form.FillableForm)4 LinkedList (java.util.LinkedList)3 IQ (org.jivesoftware.smack.packet.IQ)3 XmlPullParser (org.jivesoftware.smack.xml.XmlPullParser)3 Identity (org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity)3 DiscoverInfoBuilder (org.jivesoftware.smackx.disco.packet.DiscoverInfoBuilder)3 Form (org.jivesoftware.smackx.xdata.form.Form)3 DisclosureValue (com.xabber.xmpp.ssn.DisclosureValue)2