-
Notifications
You must be signed in to change notification settings - Fork 70
Changes to state to handle auto-joining channels that have +R. #240
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
Conversation
|
Thanks @trevarj ! Just added some inline comments. |
a2d54d2 to
d6b68df
Compare
| /// Channel joined state | ||
| join_state: JoinState, | ||
| /// Join attempts | ||
| join_attempts: u8, |
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.
Moved join_attempts out of the Joining variant in JoinState because when the state is Initial there should be join attempts. I thought it's nicer than keeping the value in Initial and in Joining.
|
All simple feedback has been applied. I commented on some code that needs another closer review. Sorry this is taking so long! |
osa1
left a 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.
Reading this code again, I think the initial state is fine. We can remove it, but if we do it we'll need an additional state for "currently joined channels" that we'll join again on reconnect, and move the chans vec to that field in StateInner::reset. Perhaps currently solution is fine.
I'll do another pass later.
Currnetly the state transitions are:
- Initial -> Joining: when we get 477 for the channel
- Initial -> Joined: when we were able to join on first attempt
- Joining -> Joined: when we get a JOIN message for the channel
- Joining -> Initial: I think when user does
/connectwhile we're trying to join? - Joined -> Initial: Connection reset
- Joined -> Joining: Is this currently invalid?
I think it'd be good to make sure the last one won't happen, or if it will then explain when.
Would be good to document this in the code also (maybe in the documentation for JoinState).
Btw, one bug I just discovered is if I do C-c enter and close tiny while there's a join task we want until the next iteration (~10 seconds) before tiny finally quits.
Right, just a reconnect.
Yes, this is unexpected/invalid. I will add these state transitions to the doc comment of JoinState.
This match should prevent the bad state. I suppose it doesn't prevent the programmer from doing it somewhere later on, but hopefully the state transition doc will prevent that. |
osa1
left a 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.
Just did another pass.. This is looking quite good now. Thanks again, @trevarj !
libtiny_client/src/state.rs
Outdated
| warn!("Could not find channel in server state channel list."); | ||
| } | ||
| } else { | ||
| warn!("Received 477 reply but nickserv_ident is not configured."); |
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 think this is fine, let's make this debug! maybe. Note that 477 does not always mean we need to register. Even if it does, it's perfectly fine for a user to try to join to a +R channel without being registered. It's not a problem with tiny that may need debugging later.
If the server sends back a 477 reply, meaning that we can't join the channel without being registered and identified with NickServ, then we check to see if nickserv_ident is configured. If it is configured then we wait for 10 seconds and retry joining the channel. We do this 3 times and then stop. Removed some unwraps. Changed UX to alert user of retries Added new Event to libtiny_client to send a channel message when a 477 reply comes from the server and we want to tell the user that a retry will be made. Also, the 477 reply from the server will show up in a channel tab which lets the user know what is going on instead of not opening a tab at all. Closing a tab that is in the process of joining a channel kills join task. Only send PART message to channel when we are actually joined (in the channel). PR feedback changes. Removed optional Sender in JoinState. Cleaned up log messages. Moved async lambda into own function. Added doc comment to JoinState. Renamed Initial state to NotJoined Fixed bug that delays quitting when join task is running More PR feedback
libtiny_client/src/state.rs
Outdated
| match utils::find_idx(&self.chans, |c| &c.name == chan) { | ||
| None => { | ||
| self.chans.push((chan.to_owned(), HashSet::new())); | ||
| self.chans.push(Chan::new(chan.to_owned())); |
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 initializes the Chan state with NotJoined instead of Joined, which is a bug probably.
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 didn't understand this part. I'm assuming that when it's not found / None then the channel is not actually joined. Possibly an unexpected state that should be logged?
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 can think of at least two cases where this can happen:
- User sends a
JOIN ...message in the server tab, instead of using/join. - The server for whatever reason adds the user to a channel. I think this happened to me before, though I don't remember the details.
I think both branches of this match should initialize the Chan state as Joined.
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.
Done!
| } else { | ||
| false | ||
| }; | ||
| let is_notice = matches!(msg_ty, MsgType::Cmd("NOTICE")); |
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.
Fixed this random clippy warning
If the server sends back a 477 reply, meaning that we can't join the
channel without being registered and identified with NickServ, then we
check to see if nickserv_ident is configured. If it is configured then
we wait for 10 seconds and retry joining the channel. We do this 3 times
and then stop.
Also cleaned up channel tuple and made it into a struct so that I could add a retry count for each channel.
Closes #236