fix: also append the day's date if we append a message with a different date than the last channel date

This commit is contained in:
2025-08-29 15:59:46 +02:00
parent f88c2af404
commit 096743adca
6 changed files with 78 additions and 92 deletions
+2 -6
View File
@@ -17,7 +17,6 @@
package cmds package cmds
import ( import (
"fmt"
"time" "time"
tea "github.com/charmbracelet/bubbletea" tea "github.com/charmbracelet/bubbletea"
@@ -42,17 +41,14 @@ func Quit(client *irc.Client) tea.Cmd {
type SendPrivMsgMsg struct { type SendPrivMsgMsg struct {
Msg string Msg string
Timestamp string Datetime time.Time
} }
func SendPrivMsg(msg string) tea.Cmd { func SendPrivMsg(msg string) tea.Cmd {
return func() tea.Msg { return func() tea.Msg {
now := time.Now()
timestamp := fmt.Sprintf("[%02d:%02d]", now.Hour(), now.Minute())
return SendPrivMsgMsg{ return SendPrivMsgMsg{
Msg: msg, Msg: msg,
Timestamp: timestamp, Datetime: time.Now(),
} }
} }
} }
+13 -21
View File
@@ -31,7 +31,7 @@ import (
) )
type Message struct { type Message struct {
Timestamp string DateTime time.Time
Tags MessageTags // starts with @ | Optional Tags MessageTags // starts with @ | Optional
Source string // starts with : | Optional Source string // starts with : | Optional
Command string // can either be a string or a numeric value | Required Command string // can either be a string or a numeric value | Required
@@ -61,6 +61,9 @@ type Channel struct {
// Channel messages history // Channel messages history
History string History string
// Date of the last message we received in this channel
LastUpdatedDate time.Time
// Users in this channel // Users in this channel
// The map key is the user's nickname // The map key is the user's nickname
// and the user struct holds data about that user // and the user struct holds data about that user
@@ -116,7 +119,6 @@ type MsgFmtOpts struct {
AsErrorMsg bool AsErrorMsg bool
NotImpl bool NotImpl bool
AsDate bool
} }
var unimpl = lipgloss.NewStyle().Foreground(ui.ErrorColor).Render("[UNIMPL]") var unimpl = lipgloss.NewStyle().Foreground(ui.ErrorColor).Render("[UNIMPL]")
@@ -134,19 +136,19 @@ func (m *Message) SetTimestamp() {
// TODO: properly handle error // TODO: properly handle error
log.Fatalln(err) log.Fatalln(err)
} }
m.Timestamp = fmt.Sprintf("[%02d:%02d]", t.Local().Hour(), t.Local().Minute()) m.DateTime = t
} else { } else {
now := time.Now() m.DateTime = time.Now()
m.Timestamp = fmt.Sprintf("[%02d:%02d]", now.Hour(), now.Minute())
} }
} }
func (c *Channel) AppendMsg(timestamp string, fullMsg string, opts MsgFmtOpts) { func (c *Channel) AppendMsg(datetime time.Time, fullMsg string, opts MsgFmtOpts) {
prefixes := "" prefixes := ""
style := ui.DefaultStyle style := ui.DefaultStyle
if opts.WithTimestamp { if opts.WithTimestamp {
prefixes += timestampStyle.Render(timestamp) + " " str := fmt.Sprintf("[%02d:%02d]", datetime.Local().Hour(), datetime.Local().Minute())
prefixes += timestampStyle.Render(str) + " "
} }
if opts.NotImpl { if opts.NotImpl {
@@ -163,8 +165,10 @@ func (c *Channel) AppendMsg(timestamp string, fullMsg string, opts MsgFmtOpts) {
style = errorMsgStyle style = errorMsgStyle
} }
if opts.AsDate { if datetime.Local().Year() > c.LastUpdatedDate.Local().Year() || datetime.Local().YearDay() > c.LastUpdatedDate.YearDay() {
style = dateStyle c.LastUpdatedDate = datetime
dateMsg := fmt.Sprintf("————— %s %d —————", c.LastUpdatedDate.Month().String(), c.LastUpdatedDate.Day())
c.History += dateStyle.Render(dateMsg) + CRLF
} }
c.History += prefixes + style.Render(fullMsg) + CRLF c.History += prefixes + style.Render(fullMsg) + CRLF
@@ -225,18 +229,6 @@ func (c *Client) Register(nick string, password string, channel string) {
c.SendCommand(commands.USER, nick, "0", "*", nick) c.SendCommand(commands.USER, nick, "0", "*", nick)
} }
func (c *Client) SetDay() {
msgOpts := MsgFmtOpts{
AsDate: true,
}
now := time.Now()
msg := fmt.Sprintf("————— %s %d —————", now.Month().String(), now.Day())
c.RootChannel.Value.AppendMsg("", msg, msgOpts)
// TODO: append new day to each channel whenever the day changes
}
func (c *Client) AppendChannel(channel Channel) *Node[Channel] { func (c *Client) AppendChannel(channel Channel) *Node[Channel] {
first := c.RootChannel first := c.RootChannel
last := c.RootChannel.Prev last := c.RootChannel.Prev
+58 -58
View File
@@ -73,7 +73,7 @@ targetsLoop:
current := client.RootChannel current := client.RootChannel
for { for {
if current.Value.Name == target || current.Value.Name == source { if current.Value.Name == target || current.Value.Name == source {
current.Value.AppendMsg(msg.Timestamp, privMsg, msgOpts) current.Value.AppendMsg(msg.DateTime, privMsg, msgOpts)
continue targetsLoop continue targetsLoop
} }
@@ -89,7 +89,7 @@ targetsLoop:
Users: map[string]irc.User{source: {}}, Users: map[string]irc.User{source: {}},
} }
newChannel.AppendMsg(msg.Timestamp, privMsg, msgOpts) newChannel.AppendMsg(msg.DateTime, privMsg, msgOpts)
client.AppendChannel(newChannel) client.AppendChannel(newChannel)
} }
} }
@@ -107,14 +107,14 @@ func handleNotice(msg irc.Message, client *irc.Client) {
for _, target := range targets { for _, target := range targets {
if target == "*" || target == client.Nickname { if target == "*" || target == client.Nickname {
client.RootChannel.Value.AppendMsg(msg.Timestamp, notice, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, notice, msgOpts)
continue continue
} }
current := client.RootChannel current := client.RootChannel
for { for {
if current.Value.Name == targets[0] { if current.Value.Name == targets[0] {
current.Value.AppendMsg(msg.Timestamp, notice, msgOpts) current.Value.AppendMsg(msg.DateTime, notice, msgOpts)
} }
current = current.Next current = current.Next
@@ -144,7 +144,7 @@ func handleJoin(msg irc.Message, client *irc.Client) {
} }
client.ActiveChannel = client.AppendChannel(newChannel) client.ActiveChannel = client.AppendChannel(newChannel)
client.ActiveChannel.Value.AppendMsg(msg.Timestamp, joinMsg, msgOpts) client.ActiveChannel.Value.AppendMsg(msg.DateTime, joinMsg, msgOpts)
if _, exists := client.ActiveChannel.Value.Users[nick]; !exists { if _, exists := client.ActiveChannel.Value.Users[nick]; !exists {
client.ActiveChannel.Value.Users[nick] = irc.User{} client.ActiveChannel.Value.Users[nick] = irc.User{}
@@ -154,7 +154,7 @@ func handleJoin(msg irc.Message, client *irc.Client) {
current := client.RootChannel current := client.RootChannel
for { for {
if current.Value.Name == channel { if current.Value.Name == channel {
current.Value.AppendMsg(msg.Timestamp, joinMsg, msgOpts) current.Value.AppendMsg(msg.DateTime, joinMsg, msgOpts)
if _, exists := current.Value.Users[nick]; !exists { if _, exists := current.Value.Users[nick]; !exists {
current.Value.Users[nick] = irc.User{} current.Value.Users[nick] = irc.User{}
} }
@@ -199,7 +199,7 @@ func handleNick(msg irc.Message, client *irc.Client) {
if user, ok := current.Value.Users[oldNick]; ok { if user, ok := current.Value.Users[oldNick]; ok {
delete(current.Value.Users, oldNick) delete(current.Value.Users, oldNick)
current.Value.Users[newNick] = user current.Value.Users[newNick] = user
current.Value.AppendMsg(msg.Timestamp, message, msgOpts) current.Value.AppendMsg(msg.DateTime, message, msgOpts)
} }
// If we have a private channel open with this user, rename it as well. // If we have a private channel open with this user, rename it as well.
@@ -223,7 +223,7 @@ func handleNick(msg irc.Message, client *irc.Client) {
} }
if isMe { if isMe {
client.RootChannel.Value.AppendMsg(msg.Timestamp, message, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, message, msgOpts)
client.Nickname = newNick client.Nickname = newNick
} }
@@ -261,13 +261,13 @@ func handleKick(msg irc.Message, client *irc.Client) {
client.RemoveChannel(current) client.RemoveChannel(current)
message = fmt.Sprintf("You were kicked by %v from %v (%v)", kicker, channel, reason) message = fmt.Sprintf("You were kicked by %v from %v (%v)", kicker, channel, reason)
client.RootChannel.Value.AppendMsg(msg.Timestamp, message, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, message, msgOpts)
return return
} }
delete(current.Value.Users, nick) delete(current.Value.Users, nick)
current.Value.AppendMsg(msg.Timestamp, message, msgOpts) current.Value.AppendMsg(msg.DateTime, message, msgOpts)
} }
current = current.Next current = current.Next
@@ -296,7 +296,7 @@ func handleQuit(msg irc.Message, client *irc.Client) {
// if i == 0 { // if i == 0 {
// continue // continue
// } // }
current.Value.AppendMsg(msg.Timestamp, quitMsg, msgOpts) current.Value.AppendMsg(msg.DateTime, quitMsg, msgOpts)
delete(current.Value.Users, nick) delete(current.Value.Users, nick)
current = current.Next current = current.Next
@@ -333,7 +333,7 @@ func handlePart(msg irc.Message, client *irc.Client) {
client.RemoveChannel(current) client.RemoveChannel(current)
} else { } else {
current.Value.AppendMsg(msg.Timestamp, partMsg, msgOpts) current.Value.AppendMsg(msg.DateTime, partMsg, msgOpts)
delete(current.Value.Users, nick) delete(current.Value.Users, nick)
} }
@@ -361,7 +361,7 @@ func handleTopic(msg irc.Message, client *irc.Client) {
for { for {
if current.Value.Name == channel { if current.Value.Name == channel {
current.Value.Topic = topic current.Value.Topic = topic
current.Value.AppendMsg(msg.Timestamp, fmt.Sprintf("Topic changed: %v", topic), msgOpts) current.Value.AppendMsg(msg.DateTime, fmt.Sprintf("Topic changed: %v", topic), msgOpts)
break break
} }
@@ -451,7 +451,7 @@ func handleCAP(msg irc.Message, client *irc.Client) {
WithTimestamp: true, WithTimestamp: true,
AsServerMsg: true, AsServerMsg: true,
} }
client.RootChannel.Value.AppendMsg(msg.Timestamp, "Unrecognized capabilities: "+strings.Join(caps, " "), msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, "Unrecognized capabilities: "+strings.Join(caps, " "), msgOpts)
case "DEL": case "DEL":
caps := strings.Split(msg.Parameters[2], " ") caps := strings.Split(msg.Parameters[2], " ")
for _, capability := range caps { for _, capability := range caps {
@@ -472,7 +472,7 @@ func handleWELCOME(msg irc.Message, client *irc.Client) {
// set server-registered nickname because the server MAY return a different nickname than // set server-registered nickname because the server MAY return a different nickname than
// the one the user chose because of length restrictions or otherwise. // the one the user chose because of length restrictions or otherwise.
client.Nickname = nick client.Nickname = nick
client.RootChannel.Value.AppendMsg(msg.Timestamp, welcomeMsg, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, welcomeMsg, msgOpts)
// Only join the user-requested channel AFTER registration is complete. // Only join the user-requested channel AFTER registration is complete.
if client.InitialChannel != "" { if client.InitialChannel != "" {
@@ -488,7 +488,7 @@ func handleYOURHOST(msg irc.Message, client *irc.Client) {
AsServerMsg: true, AsServerMsg: true,
} }
client.RootChannel.Value.AppendMsg(msg.Timestamp, host, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, host, msgOpts)
} }
func handleCREATED(msg irc.Message, client *irc.Client) { func handleCREATED(msg irc.Message, client *irc.Client) {
@@ -499,7 +499,7 @@ func handleCREATED(msg irc.Message, client *irc.Client) {
AsServerMsg: true, AsServerMsg: true,
} }
client.RootChannel.Value.AppendMsg(msg.Timestamp, created, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, created, msgOpts)
} }
func handleMYINFO(msg irc.Message, client *irc.Client) { func handleMYINFO(msg irc.Message, client *irc.Client) {
@@ -510,7 +510,7 @@ func handleMYINFO(msg irc.Message, client *irc.Client) {
AsServerMsg: true, AsServerMsg: true,
} }
client.RootChannel.Value.AppendMsg(msg.Timestamp, info, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, info, msgOpts)
} }
func handleISUPPORT(msg irc.Message, client *irc.Client) { func handleISUPPORT(msg irc.Message, client *irc.Client) {
@@ -537,7 +537,7 @@ func handleISUPPORT(msg irc.Message, client *irc.Client) {
log.Printf("Unknown feature: \"%v\" with value: \"%v\"\n", key, value) log.Printf("Unknown feature: \"%v\" with value: \"%v\"\n", key, value)
} }
client.RootChannel.Value.AppendMsg(msg.Timestamp, token, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, token, msgOpts)
} }
} }
@@ -549,7 +549,7 @@ func handleLUSERCLIENT(msg irc.Message, client *irc.Client) {
AsServerMsg: true, AsServerMsg: true,
} }
client.RootChannel.Value.AppendMsg(msg.Timestamp, message, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, message, msgOpts)
} }
func handleLUSEROP(msg irc.Message, client *irc.Client) { func handleLUSEROP(msg irc.Message, client *irc.Client) {
@@ -560,7 +560,7 @@ func handleLUSEROP(msg irc.Message, client *irc.Client) {
AsServerMsg: true, AsServerMsg: true,
} }
client.RootChannel.Value.AppendMsg(msg.Timestamp, message, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, message, msgOpts)
} }
func handleLUSERUNKNOWN(msg irc.Message, client *irc.Client) { func handleLUSERUNKNOWN(msg irc.Message, client *irc.Client) {
@@ -571,7 +571,7 @@ func handleLUSERUNKNOWN(msg irc.Message, client *irc.Client) {
AsServerMsg: true, AsServerMsg: true,
} }
client.RootChannel.Value.AppendMsg(msg.Timestamp, message, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, message, msgOpts)
} }
func handleLUSERCHANNELS(msg irc.Message, client *irc.Client) { func handleLUSERCHANNELS(msg irc.Message, client *irc.Client) {
@@ -582,7 +582,7 @@ func handleLUSERCHANNELS(msg irc.Message, client *irc.Client) {
AsServerMsg: true, AsServerMsg: true,
} }
client.RootChannel.Value.AppendMsg(msg.Timestamp, message, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, message, msgOpts)
} }
func handleLUSERME(msg irc.Message, client *irc.Client) { func handleLUSERME(msg irc.Message, client *irc.Client) {
@@ -593,7 +593,7 @@ func handleLUSERME(msg irc.Message, client *irc.Client) {
AsServerMsg: true, AsServerMsg: true,
} }
client.RootChannel.Value.AppendMsg(msg.Timestamp, message, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, message, msgOpts)
} }
func handleLOCALUSERS(msg irc.Message, client *irc.Client) { func handleLOCALUSERS(msg irc.Message, client *irc.Client) {
@@ -610,7 +610,7 @@ func handleLOCALUSERS(msg irc.Message, client *irc.Client) {
AsServerMsg: true, AsServerMsg: true,
} }
client.RootChannel.Value.AppendMsg(msg.Timestamp, message, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, message, msgOpts)
} }
func handleGLOBALUSERS(msg irc.Message, client *irc.Client) { func handleGLOBALUSERS(msg irc.Message, client *irc.Client) {
@@ -627,7 +627,7 @@ func handleGLOBALUSERS(msg irc.Message, client *irc.Client) {
AsServerMsg: true, AsServerMsg: true,
} }
client.RootChannel.Value.AppendMsg(msg.Timestamp, message, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, message, msgOpts)
} }
func handleAWAY(msg irc.Message, client *irc.Client) { func handleAWAY(msg irc.Message, client *irc.Client) {
@@ -640,7 +640,7 @@ func handleAWAY(msg irc.Message, client *irc.Client) {
AsServerMsg: true, AsServerMsg: true,
} }
client.RootChannel.Value.AppendMsg(msg.Timestamp, awayMsg, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, awayMsg, msgOpts)
} }
func handleUNAWAY(msg irc.Message, client *irc.Client) { func handleUNAWAY(msg irc.Message, client *irc.Client) {
@@ -651,7 +651,7 @@ func handleUNAWAY(msg irc.Message, client *irc.Client) {
AsServerMsg: true, AsServerMsg: true,
} }
client.RootChannel.Value.AppendMsg(msg.Timestamp, message, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, message, msgOpts)
} }
func handleNOWAWAY(msg irc.Message, client *irc.Client) { func handleNOWAWAY(msg irc.Message, client *irc.Client) {
@@ -662,7 +662,7 @@ func handleNOWAWAY(msg irc.Message, client *irc.Client) {
AsServerMsg: true, AsServerMsg: true,
} }
client.RootChannel.Value.AppendMsg(msg.Timestamp, message, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, message, msgOpts)
} }
func handleWHOISUSER(msg irc.Message, client *irc.Client) { func handleWHOISUSER(msg irc.Message, client *irc.Client) {
@@ -684,8 +684,8 @@ func handleWHOISUSER(msg irc.Message, client *irc.Client) {
realName, realName,
) )
client.RootChannel.Value.AppendMsg(msg.Timestamp, "WHOIS Information", msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, "WHOIS Information", msgOpts)
client.RootChannel.Value.AppendMsg(msg.Timestamp, message, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, message, msgOpts)
} }
func handleWHOISSERVER(msg irc.Message, client *irc.Client) { func handleWHOISSERVER(msg irc.Message, client *irc.Client) {
@@ -703,7 +703,7 @@ func handleWHOISSERVER(msg irc.Message, client *irc.Client) {
serverInfo, serverInfo,
) )
client.RootChannel.Value.AppendMsg(msg.Timestamp, message, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, message, msgOpts)
} }
func handleWHOISIDLE(msg irc.Message, client *irc.Client) { func handleWHOISIDLE(msg irc.Message, client *irc.Client) {
@@ -727,7 +727,7 @@ func handleWHOISIDLE(msg irc.Message, client *irc.Client) {
idleSeconds, idleSeconds,
since.Format(time.ANSIC), since.Format(time.ANSIC),
) )
client.RootChannel.Value.AppendMsg(msg.Timestamp, message, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, message, msgOpts)
} }
func handleENDOFWHOIS(msg irc.Message, client *irc.Client) { func handleENDOFWHOIS(msg irc.Message, client *irc.Client) {
@@ -738,7 +738,7 @@ func handleENDOFWHOIS(msg irc.Message, client *irc.Client) {
AsServerMsg: true, AsServerMsg: true,
} }
client.RootChannel.Value.AppendMsg(msg.Timestamp, message, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, message, msgOpts)
} }
func handleWHOISCHANNELS(msg irc.Message, client *irc.Client) { func handleWHOISCHANNELS(msg irc.Message, client *irc.Client) {
@@ -751,7 +751,7 @@ func handleWHOISCHANNELS(msg irc.Message, client *irc.Client) {
message := fmt.Sprintf("channels: %s", chans) message := fmt.Sprintf("channels: %s", chans)
client.RootChannel.Value.AppendMsg(msg.Timestamp, message, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, message, msgOpts)
} }
func handleNOTOPIC(msg irc.Message, client *irc.Client) { func handleNOTOPIC(msg irc.Message, client *irc.Client) {
@@ -765,7 +765,7 @@ func handleNOTOPIC(msg irc.Message, client *irc.Client) {
current := client.RootChannel current := client.RootChannel
for { for {
if current.Value.Name == channel { if current.Value.Name == channel {
current.Value.AppendMsg(msg.Timestamp, msgStr, msgOpts) current.Value.AppendMsg(msg.DateTime, msgStr, msgOpts)
break break
} }
@@ -788,7 +788,7 @@ func handleTOPIC(msg irc.Message, client *irc.Client) {
for { for {
if current.Value.Name == channel { if current.Value.Name == channel {
current.Value.Topic = topic current.Value.Topic = topic
current.Value.AppendMsg(msg.Timestamp, fmt.Sprintf("TOPIC: %v", topic), msgOpts) current.Value.AppendMsg(msg.DateTime, fmt.Sprintf("TOPIC: %v", topic), msgOpts)
break break
} }
@@ -814,7 +814,7 @@ func handleVERSION(msg irc.Message, client *irc.Client) {
AsServerMsg: true, AsServerMsg: true,
} }
client.RootChannel.Value.AppendMsg(msg.Timestamp, versionMsg, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, versionMsg, msgOpts)
} }
func handleNAMREPLY(msg irc.Message, client *irc.Client) { func handleNAMREPLY(msg irc.Message, client *irc.Client) {
@@ -863,7 +863,7 @@ func handleINFO(msg irc.Message, client *irc.Client) {
AsServerMsg: true, AsServerMsg: true,
} }
client.RootChannel.Value.AppendMsg(msg.Timestamp, message, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, message, msgOpts)
} }
func handleENDOFINFO(msg irc.Message, client *irc.Client) { func handleENDOFINFO(msg irc.Message, client *irc.Client) {
@@ -874,7 +874,7 @@ func handleENDOFINFO(msg irc.Message, client *irc.Client) {
AsServerMsg: true, AsServerMsg: true,
} }
client.RootChannel.Value.AppendMsg(msg.Timestamp, message, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, message, msgOpts)
} }
func handleMOTDStart(msg irc.Message, client *irc.Client) { func handleMOTDStart(msg irc.Message, client *irc.Client) {
@@ -885,7 +885,7 @@ func handleMOTDStart(msg irc.Message, client *irc.Client) {
AsServerMsg: true, AsServerMsg: true,
} }
client.RootChannel.Value.AppendMsg(msg.Timestamp, message, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, message, msgOpts)
} }
func handleMOTD(msg irc.Message, client *irc.Client) { func handleMOTD(msg irc.Message, client *irc.Client) {
@@ -896,7 +896,7 @@ func handleMOTD(msg irc.Message, client *irc.Client) {
AsServerMsg: true, AsServerMsg: true,
} }
client.RootChannel.Value.AppendMsg(msg.Timestamp, messageLine, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, messageLine, msgOpts)
} }
func handleWHOISHOST(msg irc.Message, client *irc.Client) { func handleWHOISHOST(msg irc.Message, client *irc.Client) {
@@ -907,7 +907,7 @@ func handleWHOISHOST(msg irc.Message, client *irc.Client) {
AsServerMsg: true, AsServerMsg: true,
} }
client.RootChannel.Value.AppendMsg(msg.Timestamp, message, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, message, msgOpts)
} }
func handleWHOISMODES(msg irc.Message, client *irc.Client) { func handleWHOISMODES(msg irc.Message, client *irc.Client) {
@@ -918,7 +918,7 @@ func handleWHOISMODES(msg irc.Message, client *irc.Client) {
AsServerMsg: true, AsServerMsg: true,
} }
client.RootChannel.Value.AppendMsg(msg.Timestamp, message, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, message, msgOpts)
} }
func handleNOSUCHNICK(msg irc.Message, client *irc.Client) { func handleNOSUCHNICK(msg irc.Message, client *irc.Client) {
@@ -929,7 +929,7 @@ func handleNOSUCHNICK(msg irc.Message, client *irc.Client) {
AsErrorMsg: true, AsErrorMsg: true,
} }
client.RootChannel.Value.AppendMsg(msg.Timestamp, message, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, message, msgOpts)
} }
func handleNOSUCHSERVER(msg irc.Message, client *irc.Client) { func handleNOSUCHSERVER(msg irc.Message, client *irc.Client) {
@@ -940,7 +940,7 @@ func handleNOSUCHSERVER(msg irc.Message, client *irc.Client) {
AsErrorMsg: true, AsErrorMsg: true,
} }
client.RootChannel.Value.AppendMsg(msg.Timestamp, message, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, message, msgOpts)
} }
func handleNOSUCHCHANNEL(msg irc.Message, client *irc.Client) { func handleNOSUCHCHANNEL(msg irc.Message, client *irc.Client) {
@@ -953,7 +953,7 @@ func handleNOSUCHCHANNEL(msg irc.Message, client *irc.Client) {
AsErrorMsg: true, AsErrorMsg: true,
} }
client.RootChannel.Value.AppendMsg(msg.Timestamp, message, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, message, msgOpts)
} }
func handleCANNOTSENDTOCHAN(msg irc.Message, client *irc.Client) { func handleCANNOTSENDTOCHAN(msg irc.Message, client *irc.Client) {
@@ -968,7 +968,7 @@ func handleCANNOTSENDTOCHAN(msg irc.Message, client *irc.Client) {
current := client.RootChannel current := client.RootChannel
for { for {
if current.Value.Name == channel { if current.Value.Name == channel {
current.Value.AppendMsg(msg.Timestamp, message, msgOpts) current.Value.AppendMsg(msg.DateTime, message, msgOpts)
return return
} }
@@ -979,7 +979,7 @@ func handleCANNOTSENDTOCHAN(msg irc.Message, client *irc.Client) {
} }
message = fmt.Sprintf("%v: %v", channel, message) message = fmt.Sprintf("%v: %v", channel, message)
client.RootChannel.Value.AppendMsg(msg.Timestamp, message, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, message, msgOpts)
} }
func handleTOOMANYCHANNELS(msg irc.Message, client *irc.Client) { func handleTOOMANYCHANNELS(msg irc.Message, client *irc.Client) {
@@ -991,7 +991,7 @@ func handleTOOMANYCHANNELS(msg irc.Message, client *irc.Client) {
AsErrorMsg: true, AsErrorMsg: true,
} }
client.RootChannel.Value.AppendMsg(msg.Timestamp, fmt.Sprintf("%v: %v", channel, message), msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, fmt.Sprintf("%v: %v", channel, message), msgOpts)
} }
func handleUNKNOWNCOMMAND(msg irc.Message, client *irc.Client) { func handleUNKNOWNCOMMAND(msg irc.Message, client *irc.Client) {
@@ -1002,7 +1002,7 @@ func handleUNKNOWNCOMMAND(msg irc.Message, client *irc.Client) {
AsErrorMsg: true, AsErrorMsg: true,
} }
client.RootChannel.Value.AppendMsg(msg.Timestamp, message, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, message, msgOpts)
} }
func handleNOMOTD(msg irc.Message, client *irc.Client) { func handleNOMOTD(msg irc.Message, client *irc.Client) {
@@ -1013,7 +1013,7 @@ func handleNOMOTD(msg irc.Message, client *irc.Client) {
AsServerMsg: true, AsServerMsg: true,
} }
client.RootChannel.Value.AppendMsg(msg.Timestamp, message, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, message, msgOpts)
} }
func handleNONICKNAMEGIVEN(msg irc.Message, client *irc.Client) { func handleNONICKNAMEGIVEN(msg irc.Message, client *irc.Client) {
@@ -1024,7 +1024,7 @@ func handleNONICKNAMEGIVEN(msg irc.Message, client *irc.Client) {
AsServerMsg: true, AsServerMsg: true,
} }
client.RootChannel.Value.AppendMsg(msg.Timestamp, message, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, message, msgOpts)
} }
func handleNEEDMOREPARAMS(msg irc.Message, client *irc.Client) { func handleNEEDMOREPARAMS(msg irc.Message, client *irc.Client) {
@@ -1035,7 +1035,7 @@ func handleNEEDMOREPARAMS(msg irc.Message, client *irc.Client) {
AsErrorMsg: true, AsErrorMsg: true,
} }
client.RootChannel.Value.AppendMsg(msg.Timestamp, message, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, message, msgOpts)
} }
func handleALREADYREGISTERED(msg irc.Message, client *irc.Client) { func handleALREADYREGISTERED(msg irc.Message, client *irc.Client) {
@@ -1046,7 +1046,7 @@ func handleALREADYREGISTERED(msg irc.Message, client *irc.Client) {
AsServerMsg: true, AsServerMsg: true,
} }
client.RootChannel.Value.AppendMsg(msg.Timestamp, message, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, message, msgOpts)
} }
func handleBADCHANMASK(msg irc.Message, client *irc.Client) { func handleBADCHANMASK(msg irc.Message, client *irc.Client) {
@@ -1058,7 +1058,7 @@ func handleBADCHANMASK(msg irc.Message, client *irc.Client) {
AsErrorMsg: true, AsErrorMsg: true,
} }
client.RootChannel.Value.AppendMsg(msg.Timestamp, fmt.Sprintf("%v: %v", channel, message), msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, fmt.Sprintf("%v: %v", channel, message), msgOpts)
} }
func handleCHANOPRIVSNEEDED(msg irc.Message, client *irc.Client) { func handleCHANOPRIVSNEEDED(msg irc.Message, client *irc.Client) {
@@ -1073,7 +1073,7 @@ func handleCHANOPRIVSNEEDED(msg irc.Message, client *irc.Client) {
current := client.RootChannel current := client.RootChannel
for { for {
if current.Value.Name == channel { if current.Value.Name == channel {
current.Value.AppendMsg(msg.Timestamp, message, msgOpts) current.Value.AppendMsg(msg.DateTime, message, msgOpts)
break break
} }
@@ -1217,7 +1217,7 @@ func HandleCommand(msg irc.Message, client *irc.Client) {
NotImpl: true, NotImpl: true,
} }
client.RootChannel.Value.AppendMsg(msg.Timestamp, fullMsg, msgOpts) client.RootChannel.Value.AppendMsg(msg.DateTime, fullMsg, msgOpts)
} }
// send a receivedIRCmsg tea message so the ui can update // send a receivedIRCmsg tea message so the ui can update
+2 -3
View File
@@ -41,7 +41,6 @@ func handleSlashPrivMsg(params []string, client *irc.Client) tea.Cmd {
WithTimestamp: true, WithTimestamp: true,
} }
now := time.Now() now := time.Now()
timestamp := fmt.Sprintf("[%02d:%02d]", now.Hour(), now.Minute())
msg := fmt.Sprintf("%s: %s", client.Nickname, strings.Join(params[1:], " ")) msg := fmt.Sprintf("%s: %s", client.Nickname, strings.Join(params[1:], " "))
c := client.RootChannel c := client.RootChannel
@@ -49,7 +48,7 @@ func handleSlashPrivMsg(params []string, client *irc.Client) tea.Cmd {
if c.Value.Name == target { if c.Value.Name == target {
client.ActiveChannel = c client.ActiveChannel = c
c.Value.AppendMsg(timestamp, msg, msgOpts) c.Value.AppendMsg(now, msg, msgOpts)
client.SendCommand(commands.PRIVMSG, params...) client.SendCommand(commands.PRIVMSG, params...)
return cmds.SwitchChannels return cmds.SwitchChannels
@@ -68,7 +67,7 @@ func handleSlashPrivMsg(params []string, client *irc.Client) tea.Cmd {
Users: map[string]irc.User{target: {}}, Users: map[string]irc.User{target: {}},
} }
newChannel.AppendMsg(timestamp, msg, msgOpts) newChannel.AppendMsg(now, msg, msgOpts)
client.ActiveChannel = client.AppendChannel(newChannel) client.ActiveChannel = client.AppendChannel(newChannel)
batchedCmds = append(batchedCmds, cmds.UpdateTabBar) batchedCmds = append(batchedCmds, cmds.UpdateTabBar)
-1
View File
@@ -104,7 +104,6 @@ func (s State) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
s.Client.Initialize(host, port, tlsEnabled) s.Client.Initialize(host, port, tlsEnabled)
s.Client.Register(nickname, password, channel) s.Client.Register(nickname, password, channel)
s.Client.SetDay()
s.UI.MainScreen.SetSize(s.TerminalWidth, s.TerminalHeight) s.UI.MainScreen.SetSize(s.TerminalWidth, s.TerminalHeight)
+1 -1
View File
@@ -94,7 +94,7 @@ func (s State) Update(msg tea.Msg) (State, tea.Cmd) {
WithTimestamp: true, WithTimestamp: true,
} }
s.Client.ActiveChannel.Value.AppendMsg(msg.Timestamp, fullMsg, msgOpts) s.Client.ActiveChannel.Value.AppendMsg(msg.Datetime, fullMsg, msgOpts)
// TODO: make sure to only append the message to the history if server sends back no errors // 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.Value.Name, msg.Msg) s.Client.SendCommand(commands.PRIVMSG, s.Client.ActiveChannel.Value.Name, msg.Msg)
s.Viewport.SetContent(s.Client.ActiveChannel.Value.History) s.Viewport.SetContent(s.Client.ActiveChannel.Value.History)