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

Added the events for unsubscribe calls #351

Closed
wants to merge 7 commits into from

Conversation

reyalpsirc
Copy link

@RocketChat/ReactNative

Closes #ISSUE_NUMBER

There was no code checking for when the unsubscription happened and so it was never removed.

@CLAassistant
Copy link

CLAassistant commented Jul 5, 2018

CLA assistant check
All committers have signed the CLA.

@diegolmello diegolmello self-assigned this Jul 6, 2018
@diegolmello
Copy link
Member

Hi @reyalpsirc.
Thanks for this PR.
Can you give an example of where it's never been removed?

@reyalpsirc
Copy link
Author

reyalpsirc commented Jul 6, 2018

@diegolmello I as using the DDP.js file alone on another project and noticed that there was no subscription to the "unsub"/"nosub" messages. However, it seems that when unsubscribing from "stream-room-messages", this error happens: https://forums.rocket.chat/t/unsubscribe-from-stream-room-messages/1500

I can't provide the project itself where I found the issue since I'm not allowed to but, any call to a unsubscribe method with a log on on the Promise resolve for the "unsubscribe" should be enough to see that it is never called without this

Corrected issue where events were not being removed when calling the unsubscribe of a stream like stream-room-messages
@reyalpsirc
Copy link
Author

reyalpsirc commented Jul 24, 2018

@diegolmello I just updated this because the problem was not totally corrected. I basically have a DDP typescript implementation of this file and noticed that when I called the unsubscribe method and then the subscribe again, the old events linked to the previous subscribe would be revived when they actually shouldn't.

@diegolmello
Copy link
Member

@reyalpsirc Lint didn't pass. Can you fix it?

@reyalpsirc
Copy link
Author

@diegolmello fixed the lint errors

ggazzo
ggazzo previously requested changes Jul 24, 2018
app/lib/ddp.js Outdated
@@ -290,9 +296,12 @@ export default class Socket extends EventEmitter {
id,
name,
params,
unsubscribe: () => this.unsubscribe(id)
unsubscribe: () => {
// Also remove the events attached to the subscription of the collection
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use removeAllListeners instead

app/lib/ddp.js Outdated
unsubscribe: () => this.unsubscribe(id)
unsubscribe: () => {
// Also remove the events attached to the subscription of the collection
this.removeAllForEvent(name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should call this method removeAllListeners inside of unsubscribe

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to use "removeAllListeners" there then we need to pass the name as an extra parameter on unsubscribe. Otherwise there's no way to link them together.

Moved "removeAllForEvent" into the unsubscribe method
@reyalpsirc
Copy link
Author

@ggazzo I just updated the file

@@ -39,6 +39,11 @@ class EventEmitter {
}
}
}
removeAllForEvent(event) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We fixed some bugs at #379.
removeAllForEvent doesn't seem to be necessary anymore, since every subscribe closes its listener.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I made this patch from a version of ddp.js that I have in typescript (made for a specific React Native project). In my case, I needed it so that I could clear all events that were added while the stream 'stream-room-messages' was open

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Sounds like it's a different behaviour than ours.
In our case, we would clear events one by one.
For us, removeAllForEvent could cause unpredictable behaviour in future.

@@ -113,6 +118,7 @@ export default class Socket extends EventEmitter {

this.on('result', data => this.ddp.emit(data.id, { id: data.id, result: data.result, error: data.error }));
this.on('ready', data => this.ddp.emit(data.subs[0], data));
this.on('nosub', data => this.ddp.emit(data.id, data));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is useful.

@FaizanZahid
Copy link

@diegodorgam guys react native app is very good, we love it. hats off to the hard working team.

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

Successfully merging this pull request may close these issues.

5 participants