]> git.giacomolli.uk - onechat/blobdiff - whatsapp_import.go
Log daemon events at their slog levels
[onechat] / whatsapp_import.go
index ef2bcbabd9cd4a7dc70b836448ff4e7553102e1b..7071c8369495d05e29463f95bcaec5390d1147ab 100644 (file)
@@ -211,7 +211,7 @@ func (p WhatsAppImportPlan) Write(out io.Writer) error {
                "owner: " + owner,
                fmt.Sprintf("bytes: %d (new batch text)", p.bytes),
                fmt.Sprintf("messages: %d (merged log)", p.messages),
                "owner: " + owner,
                fmt.Sprintf("bytes: %d (new batch text)", p.bytes),
                fmt.Sprintf("messages: %d (merged log)", p.messages),
-               fmt.Sprintf("estimated calls: %.0f (about 1.3 per message, limit %d)", estimate, buildCallLimit),
+               fmt.Sprintf("estimated calls: %.0f (about 1.3 per message, limit %d)", estimate, rebuildCallLimit),
        }
 
        _, err = io.WriteString(out, strings.Join(lines, "\n")+"\n")
        }
 
        _, err = io.WriteString(out, strings.Join(lines, "\n")+"\n")
@@ -296,6 +296,7 @@ func whatsappImportNames(ctx context.Context, dir string) (names map[string]What
        }
 
        var state WhatsAppStateFile
        }
 
        var state WhatsAppStateFile
+
        err = json.Unmarshal(data, &state)
        if err != nil {
                return nil, "", fmt.Errorf("decode pending import names: %w", err)
        err = json.Unmarshal(data, &state)
        if err != nil {
                return nil, "", fmt.Errorf("decode pending import names: %w", err)
@@ -451,6 +452,7 @@ func whatsappImportPlan(ctx context.Context, paths []string, old []DatedMessage,
        }
 
        var err error
        }
 
        var err error
+
        plan.added, err = rebuildMerge(nil, plan.added)
        if err != nil {
                return plan, fmt.Errorf("order import batches: %w", err)
        plan.added, err = rebuildMerge(nil, plan.added)
        if err != nil {
                return plan, fmt.Errorf("order import batches: %w", err)
@@ -485,6 +487,7 @@ func whatsappImportRead(path, owner string, location *time.Location) (chat Whats
        }()
 
        var file *zip.File
        }()
 
        var file *zip.File
+
        for _, entry := range archive.File {
                if filepath.Base(entry.Name) == "_chat.txt" && !entry.FileInfo().IsDir() {
                        if file != nil {
        for _, entry := range archive.File {
                if filepath.Base(entry.Name) == "_chat.txt" && !entry.FileInfo().IsDir() {
                        if file != nil {
@@ -517,6 +520,7 @@ func whatsappImportRead(path, owner string, location *time.Location) (chat Whats
 
        scanner := bufio.NewScanner(io.LimitReader(reader, whatsappImportBytes+1))
        scanner.Buffer(make([]byte, 64*1024), buildLineBytes)
 
        scanner := bufio.NewScanner(io.LimitReader(reader, whatsappImportBytes+1))
        scanner.Buffer(make([]byte, 64*1024), buildLineBytes)
+
        for scanner.Scan() {
                line := strings.ReplaceAll(scanner.Text(), "\u200e", "")
                match := whatsappImportStart.FindStringSubmatch(line)
        for scanner.Scan() {
                line := strings.ReplaceAll(scanner.Text(), "\u200e", "")
                match := whatsappImportStart.FindStringSubmatch(line)