QuickBlox / quickblox-android-sdk

QuickBlox Android SDK includes code snippets with main use cases and framework JAR library.
BSD 3-Clause "New" or "Revised" License
417 stars 697 forks source link

Private chat Notification receiving for all the users #796

Closed mathayan321 closed 1 year ago

mathayan321 commented 2 years ago

val userIds1 = StringifyArrayList()

    for (user in userIds1!!) {
        userIds1.add(opponentId)
    }

    val event = QBEvent()
    event.userIds = userIds1
    event.environment = QBEnvironment.DEVELOPMENT
    event.notificationType = QBNotificationType.PUSH
    event.pushType = QBPushType.GCM
    val customData = HashMap<String, Any>()
    customData["data.message"] = text.toString()
    customData["data.title"] = currentUser.fullName
    customData["data.notification_id"] = 11

    event.setMessage(customData)

    QBPushNotifications.createEvent(event).performAsync(object : QBEntityCallback<QBEvent> {
        override fun onSuccess(qbEvent: QBEvent?, bundle: Bundle?) {
            Log.e("QB_notification","send")
            Log.e("CustomerData", Gson().toJson(qbEvent))
        }
        override fun onError(e: QBResponseException?) {
            Log.e("PN_error", e?.message.toString())
        }
    })

    the above is the code i am using but notification receiving for all the user, please guide us to fix this issues   
mathayan321 commented 1 year ago

What is the issues Completed ?

kirillTolmachev commented 1 year ago

@mathayan321 I have re-opened the issue.

@vdovbnya-qb Please check the code and write an answer.

vdovbnya-qb commented 1 year ago

@mathayan321 You are creating a list and trying to iterate over it, but the list is empty. You don't add it opponentId

    val userIds1 = StringifyArrayList()
    for (user in userIds1!!) {
        userIds1.add(opponentId)
     }

Try to add opponentId to the list without a loop

val userIds1 = StringifyArrayList()

    userIds1.add(opponentId)

    val event = QBEvent()
    event.userIds = userIds1
    event.environment = QBEnvironment.DEVELOPMENT
    event.notificationType = QBNotificationType.PUSH
    event.pushType = QBPushType.GCM
    val customData = HashMap<String, Any>()
    customData["data.message"] = text.toString()
    customData["data.title"] = currentUser.fullName
    customData["data.notification_id"] = 11

    event.setMessage(customData)

    QBPushNotifications.createEvent(event).performAsync(object : QBEntityCallback<QBEvent> {
        override fun onSuccess(qbEvent: QBEvent?, bundle: Bundle?) {
            Log.e("QB_notification","send")
            Log.e("CustomerData", Gson().toJson(qbEvent))
        }
        override fun onError(e: QBResponseException?) {
            Log.e("PN_error", e?.message.toString())
        }
    })