Importing and Exporting the UI Configuration

Every option of the messaging UI can be written as JSON, with the same names as in code. The same JSON applies on Android, iOS and Flutter. Uses:

  • One file with the look and features of the app, for all platforms.
  • A configuration sent from the app’s server, to change the UI without a new app release.
  • A look chosen in the Customize screen, saved on the app’s server and restored on the user’s other devices.

Format

The JSON has one object per group. Each object has options of that group, with their names in code (see UI Configuration):

{
  "theme": {"accentColor": "#FF00A884"},
  "userList": {"title": "Chats", "searchMode": "top", "enableArchive": false},
  "messages": {"enableForward": false, "enableKeep": false},
  "messageAppearance": {"showBubbleTail": false, "textSize": "large"},
  "attachments": {"buttonStyle": "plus"},
  "sensitivity": {"tapToViewLevel": 2, "blockScreenshotLevel": 3}
}

Only the options in the JSON change. The other options keep their values.

Option typeIn JSONExample
A switchtrue or false"enableForward": false
A numbera number"maxPhotos": 4
A texta string; null for none where allowed"title": "Chats"
A color"#AARRGGBB" or "#RRGGBB" (opaque)"accentColor": "#FF00A884"
A choice among constantsa word"searchMode": "top", "textSize": "large"
A list of choices (MesiboUiOption)a list of objects: value, and optionally title and detail"sizes": [{"value": 1600, "title": "Standard"}]
A list of texts or colorsa list"reactions": ["👍", "❤️"]

The choices written as words:

OptionWords
userList.searchMode"button", "top", "system", "none"
messageAppearance.textSize"small", "medium", "large", "extra_large"
attachments.buttonStyle"clip", "plus"
mediaPicker.galleryButtonAction"camera", "more_apps", "folders", "none"
The values of userList.filters"all", "unread", "favorites", "groups", "online"
The values of messageOptions.timerStarts and disappearing.timerStarts"sent", "delivered", "read"

A list of choices is replaced as a whole. For example, to offer only two picture sizes:

{
  "imageSending": {
    "sizes": [{"value": 1280, "title": "Standard"}, {"value": 4096, "title": "HD"}],
    "maxDimension": 1280
  },
  "userList": {
    "filters": [{"value": "all", "title": "All"}, {"value": "unread", "title": "Unread"}]
  }
}

The built-in attachment tiles are changed by their type: "gallery", "camera", "video", "document", "audio" or "location". Each can have title, enabled, color, imageColor, backgroundColor and borderColor:

{"attachments": {"tiles": [{"type": "location", "enabled": false}, {"type": "gallery", "color": "#FF00868B"}]}}

Pictures, drawable resources and click handlers are not in JSON. The app sets them in code. The app’s own attachment tiles are also added in code.

Applying a JSON

applyJson applies the options in a JSON. It returns a list of problems, for example an unknown option or a wrong type. Options without problems are applied.

List<String> problems = MesiboUI.getConfig().applyJson(json);
for (String problem : problems)
    Log.w("ui", problem);
val problems = MesiboUI.getConfig().applyJson(json)
problems.forEach { Log.w("ui", it) }
let problems = MesiboUI.getConfig().applyJson(json)
problems.forEach { print($0) }
NSArray<NSString *> *problems = [[MesiboUI getConfig] applyJson:json];
for (NSString *problem in problems)
    NSLog(@"%@", problem);
List<String> problems = await MesiboUI().applyJson(json);
problems.forEach(print);

The open screens are drawn again with the new configuration.

mesibo makes a new configuration each time a theme is applied, so options applied once are lost when the theme changes (see Automatic Theme Changes). An app that follows the system’s light or dark setting, or uses the Customize screen, applies its JSON in MesiboUI_onConfig, which mesibo calls for each new configuration:

@Override
public void MesiboUI_onConfig(MesiboUiConfig config, boolean dark) {
    config.applyJson(dark ? myDarkJson : myLightJson);
}
override fun MesiboUI_onConfig(config: MesiboUiConfig, dark: Boolean) {
    config.applyJson(if (dark) myDarkJson else myLightJson)
}
func MesiboUI_onConfig(config: MesiboUiConfig, dark: Bool) {
    _ = config.applyJson(dark ? myDarkJson : myLightJson)
}
- (void)MesiboUI_onConfig:(MesiboUiConfig *)config dark:(BOOL)dark {
    [config applyJson:dark ? myDarkJson : myLightJson];
}

In Flutter, the options applied with applyJson() or setConfig() are kept, and applied again to each new configuration.

Exporting the configuration

toJson writes the configuration as JSON. toJson(false) writes every option. toJson(true) writes only the options that differ from the defaults of the light theme.

String all = MesiboUI.getConfig().toJson(false);
String changed = MesiboUI.getConfig().toJson(true);
val all = MesiboUI.getConfig().toJson(false)
val changed = MesiboUI.getConfig().toJson(true)
let all = MesiboUI.getConfig().toJson(false)
let changed = MesiboUI.getConfig().toJson(true)
NSString *all = [[MesiboUI getConfig] toJson:NO];
NSString *changed = [[MesiboUI getConfig] toJson:YES];
String all = await MesiboUI().toJson();
String changed = await MesiboUI().toJson(onlyChanged: true);

Customizations

A JSON saved for the light or the dark theme is a customization. mesibo applies it each time that theme is applied. See Customizations.

JSON Schema

jsonSchema returns a JSON Schema of the configuration: every group and option, with its type, its default and its allowed words. Editors such as VS Code use the schema to check a JSON file and to complete the names.

String schema = MesiboUiConfig.jsonSchema();
val schema = MesiboUiConfig.jsonSchema()
let schema = MesiboUiConfig.jsonSchema()
NSString *schema = [MesiboUiConfig jsonSchema];

The schema is saved next to the JSON file, for example as mesibo-ui.schema.json, and named in $schema at the top of the JSON file:

{
  "$schema": "./mesibo-ui.schema.json",
  "userList": {"title": "Chats"}
}

Platform-only options

An option of one platform only, for example the location group of Android, is accepted on all platforms. A platform without the option skips it and reports no problem.