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
Conversation
There was a problem hiding this 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 :-)
src/plugins/inputs/part.js
Outdated
if (chan.type === Chan.Type.LOBBY) { | ||
let target, partedChan; | ||
if (args.length === 0) { | ||
target = chan.name; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All right!
src/plugins/inputs/part.js
Outdated
}); | ||
|
||
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 /part
ed from anywhere but itself.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 windowfoo
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 #
)
There was a problem hiding this 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.
src/plugins/inputs/part.js
Outdated
if (typeof target === "undefined") { | ||
chan.pushMessage(this, new Msg({ | ||
type: Msg.Type.ERROR, | ||
text: "Cannot part channel " + target.name + ": Channel not found." |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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..
following thelounge#1476 (comment)
src/plugins/inputs/part.js
Outdated
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this 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.
I agree with @xPaw. Checking for whether Overall, I'm excited to be able to part channels without switching to them! 👍 |
Can you squash commits, @eliemichel? Great work! |
Do we need to update https://github.com/thelounge/lounge/blob/master/client/index.html#L788-L796 ? |
There was a problem hiding this 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.
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. ;) |
4df1ebc
to
f26c2da
Compare
@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 Thx! |
No, thank you. This is a great addition, thanks for it :-) |
/part
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.