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

Take an optional argument in /part #1476

Merged
merged 1 commit into from Sep 14, 2017
Merged

Conversation

eliemichel
Copy link
Contributor

Fix #1430

/part #foo or /close #foo closes the chan #foo even if it is not the active one.

/part and /close without an argument keep their previous meaning.

Copy link
Member

@AlMcKinlay AlMcKinlay left a comment

Choose a reason for hiding this comment

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

Looks good, just 1 pedantic code style thing :-)

if (chan.type === Chan.Type.LOBBY) {
let target, partedChan;
if (args.length === 0) {
target = chan.name;
Copy link
Member

Choose a reason for hiding this comment

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

Could we simplify this and only have 1 variable, because we are just storing the name twice essentially.

So something like

const target = args.length === 0 ? chan : _.find(network.channels, {name: args[0]});

And then when we want to refer to the name, we can just do target.name. Does that make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All right!

});

if (chan.type === Chan.Type.CHANNEL) {
if (target.type === Chan.Type.CHANNEL) {
this.save();

if (network.irc) {
const partMessage = args[0] ? args.join(" ") : Helper.config.leaveMessage;
Copy link
Member

Choose a reason for hiding this comment

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

If you provide a target into the command, part message will be wrong here?

Copy link
Member

Choose a reason for hiding this comment

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

Oh yeah, good point.

https://en.wikipedia.org/wiki/List_of_Internet_Relay_Chat_commands#PART

Spec says PART <channels> [<message>] (where channels is a csv). So I guess we want to check if the chan exists, the nthe part message is the rest of the args. If the chan doesn't exist, then it's a part message. Although that could get messy.

How do other clients deal with this? Do they support /part without a chan argument?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mmh does the lobby chan have a name? If not, it will never by /parted from anywhere but itself.

Copy link
Member

Choose a reason for hiding this comment

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

It does, the same name you see in the UI.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, but what do you expect to happen when somebody does a /part Freenode for instance? For know, it responds You cannot part from networks, which does not seem unreasonable to me. Though, I'm ready to change this behavior if needed.

Copy link
Member

Choose a reason for hiding this comment

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

Well, a part message makes no sense for a query window.

So I'd say that if there is more than 1 arg and we are trying to part a query, don't let the user do it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I propose the following:

  • /part #foo bar quits #foo with message "bar".
  • /part foo bar quits the current window with message "foo bar" even if "foo" is a valid query window..
  • /part foo with "foo" a valid query window quits the query window foo with no message.
  • /part foo with "foo" not being a valid query window quits the current window with message "foo".

As a by-product, parting a query window with a leave message is still possible, but only by switching to this window and /part some message-ing.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds fine to me.

parting a query window with a leave message is still possible,

Since part is only sent for channels, it's effectively discarded.

Copy link
Member

Choose a reason for hiding this comment

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

Yup, sounds fine to me also.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also, /part #foo bar displays an error message and do nothing if #foo does not exist as a window. It does not part the current window as it would do for /part foo bar (with no #)

Copy link
Member

@AlMcKinlay AlMcKinlay left a comment

Choose a reason for hiding this comment

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

Looks great, thanks for this.

This needs to be squashed before we merge.

if (typeof target === "undefined") {
chan.pushMessage(this, new Msg({
type: Msg.Type.ERROR,
text: "Cannot part channel " + target.name + ": Channel not found."
Copy link
Member

Choose a reason for hiding this comment

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

target.name is undefined here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yeah I remember now why I did not go for the ternary at first..

@xPaw xPaw added the Type: Feature Tickets that describe a desired feature or PRs that add them to the project. label Aug 30, 2017
@xPaw xPaw added this to the 2.5.0 milestone Aug 30, 2017
eliemichel added a commit to eliemichel/lounge that referenced this pull request Aug 31, 2017
if (chan.type === Chan.Type.LOBBY) {
// Whether args[0] is to be considered as a target to part or the first word
// of leave message.
const targetArgument = args.length > 0 && (_.startsWith(args[0], "#") || args.length === 1);
Copy link
Member

Choose a reason for hiding this comment

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

This is on the server, so args[0].startsWith should work.

Copy link
Member

Choose a reason for hiding this comment

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

ignore this, see @xPaw's comment

Copy link
Member

@xPaw xPaw left a comment

Choose a reason for hiding this comment

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

Checking channel by comparing if the first char is # is only going to bring us problems.

Best and easiest way I see of doing this is checking there's a channel with name args[0], if yes get part starting with args[1], otherwise entire args becomes part message.

@dgw
Copy link
Contributor

dgw commented Aug 31, 2017

I agree with @xPaw. Checking for whether args[0] is an existing channel is an easy solution that leaves room for progressive enhancement (e.g. supporting multiple comma-separated channels, checking potential channel names against CHANTYPES instead of hardcoding #, etc.).

Overall, I'm excited to be able to part channels without switching to them! 👍

@astorije astorije assigned eliemichel and unassigned xPaw Aug 31, 2017
@astorije astorije assigned xPaw and unassigned eliemichel Sep 8, 2017
@MaxLeiter
Copy link
Member

Can you squash commits, @eliemichel? Great work!

@astorije
Copy link
Member

astorije commented Sep 9, 2017

Copy link
Member

@astorije astorije left a comment

Choose a reason for hiding this comment

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

Just to make sure we don't merge this with unsquashed commits (I can help with this if you want @eliemichel) and without Help window changes.

@astorije astorije assigned eliemichel and unassigned xPaw Sep 10, 2017
@eliemichel
Copy link
Contributor Author

Yey sorry guys I'm kind of in a rush for a deadline now, ping me back if I haven't done this end of next week. ;)

@astorije
Copy link
Member

@eliemichel, since you're busy, I took the liberty to update the help section, and squash your commits. Everything else in the code, I left it untouched :)

I'll let @xPaw or @YaManicKill merge it if they agree with the help changes.

@astorije astorije assigned xPaw and AlMcKinlay and unassigned eliemichel Sep 14, 2017
@xPaw xPaw merged commit 4431616 into thelounge:master Sep 14, 2017
@eliemichel
Copy link
Contributor Author

@astorije Thx!

@eliemichel eliemichel deleted the pr-part-other branch September 16, 2017 12:23
@AlMcKinlay
Copy link
Member

@astorije Thx!

No, thank you. This is a great addition, thanks for it :-)

@astorije astorije changed the title Take an optional argument in /part Take an optional argument in /part Sep 29, 2017
@AlMcKinlay AlMcKinlay removed their assignment Mar 12, 2018
@xPaw xPaw removed their assignment Mar 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature Tickets that describe a desired feature or PRs that add them to the project.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't /part other channel than active one
6 participants