Skip to main content

Events

Chat Events

It's possible to handle several events from SDK:

  • UnreadMessagesCount
  • ChatView
  • ProfessionalProfileView
  • ChatMessageSent
  • ChatMessageReceived

Events Implementing

UnreadMessagesCount can be captured calling it from Professionallist Sdk's component:

professionalList.setProfessionalListListener(object: ProfessionalList.ProfessionalListListener {
...
override fun onUnreadMessageCountChange(unreadMessageCount: Long) {
//Do your stuff
// note: 'unreadmessageCount' parameter means the total amount of user's unread messages
}

})

Chat View, ProfesisonalProfileView, ChatMessageSent and ChatMessageReceived events are captured via BroadcastReceiver. Each event has its own properties, the Intent of the BroadcastReceiver contains them:

  • ChatMessageSent & ChatMessageReceived Intent bundle properties: "eventType", "roomId", "professionalHash", "speciality", "messageType", "messageId" & "message".
  • ProfessionalProfileView Intent bundle properties: "eventType", "professionalHash", "speciality".
  • ChatView Intent bundle properties: "eventType", "roomId", "professionalHash", "speciality".
// 1. Create your broadcast receiver
class EventAppBroadcastReceiver : BroadcastReceiver() {
var eventProperties: Bundle? = null

override fun onReceive(context: Context?, intent: Intent) {
// Capturing bundle from the intent
eventProperties = intent.extras

//e.g Show a toast message with info related to event 'ChatMessageReceived' by the professional
Toast.makeText(context, "Chat event type: ${eventProperties?.getString("eventType")} " +
"${eventProperties?.getString("speciality")} " +
"${eventProperties?.getString("messageType")} " +
"${eventProperties?.getString("message")}", Toast.LENGTH_LONG).show()
}
}

// 2. Declare your BroadcastReceiver on your Activity
val eventAppBroadCastReceiver: BroadcastReceiver = EventAppBroadcastReceiver()

// 3. Register your BroadcastReceiver, e.g. on your OnResume() method
LocalBroadcastManager.getInstance(this).registerReceiver(eventAppBroadCastReceiver,
IntentFilter(getString(R.string.meetingdoctors_local_broadcast_chat_events)))

// Optional. If its needed to stop capturing events, unregister your Broadcastreceiver, e.g. on your OnPause() method
LocalBroadcastManager.getInstance(this).unregisterReceiver(eventAppBroadCastReceiver)