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

Error with listener list - every listeners are anonymous #365

Open
alexgaill opened this issue Aug 8, 2024 · 0 comments
Open

Error with listener list - every listeners are anonymous #365

alexgaill opened this issue Aug 8, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@alexgaill
Copy link

Describe the bug
When using MatrixClient.on() or MatrixClient.addListener(), every listener is saved as anonymous function or anonymous async function.
using MatrixClient.off() or MatrixClient.removeListener doesn't remove it because listener is not find.

To Reproduce

const listenIncidentProcess = (client: MatrixClient): void => {
  const event = 'room.message';
  const handler = handleIncidentRoomState(client);

  const isListenerRegistered = registeredListeners.some(listener =>
    listener.client === client && listener.event === event && listener.handler === handler
  );

  if (!isListenerRegistered) {
    client.addListener(event, handler);
    registeredListeners.push({ client, event, handler });
  }
};

const closeProcessListener = (roomId: string, userId: string, client: MatrixClient): void => {
  if (incidentRoomState[roomId]) {
    delete incidentRoomState[roomId][userId];
  }
  console.log(client.listeners('room.message'))
  client.removeListener('room.message', handleIncidentRoomState(client))
  console.log(client.listeners('room.message'))
}

Expected behavior
With client.listeners(), i expect to have a list with an id or a name for every listener that allow me to remove easily the one that i need to remove.

image

@alexgaill alexgaill added the bug Something isn't working label Aug 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant