diff --git a/irc/client.go b/irc/client.go index 14efecd8..2e814ce9 100644 --- a/irc/client.go +++ b/irc/client.go @@ -41,8 +41,7 @@ const ( DefaultMaxLineLen = 512 // IdentTimeout is how long before our ident (username) check times out. - IdentTimeout = time.Second + 500*time.Millisecond - IRCv3TimestampFormat = utils.IRCv3TimestampFormat + IdentTimeout = time.Second + 500*time.Millisecond // limit the number of device IDs a client can use, as a DoS mitigation maxDeviceIDsPerClient = 64 // maximum total read markers that can be stored @@ -1463,7 +1462,7 @@ func (session *Session) sendFromClientInternal(blocking bool, serverTime time.Ti func composeMultilineBatch(batchID, fromNickMask, fromAccount string, isBot bool, tags map[string]string, command, target string, message utils.SplitMessage) (result []ircmsg.Message) { batchStart := ircmsg.MakeMessage(tags, fromNickMask, "BATCH", "+"+batchID, caps.MultilineBatchType, target) - batchStart.SetTag("time", message.Time.Format(IRCv3TimestampFormat)) + batchStart.SetTag("time", message.Time.Format(utils.IRCv3TimestampFormat)) batchStart.SetTag("msgid", message.Msgid) if fromAccount != "*" { batchStart.SetTag("account", fromAccount) @@ -1571,7 +1570,7 @@ func (session *Session) setTimeTag(msg *ircmsg.Message, serverTime time.Time) { if serverTime.IsZero() { serverTime = time.Now() } - msg.SetTag("time", serverTime.UTC().Format(IRCv3TimestampFormat)) + msg.SetTag("time", serverTime.UTC().Format(utils.IRCv3TimestampFormat)) } } diff --git a/irc/getters.go b/irc/getters.go index 902614f7..29f97c75 100644 --- a/irc/getters.go +++ b/irc/getters.go @@ -517,7 +517,7 @@ func (client *Client) GetReadMarker(cfname string) (result string) { t, ok := client.readMarkers[cfname] client.stateMutex.RUnlock() if ok { - return fmt.Sprintf("timestamp=%s", t.Format(IRCv3TimestampFormat)) + return fmt.Sprintf("timestamp=%s", t.Format(utils.IRCv3TimestampFormat)) } return "*" } diff --git a/irc/handlers.go b/irc/handlers.go index d0d619c0..538c2126 100644 --- a/irc/handlers.go +++ b/irc/handlers.go @@ -719,7 +719,7 @@ func chathistoryHandler(server *Server, client *Client, msg ircmsg.Message, rb * for _, target := range targets { name := server.UnfoldName(target.CfName) rb.Add(nil, server.name, "CHATHISTORY", "TARGETS", name, - target.Time.Format(IRCv3TimestampFormat)) + target.Time.Format(utils.IRCv3TimestampFormat)) } } else if channel != nil { channel.replayHistoryItems(rb, items, true) @@ -754,7 +754,7 @@ func chathistoryHandler(server *Server, client *Client, msg ircmsg.Message, rb * msgid, err = history.NormalizeMsgid(value), nil return } else if identifier == "timestamp" { - timestamp, err = time.Parse(IRCv3TimestampFormat, value) + timestamp, err = time.Parse(utils.IRCv3TimestampFormat, value) if err == nil { timestamp = timestamp.UTC() if timestamp.Before(unixEpoch) { @@ -3055,14 +3055,14 @@ func markReadHandler(server *Server, client *Client, msg ircmsg.Message, rb *Res // "MARKREAD client set command": MARKREAD readTimestamp := strings.TrimPrefix(msg.Params[1], "timestamp=") - readTime, err := time.Parse(IRCv3TimestampFormat, readTimestamp) + readTime, err := time.Parse(utils.IRCv3TimestampFormat, readTimestamp) if err != nil { rb.Add(nil, server.name, "FAIL", "MARKREAD", "INVALID_PARAMS", utils.SafeErrorParam(readTimestamp), client.t("Invalid timestamp")) return } readTime = readTime.UTC() result := client.SetReadMarker(cftarget, readTime) - readTimestamp = fmt.Sprintf("timestamp=%s", result.Format(IRCv3TimestampFormat)) + readTimestamp = fmt.Sprintf("timestamp=%s", result.Format(utils.IRCv3TimestampFormat)) // inform the originating session whether it was a success or a no-op: rb.Add(nil, server.name, "MARKREAD", unfoldedTarget, readTimestamp) if result.Equal(readTime) { diff --git a/irc/histserv.go b/irc/histserv.go index 8e28dafc..35b2e9b4 100644 --- a/irc/histserv.go +++ b/irc/histserv.go @@ -164,7 +164,7 @@ func histservExportHandler(service *ircService, server *Server, client *Client, config := server.Config() // don't include the account name in the filename because of escaping concerns - filename := fmt.Sprintf("%s-%s.json", utils.GenerateSecretToken(), time.Now().UTC().Format(IRCv3TimestampFormat)) + filename := fmt.Sprintf("%s-%s.json", utils.GenerateSecretToken(), time.Now().UTC().Format(utils.IRCv3TimestampFormat)) pathname := config.getOutputPath(filename) outfile, err := os.Create(pathname) if err != nil { diff --git a/irc/message_cache.go b/irc/message_cache.go index 2d731823..f56568b3 100644 --- a/irc/message_cache.go +++ b/irc/message_cache.go @@ -45,7 +45,7 @@ type MessageCache struct { func addAllTags(msg *ircmsg.Message, tags map[string]string, serverTime time.Time, msgid, accountName string, isBot bool) { msg.UpdateTags(tags) - msg.SetTag("time", serverTime.Format(IRCv3TimestampFormat)) + msg.SetTag("time", serverTime.Format(utils.IRCv3TimestampFormat)) if accountName != "*" { msg.SetTag("account", accountName) }