ParseLiveQuery-Android icon indicating copy to clipboard operation
ParseLiveQuery-Android copied to clipboard

LiveQuery with two objects of same data type does not work [UPDATED]

Open ghost opened this issue 7 years ago • 0 comments

Hi,

We have 3 live queries subscribed simultaneously. Each of them subscribes on a different class. The following one is not working correctly somehow. The query is for live chatting and shall trigger when a message was created from a user that is for you. Right here, do not question the data model and why we do not have a channel to point to or to point from. The query for live chatting looks like:

ParseUser currentUser = ParseUser.getCurrentUser(); // this one is not null and is available on server
ParseUser participant = ...;                        // this one is a valid ParseUser != currentUser

ParseLiveQueryClient liveQueryClient = ParseLiveQueryClient.Factory.getClient(new OkHttp3SocketClientFactory(new OkHttpClient()));

ParseQuery<Message> queryMessages;
queryMessages = Message.getQuery();
queryMessages.whereEqualTo("receiver", currentUser).whereEqualTo("sender", participant);  // sender is my chat contact

SubscriptionHandling<Message> subscriptionHandling;
subscriptionHandling = liveQueryClient.subscribe(queryMessages);
subscriptionHandling.handleEvent(SubscriptionHandling.Event.CREATE, new SubscriptionHandling.HandleEventCallback<Message>() {
      @Override
      public void onEvent(ParseQuery<Message> query, Message message) {
            // saving message to local database
      }
});

The query has two constraints.

  1. I am receiver and
  2. sender is my chat contact. Both are user pointers.

We have also tried seperating both constraints like:

queryMessages.whereEqualTo("receiver", currentUser);
queryMessages.whereEqualTo("sender", participant);  // sender is my chat contact

but that did not work either.

Then we have tried to use one pointer only and a phonenumber as String like:

String phoneNumber = currentUser.getUsername();  // username is the users phonenumber
queryMessages.whereEqualTo("phoneNumber", phoneNumber).whereEqualTo("sender", participant);// sender is my chat contact

Somehow this is working fine. I only receive messages I should to.

What is the technical difference behind the few queries? Another aspect I want to ask for is ParseLiveQueryClients attributes. The "clientID" is unique but the "requestID" is always 1. Watch log output:

05-05 00:17:36.555 20945-21109/? V/ParseLiveQueryClient: Socket onMessage {"op":"connected","clientId":962}
05-05 00:17:36.555 20945-21108/? V/ParseLiveQueryClient: Socket onMessage {"op":"connected","clientId":961}
05-05 00:17:36.556 20945-21102/? V/ParseLiveQueryClient: Connected, sending pending subscription
05-05 00:17:36.557 20945-21107/? V/ParseLiveQueryClient: Socket onMessage {"op":"connected","clientId":963}
05-05 00:17:36.557 20945-21101/? V/ParseLiveQueryClient: Connected, sending pending subscription
05-05 00:17:36.557 20945-21119/? V/ParseLiveQueryClient: Connected, sending pending subscription
05-05 00:17:36.674 20945-21109/? V/ParseLiveQueryClient: Socket onMessage {"op":"subscribed","clientId":962,"requestId":1}
05-05 00:17:36.676 20945-21108/? V/ParseLiveQueryClient: Socket onMessage {"op":"subscribed","clientId":961,"requestId":1}
05-05 00:17:36.676 20945-21107/? V/ParseLiveQueryClient: Socket onMessage {"op":"subscribed","clientId":963,"requestId":1}

What is requestID used for and why is it always 1?

Thank you very much

UPDATE

After testing we have found out that using 2 attributes of same date type (String, Pointer, aso.) will cause errors. We have tested with two Strings and two pointers. With one pointer and one string it works well.

Not working: (Pointer, Pointer)

queryMessages.whereEqualTo("receiver", currentUser);
queryMessages.whereEqualTo("sender", participant);  // sender is my chat contact

and (String, String)

queryMessages.whereEqualTo("receiver", currentUser.getUsername());
queryMessages.whereEqualTo("sender", participant.getUsername());  // sender is my chat contact

Working: (String, Pointer)

queryMessages.whereEqualTo("receiver", currentUser.getUsername());
queryMessages.whereEqualTo("owner", participant);// sender is my chat contact

ghost avatar May 04 '17 22:05 ghost