Search code examples
javaandroidxmppquickblox

How to retrieve username from a message in Quickblox?


I am trying to retrieve the Username of the creator of a Message in Quickblox.

I am able to retrieve the ID of the user with message.getFrom(); but cannot figure out how to get the username through either using the User ID # or from the message itself. Any help with this would be greatly appreciated.

chat.addChatMessageListener(new ChatMessageListener() {
  @Override
  public void processMessage(Message message) {

    Log.i("QB LOG", "Message : " + message.getBody());

    //Get userID from message
    int userIdNo = Integer.parseInt(message.getFrom());

    //Would like to be able to retrieve user name here <---
  }

  @Override
  public boolean accept(Message.Type type) {
    switch (type) {
      case chat:
        return true; // process 1-1 chat messages
      default:
        return false;
    }
  }
});

Solution

  • String from = message.getFrom();
    int participantId = Integer.valueOf(QBChatUtils.parseQBUser(from));
    
    
    QBUsers.getUser(participantId, new QBCallbackImpl() {
    @Override
    public void onComplete(Result result) {
    if (result.isSuccess()) {
    QBUserResult qbUserResult = (QBUserResult) result;
    Log.i(TAG, ">>> User: " + qbUserResult.getUser().getFullName()