3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-23 03:02:48 +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 timestamp := session.resumeDetails.Timestamp
gap := lastDiscarded.Sub(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 gapSeconds := int(gap.Seconds()) + 1 // round up to avoid confusion
details := client.Details() details := client.Details()
oldNickmask := details.nickMask oldNickmask := details.nickMask
client.SetRawHostname(session.rawHostname) client.SetRawHostname(session.rawHostname)
hostname := client.Hostname() // may be a vhost hostname := client.Hostname() // may be a vhost
timestampString := session.resumeDetails.Timestamp.Format(IRCv3TimestampFormat) timestampString := timestamp.Format(IRCv3TimestampFormat)
// send quit/resume messages to friends // send quit/resume messages to friends
for friend := range friends { for friend := range friends {
@ -596,23 +596,29 @@ func (session *Session) playResume() {
} }
for _, fSession := range friend.Sessions() { for _, fSession := range friend.Sessions() {
if fSession.capabilities.Has(caps.Resume) { 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) fSession.Send(nil, oldNickmask, "RESUMED", hostname, timestampString)
} else { } else {
fSession.Send(nil, oldNickmask, "RESUMED", hostname) fSession.Send(nil, oldNickmask, "RESUMED", hostname)
} }
} else { } else {
if session.resumeDetails.HistoryIncomplete { if !session.resumeDetails.HistoryIncomplete {
fSession.Send(nil, oldNickmask, "QUIT", fmt.Sprintf(friend.t("Client reconnected (up to %d seconds of history lost)"), gapSeconds))
} else {
fSession.Send(nil, oldNickmask, "QUIT", fmt.Sprintf(friend.t("Client reconnected"))) 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)) 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) session.Send(nil, client.server.name, "RESUME", "SUCCESS", details.nick)

View File

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

View File

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