Using Messaging UI Module

The messaging UI module has ready-to-use chat screens. The screens, options and names are the same on Android, iOS and Flutter. Where a platform differs, it is mentioned.

There are two main screens in the messaging UI module.

1. Messaging Screen

The messaging screen shows all the messages with a user or a group, and lets the user send and receive:

  • Text and Rich messages with timestamp and status (send, read, delivered, etc.)
  • Pictures, videos, documents, voice messages and other files
  • Locations
  • Link previews
  • Replies, forwarded and edited messages, and reactions
  • Pictures edited with the built-in photo editor
  • Presence information such as Typing indicator, the online status, etc.

2. User List Screen

The user list screen shows a list of users and groups, and opens the messaging screen when one is tapped. It is usually the main screen of the messaging part of the app or even a main screen. It has several modes, set in MesiboUserListScreenOptions:

ModeAndroidiOSDescription
MessagesMesiboUI.MODE_MESSAGESMESIBO_MODE_MESSAGESThe latest message of each user or group, newest first. Usually the main screen.
ContactsMesiboUI.MODE_CONTACTSMESIBO_MODE_CONTACTSA list of users to start a chat with.
ForwardMesiboUI.MODE_FORWARDMESIBO_MODE_FORWARDA list of users and groups to forward messages to.
GroupsMesiboUI.MODE_GROUPSMESIBO_MODE_GROUPSSelect members and create a group.
Edit groupMesiboUI.MODE_EDITGROUPMESIBO_MODE_EDITGROUPAdd members to a group (groupid).

Using the Messaging UI Module

Install the messaging UI by following the instructions for Android, iOS or Flutter. Then import it:

import com.mesibo.messaging.MesiboUI;
import com.mesibo.messaging.MesiboUiConfig;
import com.mesibo.messaging.MesiboUI
import com.mesibo.messaging.MesiboUiConfig
import MesiboUI
#import <mesiboui/MesiboUI.h>
import 'package:mesibo/mesibo.dart';

Launching the screens

Open the chat list:

MesiboUI.MesiboUserListScreenOptions opts = new MesiboUI.MesiboUserListScreenOptions();
MesiboUI.launchUserList(context, opts);
val opts = MesiboUI.MesiboUserListScreenOptions()
MesiboUI.launchUserList(context, opts)
let opts = MesiboUserListScreenOptions()
MesiboUI.launchUserList(self, opts: opts)
MesiboUserListScreenOptions *opts = [MesiboUserListScreenOptions new];
[MesiboUI launchUserList:self opts:opts];
MesiboUI().launchUserList();

On Android and in Flutter, set keepRunning when the chat list is the app’s main screen: the back button then sends the app to the background instead of closing the list.

Open a chat with a user or a group:

MesiboUI.MesiboMessageScreenOptions opts = new MesiboUI.MesiboMessageScreenOptions();
opts.profile = Mesibo.getProfile("+15675551234");   // a group: Mesibo.getProfile(groupId)
MesiboUI.launchMessaging(context, opts);
val opts = MesiboUI.MesiboMessageScreenOptions()
opts.profile = Mesibo.getProfile("+15675551234")   // a group: Mesibo.getProfile(groupId)
MesiboUI.launchMessaging(context, opts)
let opts = MesiboMessageScreenOptions()
opts.profile = MesiboProfile.getProfile("+15675551234")   // a group: MesiboProfile.getGroupProfile(groupId)
MesiboUI.launchMessaging(self, opts: opts)
MesiboMessageScreenOptions *opts = [MesiboMessageScreenOptions new];
opts.profile = [MesiboProfile getProfile:@"+15675551234"];   // a group: [MesiboProfile getGroupProfile:groupId]
[MesiboUI launchMessaging:self opts:opts];
MesiboProfile profile = await Mesibo().getUserProfile("+15675551234");   // a group: getGroupProfile(groupId)
MesiboUI().launchMessaging(profile);

On iOS, a screen is pushed when the parent is in a navigation controller, and presented otherwise.

Set opts.readOnly to show a chat without the message input, for example for a channel that only sends announcements.

Other screens

These functions open the other screens, with the same names on Android and iOS:

ScreenAndroid and iOSFlutter
Pick users to forward messages (by id) or a text tolaunchForwardActivitylaunchForwardMessages, launchForwardText
Select members and create a grouplaunchCreateGrouplaunchCreateGroup
Add members to a grouplaunchEditGrouplaunchEditGroup
Edit the user profile: name, status and pictureslaunchEditProfilelaunchEditProfile
The profile of a user or a groupshowProfileshowBasicProfileInfo
The small profile popup, with Message and Info buttonsshowProfilePopupshowProfilePopup
End-to-end encryption: of a chat, or the app’s own screen to turn it on or offshowEndToEndEncryptionInfoshowEndToEndEncryptionInfo
Disappearing messages of a chat: how long its messages livelaunchDisappearingMessageslaunchDisappearingMessages
The look of the messaging UI for the light or dark theme, see Customize screenlaunchCustomizelaunchCustomize

showEndToEndEncryptionInfo takes a profile on iOS and in Flutter (nil / null for the app’s own screen). On Android it takes the address and group id of the chat; the app’s own screen is showEndToEndEncryptionInfoForSelf.

The look itself is set with setTheme (light, dark or the system’s), and saveCustomization, getCustomization and applyCustomization for a saved look of each theme, see Light and dark theme and Customizations.

