Browse Source

changes from discussion

tags/v1.1.0-rc1
Shivaram Lingamneni 5 years ago
parent
commit
c0b554e98c
3 changed files with 27 additions and 18 deletions
  1. 13
    7
      irc/client.go
  2. 1
    1
      irc/commands.go
  3. 13
    10
      irc/handlers.go

+ 13
- 7
irc/client.go View File

@@ -580,14 +580,14 @@ func (session *Session) playResume() {
580 580
 
581 581
 	timestamp := session.resumeDetails.Timestamp
582 582
 	gap := lastDiscarded.Sub(timestamp)
583
-	session.resumeDetails.HistoryIncomplete = gap > 0
583
+	session.resumeDetails.HistoryIncomplete = gap > 0 || timestamp.IsZero()
584 584
 	gapSeconds := int(gap.Seconds()) + 1 // round up to avoid confusion
585 585
 
586 586
 	details := client.Details()
587 587
 	oldNickmask := details.nickMask
588 588
 	client.SetRawHostname(session.rawHostname)
589 589
 	hostname := client.Hostname() // may be a vhost
590
-	timestampString := session.resumeDetails.Timestamp.Format(IRCv3TimestampFormat)
590
+	timestampString := timestamp.Format(IRCv3TimestampFormat)
591 591
 
592 592
 	// send quit/resume messages to friends
593 593
 	for friend := range friends {
@@ -596,23 +596,29 @@ func (session *Session) playResume() {
596 596
 		}
597 597
 		for _, fSession := range friend.Sessions() {
598 598
 			if fSession.capabilities.Has(caps.Resume) {
599
-				if session.resumeDetails.HistoryIncomplete {
599
+				if !session.resumeDetails.HistoryIncomplete {
600
+					fSession.Send(nil, oldNickmask, "RESUMED", hostname, "ok")
601
+				} else if session.resumeDetails.HistoryIncomplete && !timestamp.IsZero() {
600 602
 					fSession.Send(nil, oldNickmask, "RESUMED", hostname, timestampString)
601 603
 				} else {
602 604
 					fSession.Send(nil, oldNickmask, "RESUMED", hostname)
603 605
 				}
604 606
 			} else {
605
-				if session.resumeDetails.HistoryIncomplete {
606
-					fSession.Send(nil, oldNickmask, "QUIT", fmt.Sprintf(friend.t("Client reconnected (up to %d seconds of history lost)"), gapSeconds))
607
-				} else {
607
+				if !session.resumeDetails.HistoryIncomplete {
608 608
 					fSession.Send(nil, oldNickmask, "QUIT", fmt.Sprintf(friend.t("Client reconnected")))
609
+				} else if session.resumeDetails.HistoryIncomplete && !timestamp.IsZero() {
610
+					fSession.Send(nil, oldNickmask, "QUIT", fmt.Sprintf(friend.t("Client reconnected (up to %d seconds of message history lost)"), gapSeconds))
611
+				} else {
612
+					fSession.Send(nil, oldNickmask, "QUIT", fmt.Sprintf(friend.t("Client reconnected (message history may have been lost)")))
609 613
 				}
610 614
 			}
611 615
 		}
612 616
 	}
613 617
 
614
-	if session.resumeDetails.HistoryIncomplete {
618
+	if session.resumeDetails.HistoryIncomplete && !timestamp.IsZero() {
615 619
 		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))
620
+	} else {
621
+		session.Send(nil, client.server.name, "WARN", "RESUME", "HISTORY_LOST", client.t("Resume may have lost some message history"))
616 622
 	}
617 623
 
618 624
 	session.Send(nil, client.server.name, "RESUME", "SUCCESS", details.nick)

+ 1
- 1
irc/commands.go View File

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

+ 13
- 10
irc/handlers.go View File

@@ -2359,24 +2359,27 @@ func renameHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re
2359 2359
 	return false
2360 2360
 }
2361 2361
 
2362
-// RESUME <token> <timestamp>
2362
+// RESUME <token> [timestamp]
2363 2363
 func resumeHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool {
2364
-	if client.registered {
2365
-		rb.Add(nil, server.name, "FAIL", "RESUME", "REGISTRATION_IS_COMPLETED", client.t("Cannot resume connection, connection registration has already been completed"))
2366
-		return false
2364
+	details := ResumeDetails{
2365
+		PresentedToken: msg.Params[0],
2367 2366
 	}
2368 2367
 
2369
-	ts, err := time.Parse(IRCv3TimestampFormat, msg.Params[1])
2370
-	if err != nil {
2371
-		rb.Add(nil, server.name, "FAIL", "RESUME", "INVALID_TIMESTAMP", client.t("Cannot resume connection, timestamp is not valid"))
2368
+	if client.registered {
2369
+		rb.Add(nil, server.name, "FAIL", "RESUME", "REGISTRATION_IS_COMPLETED", client.t("Cannot resume connection, connection registration has already been completed"))
2372 2370
 		return false
2373 2371
 	}
2374 2372
 
2375
-	rb.session.resumeDetails = &ResumeDetails{
2376
-		PresentedToken: msg.Params[0],
2377
-		Timestamp:      ts,
2373
+	if 1 < len(msg.Params) {
2374
+		ts, err := time.Parse(IRCv3TimestampFormat, msg.Params[1])
2375
+		if err == nil {
2376
+			details.Timestamp = ts
2377
+		} else {
2378
+			rb.Add(nil, server.name, "WARN", "RESUME", "HISTORY_LOST", client.t("Timestamp is not in 2006-01-02T15:04:05.999Z format, ignoring it"))
2379
+		}
2378 2380
 	}
2379 2381
 
2382
+	rb.session.resumeDetails = &details
2380 2383
 	return false
2381 2384
 }
2382 2385
 

Loading…
Cancel
Save