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

Should sending messages also emit a 'message' signal? #17

Closed
pusherman opened this issue Jun 2, 2011 · 5 comments
Closed

Should sending messages also emit a 'message' signal? #17

pusherman opened this issue Jun 2, 2011 · 5 comments

Comments

@pusherman
Copy link
Contributor

This is more of a question to see what other people thought rather than an issue.

I am working on a "client" of sorts that is using node-irc to handle all the back-end IRC stuff. In my code, I listen for a 'message' signal to capture all new PRIVMSG's sent to the channel the user is currently in. The problem-- this was only emitted when someone else sends a PRIVMSG to the channel. Not when the user who is logged in sends one.

To work around this, I just update my client when a message is sent w/out waiting for a signal from node-irc. The danger in doing this is there could have been a communication issue between the client and the server and me updating the client w/out waiting for a signal saying the message was actually sent could give the client a false sense of what's actually visible in the IRC channel.

My solution would be to to change

    this.send('PRIVMSG', target, text);
} // }}}

to

    this.send('PRIVMSG', target, text);
    this.emit('message' + target, this.nick, text);
} // }}}

Thoughts?

@AvianFlu
Copy link
Contributor

AvianFlu commented Jun 2, 2011

+1

@martynsmith
Copy link
Owner

Arguably however one of your pieces of rationale is that there is "danger" in updating the client without checking the data was sent, but the patch you suggest just blindly assumes that whatever you sent made it to the server okay?

I guess it's a little safer, but still not entirely ideal, that said, given the server doesn't actually echo back things you send it, there's no way to make this 100% reliable.

The only real problem I have with this is that it may well break backward compatibility for some people. For example if someone has written a bot to respond to certain events and the bot outputs something that triggers an event on itself, then there becomes a nasty infinite loop :-(

How would you feel about modifying your patch above to make a new event "selfmessage" which is emitted when you send a message. This convention could be used for various other things too perhaps (sending notices etc) ?

Then your client could just subscribe "message" and "selfmessage" using the same callback and everything should be okay?

@pusherman
Copy link
Contributor Author

A new 'selfmessage' event works. It makes sense in that it's not a command received from the ircd but a command that is about to be sent to the ircd.

@AvianFlu
Copy link
Contributor

AvianFlu commented Jun 3, 2011

My interest in this was from a logging perspective, and I'd been thinking about implementing my own "selfmessage" event to handle the case. So, +1 once again.

@martynsmith
Copy link
Owner

Okay, sounds like I'll make it work like that :-)

Hopefully I can sort that out this evening.

Martyn

On Sat, Jun 4, 2011 at 5:24 AM, AvianFlu <
[email protected]>wrote:

My interest in this was from a logging perspective, and I'd been thinking
about implementing my own "selfmessage" event to handle the case. So, +1
once again.

Reply to this email directly or view it on GitHub:
#17 (comment)

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

No branches or pull requests

3 participants