Modes of the user list

Set the mode and its options in MesiboUserListScreenOptions:

MesiboUI.MesiboUserListScreenOptions opts = new MesiboUI.MesiboUserListScreenOptions();

// contacts
opts.mode = MesiboUI.MODE_CONTACTS;

// forward messages or a text
opts.mode = MesiboUI.MODE_FORWARD;
opts.forwardIds = new long[] { messageId };   // the messages to forward, or
opts.forwardedMessage = "Hello";              // a text to forward
opts.forwardAndClose = true;                  // close the list after forwarding

// create a group
opts.mode = MesiboUI.MODE_GROUPS;

// add members to a group
opts.mode = MesiboUI.MODE_EDITGROUP;
opts.groupid = groupId;
val opts = MesiboUI.MesiboUserListScreenOptions()

// contacts
opts.mode = MesiboUI.MODE_CONTACTS

// forward messages or a text
opts.mode = MesiboUI.MODE_FORWARD
opts.forwardIds = longArrayOf(messageId)   // the messages to forward, or
opts.forwardedMessage = "Hello"            // a text to forward
opts.forwardAndClose = true                // close the list after forwarding

// create a group
opts.mode = MesiboUI.MODE_GROUPS

// add members to a group
opts.mode = MesiboUI.MODE_EDITGROUP
opts.groupid = groupId
let opts = MesiboUserListScreenOptions()

// contacts
opts.mode = MESIBO_MODE_CONTACTS

// forward messages or a text
opts.mode = MESIBO_MODE_FORWARD
opts.forwardIds = [NSNumber(value: messageId)]   // the messages to forward, or
opts.forwardedMessage = "Hello"                  // a text to forward
opts.forwardAndClose = true                      // close the list after forwarding

// create a group
opts.mode = MESIBO_MODE_GROUPS

// add members to a group
opts.mode = MESIBO_MODE_EDITGROUP
opts.groupid = groupId
MesiboUserListScreenOptions *opts = [MesiboUserListScreenOptions new];

// contacts
opts.mode = MESIBO_MODE_CONTACTS;

// forward messages or a text
opts.mode = MESIBO_MODE_FORWARD;
opts.forwardIds = @[@(messageId)];     // the messages to forward, or
opts.forwardedMessage = @"Hello";      // a text to forward
opts.forwardAndClose = YES;            // close the list after forwarding

// create a group
opts.mode = MESIBO_MODE_GROUPS;

// add members to a group
opts.mode = MESIBO_MODE_EDITGROUP;
opts.groupid = groupId;
// forward messages or a text
MesiboUI().launchForwardMessages([messageId], false);   // false: open the chat when forwarding to one user
MesiboUI().launchForwardText("Hello", true);             // true: close the list after forwarding

// create a group
MesiboUI().launchCreateGroup();

// add members to a group
MesiboUI().launchEditGroup(groupId);

Embedding the screens

Instead of launching the screens, the app can embed them in its own screens, with the same options: fragments on Android, and view controllers on iOS. In Flutter, the screens are always launched.

public class ChatsActivity extends MesiboBaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chats);

        // the chat list
        MesiboUI.MesiboUserListScreenOptions opts = new MesiboUI.MesiboUserListScreenOptions();
        opts.mode = MesiboUI.MODE_MESSAGES;

        MesiboUserListFragment fragment = new MesiboUserListFragment();
        fragment.setOptions(opts);

        getSupportFragmentManager().beginTransaction()
                .replace(R.id.fragment_container, fragment)
                .commit();
    }
}
class ChatsActivity : MesiboBaseActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_chats)

        // the chat list
        val opts = MesiboUI.MesiboUserListScreenOptions()
        opts.mode = MesiboUI.MODE_MESSAGES

        val fragment = MesiboUserListFragment()
        fragment.setOptions(opts)

        supportFragmentManager.beginTransaction()
            .replace(R.id.fragment_container, fragment)
            .commit()
    }
}
// the chat list
let opts = MesiboUserListScreenOptions()
let list = MesiboUI.getUserListViewController(opts)
navigationController?.pushViewController(list, animated: true)

// a chat
let chatOpts = MesiboMessageScreenOptions()
chatOpts.profile = profile
if let chat = MesiboUI.getMessageViewController(chatOpts) {
    navigationController?.pushViewController(chat, animated: true)
}
// the chat list
MesiboUserListScreenOptions *opts = [MesiboUserListScreenOptions new];
UIViewController *list = [MesiboUI getUserListViewController:opts];
[self.navigationController pushViewController:list animated:YES];

// a chat
MesiboMessageScreenOptions *chatOpts = [MesiboMessageScreenOptions new];
chatOpts.profile = profile;
UIViewController *chat = [MesiboUI getMessageViewController:chatOpts];
if (chat)
    [self.navigationController pushViewController:chat animated:YES];

On Android, a chat is a MesiboMessagingFragment with MesiboMessageScreenOptions, the same way. MesiboBaseActivity keeps the content clear of the system bars and the keyboard, and passes activity results and the back button to the fragment (the messaging fragment uses them for attachments). An activity that does not extend MesiboBaseActivity must do the same.

For complete apps using the messaging UI, see the First App for Android, iOS and Flutter (the example app of the mesibo package).

Customizing the UI describes adding buttons and menu items, handling actions, and changing how messages are shown. All the texts, colors and options are in Messaging UI Settings.