mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-12-09 04:21:08 +01:00
[xdata] Ensure that hidden FROM_TYPE field is first
This commit is contained in:
parent
687c4f35aa
commit
33f59fd7ed
2 changed files with 37 additions and 0 deletions
|
|
@ -100,6 +100,9 @@ public final class DataForm implements ExtensionElement {
|
|||
instructions = CollectionUtil.cloneAndSeal(builder.instructions);
|
||||
reportedData = builder.reportedData;
|
||||
items = CollectionUtil.cloneAndSeal(builder.items);
|
||||
|
||||
builder.orderFields();
|
||||
|
||||
fields = CollectionUtil.cloneAndSeal(builder.fields);
|
||||
fieldsMap = CollectionUtil.cloneAndSeal(builder.fieldsMap);
|
||||
extensionElements = CollectionUtil.cloneAndSeal(builder.extensionElements);
|
||||
|
|
@ -382,6 +385,30 @@ public final class DataForm implements ExtensionElement {
|
|||
extensionElements = CollectionUtil.newListWith(dataForm.getExtensionElements());
|
||||
}
|
||||
|
||||
private void orderFields() {
|
||||
Iterator<FormField> it = fields.iterator();
|
||||
if (!it.hasNext()) {
|
||||
return;
|
||||
}
|
||||
|
||||
FormField hiddenFormTypeField = it.next().asHiddenFormTypeFieldIfPossible();
|
||||
if (hiddenFormTypeField != null) {
|
||||
// The hidden FROM_TYPE field is already in first position, nothing to do.
|
||||
return;
|
||||
}
|
||||
|
||||
while (it.hasNext()) {
|
||||
hiddenFormTypeField = it.next().asHiddenFormTypeFieldIfPossible();
|
||||
if (hiddenFormTypeField != null) {
|
||||
// Remove the hidden FORM_TYPE field that is not on first position.
|
||||
it.remove();
|
||||
// And insert it again at first position.
|
||||
fields.add(0, hiddenFormTypeField);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated do not use.
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue