3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 10:42:52 +01:00

changes from discussion

This commit is contained in:
Shivaram Lingamneni 2019-05-29 07:34:23 -04:00
parent acc9d8c13d
commit c0b554e98c
3 changed files with 27 additions and 18 deletions

View File

@ -580,14 +580,14 @@ func (session *Session) playResume() {
timestamp := session.resumeDetails.Timestamp
gap := lastDiscarded.Sub(timestamp)
session.resumeDetails.HistoryIncomplete = gap > 0
session.resumeDetails.HistoryIncomplete = gap > 0 || timestamp.IsZero()
gapSeconds := int(gap.Seconds()) + 1 // round up to avoid confusion
details := client.Details()
oldNickmask := details.nickMask
client.SetRawHostname(session.rawHostname)
hostname := client.Hostname() // may be a vhost
timestampString := session.resumeDetails.Timestamp.Format(IRCv3TimestampFormat)
timestampString := timestamp.Format(IRCv3TimestampFormat)
// send quit/resume messages to friends
for friend := range friends {
@ -596,23 +596,29 @@ func (session *Session) playResume() {
}
for _, fSession := range friend.Sessions() {
if fSession.capabilities.Has(caps.Resume) {
if session.resumeDetails.HistoryIncomplete {
if !session.resumeDetails.HistoryIncomplete {
fSession.Send(nil, oldNickmask, "RESUMED", hostname, "ok")
} else if session.resumeDetails.HistoryIncomplete && !timestamp.IsZero() {
fSession.Send(nil, oldNickmask, "RESUMED", hostname, timestampString)
} else {
fSession.Send(nil, oldNickmask, "RESUMED", hostname)
}
} else {
if session.resumeDetails.HistoryIncomplete {
fSession.Send(nil, oldNickmask, "QUIT", fmt.Sprintf(friend.t("Client reconnected (up to %d seconds of history lost)"), gapSeconds))
} else {
if !session.resumeDetails.HistoryIncomplete {
fSession.Send(nil, oldNickmask, "QUIT", fmt.Sprintf(friend.t("Client reconnected")))
} else if session.resumeDetails.HistoryIncomplete && !timestamp.IsZero() {
fSession.Send(nil, oldNickmask, "QUIT", fmt.Sprintf(friend.t("Client reconnected (up to %d seconds of message history lost)"), gapSeconds))
} else {
fSession.Send(nil, oldNickmask, "QUIT", fmt.Sprintf(friend.t("Client reconnected (message history may have been lost)")))
}
}
}
}
if session.resumeDetails.HistoryIncomplete {
if session.resumeDetails.HistoryIncomplete && !timestamp.IsZero() {
session.Send(nil, client.server.name, "WARN", "RESUME", "HISTORY_LOST", fmt.Sprintf(client.t("Resume may have lost up to %d seconds of history"), gapSeconds))
} else {
session.Send(nil, client.server.name, "WARN", "RESUME", "HISTORY_LOST", client.t("Resume may have lost some message history"))
}
session.Send(nil, client.server.name, "RESUME", "SUCCESS", details.nick)

View File

@ -232,7 +232,7 @@ func init() {
"RESUME": {
handler: resumeHandler,
usablePreReg: true,
minParams: 2,
minParams: 1,
},
"SAJOIN": {
handler: sajoinHandler,

View File

@ -2359,24 +2359,27 @@ func renameHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re
return false
}
// RESUME <token> <timestamp>
// RESUME <token> [timestamp]
func resumeHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool {
details := ResumeDetails{
PresentedToken: msg.Params[0],
}
if client.registered {
rb.Add(nil, server.name, "FAIL", "RESUME", "REGISTRATION_IS_COMPLETED", client.t("Cannot resume connection, connection registration has already been completed"))
return false
}
ts, err := time.Parse(IRCv3TimestampFormat, msg.Params[1])
if err != nil {
rb.Add(nil, server.name, "FAIL", "RESUME", "INVALID_TIMESTAMP", client.t("Cannot resume connection, timestamp is not valid"))
return false
}
rb.session.resumeDetails = &ResumeDetails{
PresentedToken: msg.Params[0],
Timestamp: ts,
if 1 < len(msg.Params) {
ts, err := time.Parse(IRCv3TimestampFormat, msg.Params[1])
if err == nil {
details.Timestamp = ts
} else {
rb.Add(nil, server.name, "WARN", "RESUME", "HISTORY_LOST", client.t("Timestamp is not in 2006-01-02T15:04:05.999Z format, ignoring it"))
}
}
rb.session.resumeDetails = &details
return false
}