chore: document and add RFC1459, RFC2812 and IRCv3 commands

* also rename ChannelIndex to ActiveChannelIndex
This commit is contained in:
2022-01-21 03:23:02 +02:00
parent 2edc007022
commit 26deca05d9
5 changed files with 280 additions and 126 deletions
+10 -2
View File
@@ -245,13 +245,21 @@ func (s *State) HandleCommand(msg parser.IRCMessage) {
case commands.RPL_NAMREPLY:
s.handleNAMREPLY(msg)
case commands.RPL_ENDOFNAMES:
// TODO: what do i do here lol
// TODO: toggle a flag on the channel to indicate
// it received all the names correctly.
// start a timeout and update said timeout on every RPL_NAMREPLY
// and log an error if timeout ends without receiving this command.
case commands.RPL_MOTDSTART:
s.handleMOTDStart(msg)
case commands.RPL_MOTD:
s.handleMOTD(msg)
case commands.RPL_ENDOFMOTD:
// TODO: what do i do here lol
// TODO: toggle a flag on the client/server to indicate
// it received all the MOTD correctly
// start a timeout and update said timeout on every RPL_MOTD
// and log an error if timeout ends without receiving this command.
default:
fullMsg := fmt.Sprintf("%s %s %s %s", msg.Tags, msg.Source, msg.Command, strings.Join(msg.Parameters, " "))
+18 -18
View File
@@ -82,7 +82,7 @@ func (s State) Update(msg tea.Msg) (State, tea.Cmd) {
switch msg := msg.(type) {
case ReceivedIRCMsgMsg:
wasAtBottom := s.Viewport.AtBottom()
s.Viewport.SetContent(s.Client.Channels[s.Client.ChannelIndex].History)
s.Viewport.SetContent(s.Client.Channels[s.Client.ActiveChannelIndex].History)
if wasAtBottom {
s.Viewport.GotoBottom()
@@ -105,14 +105,14 @@ func (s State) Update(msg tea.Msg) (State, tea.Cmd) {
s.Client.ActiveChannel = channel
for i, c := range s.Client.Channels {
if c.Name == channel {
s.Client.ChannelIndex = i
s.Client.ActiveChannelIndex = i
break
} else if i == len(s.Client.Channels)-1 {
s.Client.Channels = append(s.Client.Channels, client.Channel{
Name: channel,
Users: make(map[string]client.User),
})
s.Client.ChannelIndex = len(s.Client.Channels) - 1
s.Client.ActiveChannelIndex = len(s.Client.Channels) - 1
LastTabIndexInTabBar = len(s.Client.Channels) - 1
s.TabRenderingDirection = Left
}
@@ -124,17 +124,17 @@ func (s State) Update(msg tea.Msg) (State, tea.Cmd) {
} else {
if s.Client.ActiveChannel != s.Client.Host {
fullMsg := s.Client.Nickname + ": " + msg.Msg
s.Client.Channels[s.Client.ChannelIndex].History += fullMsg + client.CRLF
s.Client.Channels[s.Client.ActiveChannelIndex].History += fullMsg + client.CRLF
// TODO: make sure to only append the message to the history if server sends back no errors
s.Client.SendCommand(commands.PRIVMSG, s.Client.ActiveChannel, msg.Msg)
s.Viewport.SetContent(s.Client.Channels[s.Client.ChannelIndex].History)
s.Viewport.SetContent(s.Client.Channels[s.Client.ActiveChannelIndex].History)
s.Viewport.GotoBottom()
}
}
return s, nil
case SwitchChannelsMsg:
s.Viewport.SetContent(s.Client.Channels[s.Client.ChannelIndex].History)
s.Viewport.SetContent(s.Client.Channels[s.Client.ActiveChannelIndex].History)
s.Viewport.GotoBottom()
*s.SidePanel, cmd = s.SidePanel.Update(msg)
@@ -181,26 +181,26 @@ func (s State) Update(msg tea.Msg) (State, tea.Cmd) {
}
if key == "right" {
s.Client.ChannelIndex++
s.Client.ActiveChannelIndex++
} else {
s.Client.ChannelIndex--
s.Client.ActiveChannelIndex--
}
if s.Client.ChannelIndex >= len(s.Client.Channels) {
s.Client.ChannelIndex = 0
} else if s.Client.ChannelIndex < 0 {
s.Client.ChannelIndex = len(s.Client.Channels) - 1
if s.Client.ActiveChannelIndex >= len(s.Client.Channels) {
s.Client.ActiveChannelIndex = 0
} else if s.Client.ActiveChannelIndex < 0 {
s.Client.ActiveChannelIndex = len(s.Client.Channels) - 1
}
if s.Client.ChannelIndex > LastTabIndexInTabBar {
if s.Client.ActiveChannelIndex > LastTabIndexInTabBar {
s.TabRenderingDirection = Left
LastTabIndexInTabBar = s.Client.ChannelIndex
} else if s.Client.ChannelIndex < FirstTabIndexInTabBar {
FirstTabIndexInTabBar = s.Client.ChannelIndex
LastTabIndexInTabBar = s.Client.ActiveChannelIndex
} else if s.Client.ActiveChannelIndex < FirstTabIndexInTabBar {
FirstTabIndexInTabBar = s.Client.ActiveChannelIndex
s.TabRenderingDirection = Right
}
s.Client.ActiveChannel = s.Client.Channels[s.Client.ChannelIndex].Name
s.Client.ActiveChannel = s.Client.Channels[s.Client.ActiveChannelIndex].Name
return s, SwitchChannels
case "g":
if s.FocusIndex == Viewport {
@@ -268,7 +268,7 @@ func (s *State) SetSize(width, height int) {
// we need this to render an empty viewport
history := ""
if len(s.Client.Channels) != 0 {
history = s.Client.Channels[s.Client.ChannelIndex].History
history = s.Client.Channels[s.Client.ActiveChannelIndex].History
}
// we need to re-set the content because words wrap differently on different sizes
+2 -2
View File
@@ -36,7 +36,7 @@ type SidePanelState struct {
func (s *SidePanelState) getHeader() string {
usersCount := 0
if len(s.Client.Channels) != 0 {
usersCount = len(s.Client.Channels[s.Client.ChannelIndex].Users)
usersCount = len(s.Client.Channels[s.Client.ActiveChannelIndex].Users)
}
separator := strings.Repeat("—", s.Viewport.Width) + "\n"
header := fmt.Sprintf("Users in this channel (%d)\n", usersCount) + separator
@@ -48,7 +48,7 @@ func (s *SidePanelState) getLatestNicks() []string {
nicks := make([]string, 0)
if len(s.Client.Channels) != 0 {
for nick, user := range s.Client.Channels[s.Client.ChannelIndex].Users {
for nick, user := range s.Client.Channels[s.Client.ActiveChannelIndex].Users {
_nick := user.Prefix + nick
nicks = append(nicks, _nick)
}