Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ghost opened this issue May 4, 2017 · 0 comments
Open

Comments

@ghost
Copy link

ghost commented May 4, 2017

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 ghost changed the title LiveQuery with two pointers of same type does not work LiveQuery with two objects of same data type does not work May 10, 2017
@ghost ghost changed the title LiveQuery with two objects of same data type does not work LiveQuery with two objects of same data type does not work [UPDATED] May 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants