-
Notifications
You must be signed in to change notification settings - Fork 140
Event handling refactor and fix handling of pusher_internal:subscription_count event #336
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
Conversation
but pass it on to the handlers. Also create the public pusher:subscription_count event
Looking at CI history, the test failures seem to be new to this PR. |
- formatting - fix subscriptioncount
Codecov ReportBase: 74.79% // Head: 74.50% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #336 +/- ##
============================================
- Coverage 74.79% 74.50% -0.30%
- Complexity 346 361 +15
============================================
Files 51 48 -3
Lines 1964 1957 -7
Branches 150 147 -3
============================================
- Hits 1469 1458 -11
- Misses 430 433 +3
- Partials 65 66 +1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
I did a change in the failing test, I think it's more stable now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going through the changes, but there are a lot of formatting changes and some other improvements (like adding final
). They are all welcome, but Ideally would have been a separate PR.
|
||
@SerializedName("user_id") | ||
private final String userId; | ||
|
||
private final String data; | ||
private final String channel; | ||
private final String event; | ||
|
||
public String getUserId() { | ||
return userId; | ||
} | ||
|
||
public String getChannelName() { | ||
return channel; | ||
} | ||
|
||
public String getEventName() { | ||
return event; | ||
} | ||
|
||
public String getData() { | ||
return data; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the changes in this class needed for the fix? This is a breaking change in the public interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added the getProperty method back, so now the public API is the same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. That's better. I would also remove the automatic conversion from object to string on the data field.
All our SDKs should be serializing event data as strings, but that's not a breaking change of course.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also remove the automatic conversion from object to string on the data field.
I'm not sure what you mean here, it was a string and it's still a string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm referring to the fromJson
method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. Test data is incorrect then. Let's fix that and make PusherEvent
simpler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well the data can be anything (even not json).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should always be a string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that is true, I'll fix the unit tests and always handle it as string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
public void handleEvent(PusherEvent event) { | ||
user.handleEvent(event); | ||
channelManager.handleEvent(event); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should remain private. I don't think there's a benefit to exposing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's implementing the PusherEventHandler interface now, so it has to be public
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But what's the benefit of implementing that interface if we don't want to expose this method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously it used a BiConsumer, which is kind of magic. Now it's a nice interface implementation, passed to factory.getConnection
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the call to getConnection
, we could keep it as it was with this::handleEvent
then Pusher
doesn't have to implement anything if you make getConnection
take a Consumer<PusherEvent>
or if you annotate PusherEventHandler
as a FunctionalInterface
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, like this?
if (event.getEventName().equals(SUBSCRIPTION_COUNT_EVENT)) { | ||
handleSubscriptionCountEvent(event); | ||
} | ||
emit(event); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Processing the internal subscription count event further is a change in behaviour that is not required to fix the reported issue if I understand correctly. Do we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's used to update the internal subscriptionCount value, which provides for the getCount() method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is done in the handleSubscriptionCountEvent
.
What I'm pointing out is
- Before this PR,
handleEvent
stopped after callinghandleSubscriptionCountEvent
. The only event processed further would be the public subscription count event. - With this PR, we call
emit
on the internal event after callinghandleSubscriptionCountEvent
. The equivalent behaviour wasn't there before. I'm not sure it is needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok changed it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Thanks!
Description of the pull request
pass the pusher_internal:subscription_count event on to the handlers. Also create the public
pusher:subscription_count event
Why is the change necessary?
The event was not send and the data was not parsed correctly.
CC @pusher/mobile