mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-06-07 10:53:07 +03:00
chat: Remove injectTimestamp after 30min stuff
This commit is contained in:
parent
783c607fad
commit
54ce8bb08d
@ -284,7 +284,7 @@ func InitCommands(c *Commands) {
|
|||||||
|
|
||||||
c.Add(Command{
|
c.Add(Command{
|
||||||
Prefix: "/timestamp",
|
Prefix: "/timestamp",
|
||||||
Help: "Timestamps after 30min of inactivity.",
|
Help: "Prefix messages with a timestamp.",
|
||||||
Handler: func(room *Room, msg message.CommandMsg) error {
|
Handler: func(room *Room, msg message.CommandMsg) error {
|
||||||
u := msg.From()
|
u := msg.From()
|
||||||
cfg := u.Config()
|
cfg := u.Config()
|
||||||
|
@ -195,20 +195,8 @@ func (u *User) writeMsg(m Message) error {
|
|||||||
// HandleMsg will render the message to the screen, blocking.
|
// HandleMsg will render the message to the screen, blocking.
|
||||||
func (u *User) HandleMsg(m Message) error {
|
func (u *User) HandleMsg(m Message) error {
|
||||||
u.mu.Lock()
|
u.mu.Lock()
|
||||||
cfg := u.config
|
|
||||||
lastMsg := u.lastMsg
|
|
||||||
u.lastMsg = m.Timestamp()
|
u.lastMsg = m.Timestamp()
|
||||||
injectTimestamp := !lastMsg.IsZero() && cfg.Timestamp && u.lastMsg.Sub(lastMsg) > timestampTimeout
|
|
||||||
u.mu.Unlock()
|
u.mu.Unlock()
|
||||||
|
|
||||||
if injectTimestamp {
|
|
||||||
// Inject a timestamp at most once every timestampTimeout between message intervals
|
|
||||||
ts := NewSystemMsg(fmt.Sprintf("Timestamp: %s", m.Timestamp().UTC().Format(timestampLayout)), u)
|
|
||||||
if err := u.writeMsg(ts); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return u.writeMsg(m)
|
return u.writeMsg(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user