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

fix: unsubscribe message event #187

Merged
merged 1 commit into from
Dec 18, 2023
Merged

Conversation

kele-leanes
Copy link
Contributor

Description:
This pull request addresses the concerns raised in issue #180 by implementing the removal of the event subscription. The primary focus is on enhancing the reliability of unsubscribing from the message stream.

It is highly recommended to utilize the method returned by the streamMessages function for unsubscribing, as opposed to relying solely on the static unsubscribeFromMessages. This is crucial because the latter may not comprehensively handle unsubscription and might inadvertently impact multiple listeners.

For instance, consider the updated usage example below:

export function useXmtpStream(conversation?: Conversation<any>) {
  useEffect(() => {
    const streamMessages = () => {
      if (!conversation) {
        return;
      }

      return conversation.streamMessages(async (message) => {
        console.log(message);
      });
    };

    const unsubscribe = streamMessages();

    return () => {
      if (conversation) {
        unsubscribe?.(); // Invoke the unsubscribe method
      }
    };
  }, []);
}

By calling the unsubscribe method obtained from streamMessages, we ensure a more comprehensive unsubscription process, mitigating potential issues related to multiple listeners.

@kele-leanes kele-leanes self-assigned this Dec 18, 2023
@kele-leanes kele-leanes requested a review from a team as a code owner December 18, 2023 18:40
Copy link
Contributor

@nplasterer nplasterer left a comment

Choose a reason for hiding this comment

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

Seems like a good change!

@nplasterer nplasterer merged commit e95063a into main Dec 18, 2023
4 of 5 checks passed
@nplasterer nplasterer deleted the kele/unsubscribe-from-stream branch December 18, 2023 23:39
Copy link
Contributor

🎉 This PR is included in version 1.23.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants