Browse Source

fix #836

tags/v2.0.0-rc1
Shivaram Lingamneni 4 years ago
parent
commit
3e01e9995b
3 changed files with 39 additions and 5 deletions
  1. 2
    2
      irc/accounts.go
  2. 33
    1
      irc/database.go
  3. 4
    2
      irc/server.go

+ 2
- 2
irc/accounts.go View File

@@ -378,7 +378,7 @@ func (am *AccountManager) Register(client *Client, account string, callbackNames
378 378
 		return err
379 379
 	}
380 380
 
381
-	registeredTimeStr := strconv.FormatInt(time.Now().Unix(), 10)
381
+	registeredTimeStr := strconv.FormatInt(time.Now().UnixNano(), 10)
382 382
 	callbackSpec := fmt.Sprintf("%s:%s", callbackNamespace, callbackValue)
383 383
 
384 384
 	var setOptions *buntdb.SetOptions
@@ -998,7 +998,7 @@ func (am *AccountManager) deserializeRawAccount(raw rawClientAccount, cfName str
998 998
 	result.Name = raw.Name
999 999
 	result.NameCasefolded = cfName
1000 1000
 	regTimeInt, _ := strconv.ParseInt(raw.RegisteredAt, 10, 64)
1001
-	result.RegisteredAt = time.Unix(regTimeInt, 0).UTC()
1001
+	result.RegisteredAt = time.Unix(0, regTimeInt).UTC()
1002 1002
 	e := json.Unmarshal([]byte(raw.Credentials), &result.Credentials)
1003 1003
 	if e != nil {
1004 1004
 		am.server.logger.Error("internal", "could not unmarshal credentials", e.Error())

+ 33
- 1
irc/database.go View File

@@ -9,6 +9,7 @@ import (
9 9
 	"fmt"
10 10
 	"log"
11 11
 	"os"
12
+	"strconv"
12 13
 	"strings"
13 14
 	"time"
14 15
 
@@ -22,7 +23,7 @@ const (
22 23
 	// 'version' of the database schema
23 24
 	keySchemaVersion = "db.version"
24 25
 	// latest schema of the db
25
-	latestDbSchema = "9"
26
+	latestDbSchema = "10"
26 27
 )
27 28
 
28 29
 type SchemaChanger func(*Config, *buntdb.Tx) error
@@ -594,6 +595,32 @@ func schemaChangeV8ToV9(config *Config, tx *buntdb.Tx) error {
594 595
 	return nil
595 596
 }
596 597
 
598
+// #836: account registration time at nanosecond resolution
599
+// (mostly to simplify testing)
600
+func schemaChangeV9ToV10(config *Config, tx *buntdb.Tx) error {
601
+	prefix := "account.registered.time "
602
+	var accounts, times []string
603
+	tx.AscendGreaterOrEqual("", prefix, func(key, value string) bool {
604
+		if !strings.HasPrefix(key, prefix) {
605
+			return false
606
+		}
607
+		account := strings.TrimPrefix(key, prefix)
608
+		accounts = append(accounts, account)
609
+		times = append(times, value)
610
+		return true
611
+	})
612
+	for i, account := range accounts {
613
+		time, err := strconv.ParseInt(times[i], 10, 64)
614
+		if err != nil {
615
+			log.Printf("corrupt registration time entry for %s: %v\n", account, err)
616
+			continue
617
+		}
618
+		time = time * 1000000000
619
+		tx.Set(prefix+account, strconv.FormatInt(time, 10), nil)
620
+	}
621
+	return nil
622
+}
623
+
597 624
 func init() {
598 625
 	allChanges := []SchemaChange{
599 626
 		{
@@ -636,6 +663,11 @@ func init() {
636 663
 			TargetVersion:  "9",
637 664
 			Changer:        schemaChangeV8ToV9,
638 665
 		},
666
+		{
667
+			InitialVersion: "9",
668
+			TargetVersion:  "10",
669
+			Changer:        schemaChangeV9ToV10,
670
+		},
639 671
 	}
640 672
 
641 673
 	// build the index

+ 4
- 2
irc/server.go View File

@@ -919,14 +919,16 @@ func (server *Server) GetHistorySequence(providedChannel *Channel, client *Clien
919 919
 	if config.History.Restrictions.ExpireTime != 0 {
920 920
 		cutoff = time.Now().UTC().Add(-time.Duration(config.History.Restrictions.ExpireTime))
921 921
 	}
922
-	if config.History.Restrictions.EnforceRegistrationDate {
922
+	// #836: registration date cutoff is always enforced for DMs
923
+	if config.History.Restrictions.EnforceRegistrationDate || channel == nil {
923 924
 		regCutoff := client.historyCutoff()
924 925
 		// take the later of the two cutoffs
925 926
 		if regCutoff.After(cutoff) {
926 927
 			cutoff = regCutoff
927 928
 		}
928 929
 	}
929
-	if !cutoff.IsZero() {
930
+	// #836 again: grace period is never applied to DMs
931
+	if !cutoff.IsZero() && channel != nil {
930 932
 		cutoff = cutoff.Add(-time.Duration(config.History.Restrictions.GracePeriod))
931 933
 	}
932 934
 

Loading…
Cancel
Save