Advanced intégration
MQTT Chat can be customized to best suit your application need.

Events Callbacks

MqttChat listeners seen before allow developer to be able to carry out the adequate treatment generally after the action is executed. On the other hand, Events Callbacks allow certain actions to be authorized or not and therefore to make a treatment (local or server side) before deciding authorizing or refusing the execution of certan actions.
MQTT CHAT messenger uses this java class called EventsCallbacks sto handle plugins restriction and customisation.
1
public class EventsCallbacks {
2
3
public EventsCallbacks() {
4
}
5
6
public void onSendingMessage(int toUserId, Message message, AuthorisationCallback authorisationCallback) {
7
authorisationCallback.OK();
8
}
9
10
public void onRemovingFriend(int friendId, AuthorisationCallback authorisationCallback) {
11
authorisationCallback.OK();
12
}
13
14
public void onLockingUser(int userId, AuthorisationCallback authorisationCallback) {
15
authorisationCallback.OK();
16
}
17
18
public void onUnLockingUser(int userId, AuthorisationCallback authorisationCallback) {
19
authorisationCallback.OK();
20
}
21
22
public void onDeletingConversation(int userId, AuthorisationCallback authorisationCallback) {
23
authorisationCallback.OK();
24
}
25
26
public void onAudioCallClick(int userId, AuthorisationCallback authorisationCallback) {
27
authorisationCallback.OK();
28
}
29
30
public void onVideoCallClick(int userId, AuthorisationCallback authorisationCallback) {
31
authorisationCallback.OK();
32
}
33
}
Copied!
And below the abstract AuthorisationCallback class.
1
public abstract class AuthorisationCallback {
2
public AuthorisationCallback() {
3
}
4
5
public abstract void OK();
6
7
public abstract void Cancel(String var1);
8
}
Copied!
As you can see, by default EventsCallbacks class does not apply any restriction when sending messages or establishing audio and video calls between users. This default behaviour can be customised to implement desired restruction that we want implement.
For example, if you want to prohibit the sending of messages to a specific user (userid=10). You can create a custom class CustomEventsCallbacks which extends the parent class EventsCallbacks. Then in onSendingMessage() we make condition on toUserId parameter. see code below:
1
public class CustomEventsCallbacks extends EventsCallbacks {
2
3
private Context mContext;
4
5
public CustomEventsCallbacks(Context mContext) {
6
this.mContext = mContext;
7
}
8
9
public void onSendingMessage(int toUserId, Message message, AuthorisationCallback authorisationCallback) {
10
if(toUserId==10){
11
authorisationCallback.Cancel("You can not send message to this user");
12
}else{
13
authorisationCallback.OK();
14
}
15
}
16
}
Copied!
Finally, d'ont forget
👍
to affect our custom class to MQTT CHAT messenger to override default EventsCallbacks class like below:
1
MqttChat.getInstanavace().setEventsCallbacks(new CustomEventsCallbacks(getApplicationContext()));
Copied!
authorisationCallback.Cancel(String message);
will interrupt the execution of the action and display the message to the user in the same time.

Settings

MQTTChat GUI already offers a basic interface to allow users to change chat settings.
If you want to use gloobal settings or integrate chat settings into your main settings activity. You can proceed as follows:
  1. 1.
    Remove settings button from GUI.
1
MqttChat.getInstance().getMySettings().setShowSettingsIcon(false);
Copied!
2. Change MQTTChat Settings using Code.
  • Enable/Disable sound notifications:
1
MqttChat.getInstance().getMySettings().setSoundAlerts(true);
2
MqttChat.getInstance().getMySettings().isSoundAlerts();
Copied!
  • Enable/Disable Audio calls:
1
MqttChat.getInstance().getMySettings().setAcOk(true);
2
MqttChat.getInstance().getMySettings().isAcOk()
Copied!
  • Enable/Disable Video calls:
1
MqttChat.getInstance().getMySettings().setVcOk(false);
2
MqttChat.getInstance().getMySettings().isVcOk()
Copied!
  • Enable/Disable FCM Notifications :
If true, an android notification will be displayed to the user if a message is received and the app is closed.
1
MqttChat.getInstance().getMySettings().setNotification(true);
2
MqttChat.getInstance().getMySettings().isNotifications();
Copied!
3. Change user status programmatically.
Status can be : Presence.ONLINE or Presence.BUSY. Second parameter can be : null or Callback object.
1
MqttChat.getInstance().getMyPresence().setUserStatus(Presence.ONLINE, null);
Copied!

MQTT Notifications

Before we see how to retrieve and view MQTT notifications. Click here to learn how to send notifications from Server using REST API.
To retrieve MQTT notifications sent from the server to android Application two cases may arise:

Application is on foreground

In this case android application is on foreground and connection with the MQTT server is established.
So you can catch event using MqttChatListener already seen here.
1
MqttChat.getInstance().addChatiListener(new myChatiListener() {
2
@Override
3
public void onReceiveNotification(Notification notification) {
4
/** notification received here **/
5
}
6
});
7
Copied!

Application is closed or in background

If application is closed or application is in background. in this case notification cannot be sent by MQTT and then will be sent with FCM provided FCM feature is enabled.
So you can catch event using MqttChatFCMListener already seen here.
1
MqttChat.getInstance().addMqttchatFCMListener(new MqttChatFCMListener() {
2
@Override
3
public void onReceiveFCMNotification(boolean notificationsSettingEnabled, int toUserId, Notification notification) {
4
/** notification received here **/
5
}
6
});
7
Copied!
notificationsSettinEnabled: indicates whether or not user accepts FCM notifications for offline messages in chat settings. If you want to consider it also to show notifications or you can simply ignore it.
Therefore to receive notifications regardless of the application is in the foreground or closed. it is necessary to implement the two senarios.

Friends feature

Search feature