webofneeds icon indicating copy to clipboard operation
webofneeds copied to clipboard

Sending UsageCommentEvent on ConnectCommandSuccessEvent uses wrong connection

Open philprime opened this issue 6 years ago • 0 comments

Describe the bug When a user requests a connection to a service atom, the connection needs to be accepted by responding with a ConnectCommandEvent. To subscribe to the ConnectCommandSuccessEvent for a single event using ActionOnFirstEventListener, the connection in the BaseEventBotAction is always the first one connected since the bot started and not the one that just connected.

To Reproduce Steps to reproduce the behavior:

  1. Create a new bot using the bot-skeleton
  2. Add a connect from other atom event handler
bus.subscribe(ConnectFromOtherAtomEvent.class, noInternalServiceAtomEventFilter, new OpenConnectionAction(ctx));
  1. In the class OpenConnectionAction send a ConnectCommandEvent as a response
final ConnectCommandEvent connectCommandEvent = new ConnectCommandEvent(
                    connectFromOtherAtomEvent.getRecipientSocket(),
                    connectFromOtherAtomEvent.getSenderSocket(), message);
  1. Await for connection result
bus.subscribe(ConnectCommandSuccessEvent.class, new ActionOnFirstEventListener(ctx, new CommandResultFilter(connectCommandEvent),
                    new BaseEventBotAction(ctx) {
                        @Override
                        protected void doRun(Event event, EventListener executingListener) {
                            ...
                        }
 }));
  1. Inside the doRun send the UsageCommandEvent to the newly created connection
final ConnectCommandSuccessEvent successEvent = (ConnectCommandSuccessEvent) event;
logger.info(successEvent.getCon().toString());
UsageCommandEvent usageCommandEvent = new UsageCommandEvent(successEvent.getCon());
ctx.getEventBus().publish(usageCommandEvent);

Expected behavior when sending the UsageCommandEvent, it should send it to the newly connected atom.

Screenshots Not available

Desktop (please complete the following information):

  • OS: macOS Mojave 10.14.6
  • Browser Google Chrome
  • Version 77.0.3865.120

Smartphone (please complete the following information):

  • Device: none
  • OS: none
  • Browser none
  • Version none

Additional context We actually found this in the WoN-Hackathon 2019 when working on our PollVoteBot in the following branch:

https://github.com/WoN-Hackathon-2019/won-pollvotebot/tree/vote-service-atom-commands

philprime avatar Dec 17 '19 13:12 philprime