powered by Jive Software

Smack 4.4.0-alpha3: Room configuration sends Boolean value as 'true' or 'false' in submit form

Please refer to
Example 166.** Service Sends Configuration Form to Owner

The Form.setAnswer(String, boolean) will create a submit FormField with <value/> set to ‘true’ or ‘false’. It seems that some xmpp server e.g. ejabberd accepts only ‘1’ or ‘0’ as boolean, otherwise it just ignore the FormField configuration change requested.

Since setAnswer() checks the submit value type against the configuration field.getType(), app is unable to override the Form class setAnswer with ‘1’ and ‘0’ for boolean.

=========== smack Form class ==========

    public void setAnswer(String variable, boolean value) {
        FormField field = getField(variable);
        if (field == null) {
            throw new IllegalArgumentException("Field not found for the specified variable name.");
        }
        if (field.getType() != FormField.Type.bool) {
            throw new IllegalArgumentException("This field is not of type boolean.");
        }
        setAnswer(field, Boolean.toString(value));
    }
======= debug log capture on aTalk =========
2020-03-27 13:19:15.365 4865-5015/org.atalk.android D/SMACK: SENT (0): 
    <iq to='chatroom-gk3v@conference.atalk.sytes.net' id='W2VK6-148' type='set'>
      <query xmlns='http://jabber.org/protocol/muc#owner'>
        <x xmlns='jabber:x:data' type='submit'>
          <field var='FORM_TYPE' type='hidden'>
            <value>
              http://jabber.org/protocol/muc#roomconfig
            </value>
          </field>
          <field var='muc#roomconfig_publicroom' type='boolean'>
            <value>
              false
            </value>
          </field>
          <field var='public_list' type='boolean'>
            <value>
              true
            </value>
          </field>
          <field var='muc#roomconfig_maxusers' type='list-single'>
            <value>
              100
            </value>
          </field>
          <field var='muc#roomconfig_whois' type='list-single'>
            <value>
              anyone
            </value>
          </field>
          <field var='muc#roomconfig_presencebroadcast' type='list-multi'>
            <value>
              moderator
            </value>
            <value>
              participant
            </value>
            <value>
              visitor
            </value>
          </field>
          <field var='allow_private_messages_from_visitors' type='list-single'>
            <value>
              anyone
            </value>
          </field>
        </x>
      </query>
    </iq>

Further investigation invalidate my observation. The ejabberd server does accept true and false as value.
It is aTalk problem; When displaying the checkBox state i.e. need to convert value “1” and "0’ to Boolean true and false before setting the checkBox for display.

See note #10 in XEP-0004: https://xmpp.org/extensions/xep-0004.html#nt-idm45541347586784

1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.