How MQTT CHAT android messenger is perfect for dating apps.

MQTT CHAT
3 min readMar 30, 2022

In any dating app, chat and real time messaging are the most important features that can contribute to the success of the dating app.

From the experience i had browsing through some dating apps in google play. This feature is almost neglected. It’s very rare to find an application that contains a consitent messenger that allows sending text, smileys captured and saved photos, voice notes, Urls formatting,… and of corse audio&video calls.

I understand that developing a complete messenger is painful in terms of time and cost. Moreover, most of dating applications require specific constraints related to the use of chat.

For example: a user should be able to use a specific feature only after having paid for a pack. Or user can send only two or three messages and wait the other user to respond before he can send more messages. Sometimes we would like to scan messages or photos before sending them to the recipients or to place ads everywhere in the messenger graphical interfaces.

Fortunately MQTT CHAT messenger v4.0.0 has taken into account all theses considerations.Of Course I will not present in this article a complete documentation of messenger that you can find in this link. I will show you for example, how to implement message sending restriction with MQTT chat android messenger.

In this exemple, user can send only three messages and wait the other user to respond before he can send other messages. This restriction is widely used in dating applications to protect certain users from sending messages abuse, or receiving certain types of content without prior consent.

To start, MQTT CHAT messenger uses this java class called EventsCallbacks sto handle plugins restriction and customisation.

public class EventsCallbacks {    public EventsCallbacks() {
}

public void onSendingMessage(int toUserId, Message message, AuthorisationCallback authorisationCallback) {
authorisationCallback.OK();
}

public void onRemovingFriend(int friendId, AuthorisationCallback authorisationCallback) {
authorisationCallback.OK();
}

public void onLockingUser(int userId, AuthorisationCallback authorisationCallback) {
authorisationCallback.OK();
}

public void onUnLockingUser(int userId, AuthorisationCallback authorisationCallback) {
authorisationCallback.OK();
}

public void onDeletingConversation(int userId, AuthorisationCallback authorisationCallback) {
authorisationCallback.OK();
}

public void onAudioCallClick(int userId, AuthorisationCallback authorisationCallback) {
authorisationCallback.OK();
}

public void onVideoCallClick(int userId, AuthorisationCallback authorisationCallback) {
authorisationCallback.OK();
}
}

And below the AuthorisationCallback class.

public abstract class AuthorisationCallback {    public AuthorisationCallback() {
}

public abstract void OK();

public abstract void Cancel(String var1);
}

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.

So we will start by creating our custom class called CustomEventsCallbacks which extends the parent class. In onSendingMessage() method we check if number of sent messages is <3, if ok we return authorisationCallback.OK() else authorisationCallback.Cancel(String custom_message_to_user);

public class CustomEventsCallbacks extends EventsCallbacks {

private Context mContext;

public CustomEventsCallbacks(Context mContext) {
this.mContext = mContext;
}

@Override
public void onSendingMessage(int toUserId, Message message,AuthorisationCallback authorisationCallback){
int cIndex= MqttChat.getInstance().getLoggedUser().getContactIndexByUserid(toUserId);
Contact c=MqttChat.getInstance().getLoggedUser().getContacts().get(cIndex);
if(c.getMessages().size()<=3){ authorisationCallback.OK(); }else{
authorisationCallback.Cancel(mContext.getResources().getString(R.string.wait_response,EventsCallbacksUtil.getContactName(toUserId)));
}
};
}

Finally, we affect our custom class to MQTT CHAT messenger like below

MqttChat.getInstance().setEventsCallbacks(new CustomEventsCallbacks(getApplicationContext()));

Below screenshot that show restruction message.

Official Website

Demo Repository on github

--

--