mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-29 07:29:31 +01:00
consolidate some time-setting code
This commit is contained in:
parent
34f11ddb97
commit
8dca545264
@ -1160,12 +1160,7 @@ func (session *Session) sendFromClientInternal(blocking bool, serverTime time.Ti
|
|||||||
msg.SetTag("msgid", msgid)
|
msg.SetTag("msgid", msgid)
|
||||||
}
|
}
|
||||||
// attach server-time
|
// attach server-time
|
||||||
if session.capabilities.Has(caps.ServerTime) {
|
session.setTimeTag(&msg, serverTime)
|
||||||
if serverTime.IsZero() {
|
|
||||||
serverTime = time.Now().UTC()
|
|
||||||
}
|
|
||||||
msg.SetTag("time", serverTime.Format(IRCv3TimestampFormat))
|
|
||||||
}
|
|
||||||
|
|
||||||
return session.SendRawMessage(msg, blocking)
|
return session.SendRawMessage(msg, blocking)
|
||||||
}
|
}
|
||||||
@ -1246,12 +1241,19 @@ func (client *Client) Send(tags map[string]string, prefix string, command string
|
|||||||
|
|
||||||
func (session *Session) Send(tags map[string]string, prefix string, command string, params ...string) (err error) {
|
func (session *Session) Send(tags map[string]string, prefix string, command string, params ...string) (err error) {
|
||||||
msg := ircmsg.MakeMessage(tags, prefix, command, params...)
|
msg := ircmsg.MakeMessage(tags, prefix, command, params...)
|
||||||
if session.capabilities.Has(caps.ServerTime) && !msg.HasTag("time") {
|
session.setTimeTag(&msg, time.Time{})
|
||||||
msg.SetTag("time", time.Now().UTC().Format(IRCv3TimestampFormat))
|
|
||||||
}
|
|
||||||
return session.SendRawMessage(msg, false)
|
return session.SendRawMessage(msg, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (session *Session) setTimeTag(msg *ircmsg.IrcMessage, serverTime time.Time) {
|
||||||
|
if session.capabilities.Has(caps.ServerTime) && !msg.HasTag("time") {
|
||||||
|
if serverTime.IsZero() {
|
||||||
|
serverTime = time.Now()
|
||||||
|
}
|
||||||
|
msg.SetTag("time", serverTime.UTC().Format(IRCv3TimestampFormat))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Notice sends the client a notice from the server.
|
// Notice sends the client a notice from the server.
|
||||||
func (client *Client) Notice(text string) {
|
func (client *Client) Notice(text string) {
|
||||||
client.Send(nil, client.server.name, "NOTICE", client.Nick(), text)
|
client.Send(nil, client.server.name, "NOTICE", client.Nick(), text)
|
||||||
|
@ -93,9 +93,7 @@ func (rb *ResponseBuffer) AddFromClient(time time.Time, msgid string, fromNickMa
|
|||||||
msg.SetTag("msgid", msgid)
|
msg.SetTag("msgid", msgid)
|
||||||
}
|
}
|
||||||
// attach server-time
|
// attach server-time
|
||||||
if rb.session.capabilities.Has(caps.ServerTime) && !msg.HasTag("time") {
|
rb.session.setTimeTag(&msg, time)
|
||||||
msg.SetTag("time", time.UTC().Format(IRCv3TimestampFormat))
|
|
||||||
}
|
|
||||||
|
|
||||||
rb.AddMessage(msg)
|
rb.AddMessage(msg)
|
||||||
}
|
}
|
||||||
@ -223,9 +221,7 @@ func (rb *ResponseBuffer) flushInternal(final bool, blocking bool) error {
|
|||||||
// ACK message
|
// ACK message
|
||||||
message := ircmsg.MakeMessage(nil, rb.session.client.server.name, "ACK")
|
message := ircmsg.MakeMessage(nil, rb.session.client.server.name, "ACK")
|
||||||
message.SetTag(caps.LabelTagName, rb.Label)
|
message.SetTag(caps.LabelTagName, rb.Label)
|
||||||
if rb.session.capabilities.Has(caps.ServerTime) {
|
rb.session.setTimeTag(&message, time.Time{})
|
||||||
message.SetTag("time", time.Now().UTC().Format(IRCv3TimestampFormat))
|
|
||||||
}
|
|
||||||
rb.session.SendRawMessage(message, blocking)
|
rb.session.SendRawMessage(message, blocking)
|
||||||
} else if useLabel && len(rb.messages) == 1 && rb.batchID == "" && final {
|
} else if useLabel && len(rb.messages) == 1 && rb.batchID == "" && final {
|
||||||
// single labeled message
|
// single labeled message
|
||||||
@ -235,9 +231,7 @@ func (rb *ResponseBuffer) flushInternal(final bool, blocking bool) error {
|
|||||||
// send each message out
|
// send each message out
|
||||||
for _, message := range rb.messages {
|
for _, message := range rb.messages {
|
||||||
// attach server-time if needed
|
// attach server-time if needed
|
||||||
if rb.session.capabilities.Has(caps.ServerTime) && !message.HasTag("time") {
|
rb.session.setTimeTag(&message, time.Time{})
|
||||||
message.SetTag("time", time.Now().UTC().Format(IRCv3TimestampFormat))
|
|
||||||
}
|
|
||||||
|
|
||||||
// attach batch ID, unless this message was part of a nested batch and is
|
// attach batch ID, unless this message was part of a nested batch and is
|
||||||
// already tagged
|
// already tagged
|
||||||
|
Loading…
Reference in New Issue
Block a user