Chat events

Events Litener.
Interaction with library is possible essentially through three listeners: MqttChatListener, MqttChatUiListener and MqttChatFCMListener.
MqttChatListener and MqttChatUiListener events : are called when application is in foreground or is still in task list.
MqttChatFCMListener events : are called by google play firebase services when application is closed and FCM feature is activated. Click here to see how to activate FCM in Mqttchat android library.

MQTTChat listener

Is used to get all MQTT chat events :
MqttChatListener listener= new MqttChatListener() {
@Override
public void onLoadComplete() {
Log.i(Tag,"MQTT Chat load complete");
}
@Override
public void onUserPresenceUpdate(int i, String s, boolean b, boolean b1, String s1) {
Log.i(Tag,"User presence update : userId:"+i +"; new status:"+s+" ;voice capacity:"+b +" ;video capacity:"+b1+"; timestamp:"+s1);
}
@Override
public void onSendMessage(int i, Message message) {
Log.i(Tag,"Logged user send message to userId :"+i +"; message:"+message.toString());
}
@Override
public void onAckMessage(int i, Ack ack, Message message) {
Log.i(Tag,"Logged user received Ack from server for message sent to userId :"+i +"; ack :"+ack.toString()+"; message:"+message.toString());
}
@Override
public void onRejectMessage(int i, String s, Message message) {
Log.i(Tag,"Logged user has sent message to userId:"+i+"; message was rejected by server because of :"+s+"; and message content :"+message.toString());
}
@Override
public void onIncomingMessage(int i, Message message) {
Log.i(Tag,"Logged user received new message from userId:"+i+"; message content:"+message.toString());
}
@Override
void onReceiveNotification(Notification notification){
Log.i(Tag,"Logged user received MQTT chat notification:"+notification.toString());
}
@Override
public void onUserTyping(int i, boolean b) {
Log.i(Tag,"A user userId:"+i+" is currently typing to logged user; is typing :"+b);
}
@Override
public void onReadingMessage(int i, int i1, String s) {
Log.i(Tag,"A user userId:"+i+"; is reading message id:"+i1+" ; reading date :"+s);
}
@Override
public void onNotReadMessagesCountUpdate(int i) {
Log.i(Tag,"Number of unread messages is changed for logged user, new number is :"+i);
}
@Override
public void onError(int i, String s) {
Log.e(Tag,"MQTTCHAT error code :"+i+";message :"+s);
}
};
To add listener to MQTT chat:
MqttChat.getInstance().addMqttchatListener(listener);
And to remove listener :
MqttChat.getInstance().removeMqttchatListener(listener);
You can add many listeners in differents activities or fragments. So you can catch events where you need.
void onLoadComplete();
When chat is completely loaded.
void onUserPresenceUpdate(int userId, String status, boolean audioCap, boolean videoCAP, String timestamp);
When a contact in contacts list or friend user in friends list has changed status.
void onSendMessage(int toUserId, Message message);
When logged user send a message.
void onAckMessage(int toUserId, Ack ack,Message message);
When ACK is received from server. that mean that the message is successfully sent and will be delivered.
void onRejectMessage(int toUserId,String why,Message message);
When message is rejected from server. because user is locked by toUserid user.
void onIncomingMessage(int fromUserId,Message message);
When logged user receive new message.
void onReceiveNotification(Notification notification);
When logged user receive new Notification.
void onUserTyping(int fromUserId,boolean on);
When a contact or friend is typing.
void onReadingMessage(int fromUserId,int messageId,String readDate);
When a contact or friend read a sent message.
void onNotReadMessagesCountUpdate(int n);
When a number or unreaded message change.
void onError(int code,String error);
When error occured.

MqttChat UI listener

Is used to get events performed by users on the main chat UI.
MqttChatUiListener listener= new MqttChatUiListener() {
@Override
public void onRemoveFriendSuccess(int i) {
Log.i(Tag,"user has removed friend with userId:"+i);
}
@Override
public void onRemoveFriendFail(int i, String s) {
Log.e(Tag,"an error "+s+" has occured when user try to remove friend with userId:"+i);
}
@Override
public void onLockUserSuccess(int i) {
Log.i(Tag,"user has locked user with userId:"+i);
}
@Override
public void onLockUserFail(int i, String s) {
Log.e(Tag,"an error "+s+" has occured when user try to lock user with userId:"+i);
}
@Override
public void onUnLockUserSuccess(int i) {
Log.i(Tag,"user has unlocked user with userId:"+i);
}
@Override
public void onUnLockUserFail(int i, String s) {
Log.e(Tag,"an error "+s+" has occured when user try to unlock user with userId:"+i);
}
@Override
public void onDeleteConversationSuccess(int i) {
Log.i(Tag,"user has deleted conversation with user having userId:"+i);
}
@Override
public void onDeleteConversationFail(int i, String s) {
Log.e(Tag,"an error "+s+" has occured when user try to remove conversation with user having userId:"+i);
}
}
To add listener to MQTT chat:
MqttChat.getInstance().addMqttchatUiListener(listener);
And to remove listener :
MqttChat.getInstance().removeMqttchatUiListener(listener);

MQTTChat FCM listener

Two types of FCM events are provided by the listener: events following an MQTT Chat notification received. Or else an FCM notification message received by FCM service that can be sent by your server or another library.
MqttChat.getInstance().addMqttchatFCMListener(new MqttChatFCMListener() {
@Override
public void onReceiveFCMNotification(boolean notificationsSettingEnabled, int toUserId, Notification notification) {
}
@Override
public void onReceiveOtherFCMData(com.google.firebase.messaging.RemoteMessage message) {
}
});
Event
Description
void onReceiveFCMNotification(boolean notificationsSettingEnabled, int toUserId, Notification notification);
When MQTT Chat server send notification to FCM. That means logged user received a notification when application is closed.
void onReceiveOtherFCMData(RemoteMessage message);
When an FCM notification message not sent by MQTT Chat is received by FCM service and then delivered to you through this event.
For more details about MQTT advanced notifications management in android library please see this section.