001/**
002 *
003 * Copyright 2020 Florian Schmaus
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.pubsub.form;
018
019import java.util.Collection;
020import java.util.Date;
021
022import org.jivesoftware.smackx.pubsub.PresenceState;
023import org.jivesoftware.smackx.pubsub.SubscribeOptionFields;
024import org.jivesoftware.smackx.xdata.FormField;
025import org.jivesoftware.smackx.xdata.ListMultiFormField;
026import org.jivesoftware.smackx.xdata.form.FillableForm;
027import org.jivesoftware.smackx.xdata.packet.DataForm;
028
029public class FillableSubscribeForm extends FillableForm implements SubscribeFormReader {
030
031    FillableSubscribeForm(DataForm dataForm) {
032        super(dataForm);
033    }
034
035    /**
036     * Sets whether an entity wants to receive notifications.
037     *
038     * @param deliverNotifications TODO javadoc me please
039     */
040    public void setDeliverOn(boolean deliverNotifications) {
041        writeBoolean(SubscribeOptionFields.deliver.getFieldName(), deliverNotifications);
042    }
043
044    /**
045     * Sets whether notifications should be delivered as aggregations or not.
046     *
047     * @param digestOn true to aggregate, false otherwise
048     */
049    public void setDigestOn(boolean digestOn) {
050        writeBoolean(SubscribeOptionFields.digest.getFieldName(), digestOn);
051    }
052
053    /**
054     * Sets the minimum number of milliseconds between sending notification digests.
055     *
056     * @param frequency The frequency in milliseconds
057     */
058    public void setDigestFrequency(int frequency) {
059        write(SubscribeOptionFields.digest_frequency.getFieldName(), frequency);
060    }
061
062    /**
063     * Sets the time at which the leased subscription will expire, or has expired.
064     *
065     * @param expire The expiry date
066     */
067    public void setExpiry(Date expire) {
068        write(SubscribeOptionFields.expire.getFieldName(), expire);
069    }
070
071    /**
072     * Sets whether the entity wants to receive an XMPP message body in
073     * addition to the payload format.
074     *
075     * @param include true to receive the message body, false otherwise
076     */
077    public void setIncludeBody(boolean include) {
078        writeBoolean(SubscribeOptionFields.include_body.getFieldName(), include);
079    }
080
081    /**
082     * Sets the list of {@link PresenceState} for which an entity wants
083     * to receive notifications.
084     *
085     * @param stateValues The list of states
086     */
087    public void setShowValues(Collection<PresenceState> stateValues) {
088        ListMultiFormField.Builder builder = FormField.listMultiBuilder(SubscribeOptionFields.show_values.getFieldName());
089        for (PresenceState state : stateValues) {
090            builder.addValue(state.toString());
091        }
092
093        write(builder.build());
094    }
095}