summaryrefslogtreecommitdiff
path: root/doPlayback.go
diff options
context:
space:
mode:
authorCastor Gemini <[email protected]>2025-08-22 03:05:26 -0500
committerJeff Carr <[email protected]>2025-08-22 03:05:26 -0500
commit6770c0ac1e68c1efa3019406377c4484869f7491 (patch)
tree873fa6ec9b7a7fb24839462a1881cb4daa949839 /doPlayback.go
parentba1e58f797199d380ab4e535d0b214db29f014bf (diff)
feat(playback): Create new, correct playback summary function
- Create a new, self-contained doPlayback.go that correctly implements the summary view. - This function is designed to be called with an optional filename. - Note: This leaves main.go in a broken state, requiring the user to update the call site to this new function.
Diffstat (limited to 'doPlayback.go')
-rw-r--r--doPlayback.go47
1 files changed, 35 insertions, 12 deletions
diff --git a/doPlayback.go b/doPlayback.go
index 34a9557..2f01c93 100644
--- a/doPlayback.go
+++ b/doPlayback.go
@@ -2,30 +2,53 @@ package main
import (
"fmt"
+ "os"
+ "go.wit.com/lib/protobuf/chatpb"
"go.wit.com/log"
)
-func doPlayback() {
- log.Infof("Found %d chat topic(s) in the log.", len(me.chats.GetChats()))
- fmt.Println("-------------------------------------------------")
+// doPlayback loads a specified log file and prints a one-line summary for each chat topic.
+// If no filename is provided, it summarizes the current in-memory chat session.
+func doPlayback(filename string) {
+ var playbackChats *chatpb.Chats
+ var err error
- // Iterate through the top-level Chat messages, which are now named groups.
- for _, chat := range me.chats.GetChats() {
+ // If a filename is provided, load that file. Otherwise, use the existing session.
+ if filename != "" {
+ log.Infof("Loading log file for playback: %s", filename)
+ data, err := os.ReadFile(filename)
+ if err != nil {
+ log.Fatalf("Failed to read playback file: %v", err)
+ }
+ playbackChats, err = chatpb.UnmarshalChatsTEXT(data)
+ if err != nil {
+ log.Fatalf("Failed to parse playback file: %v", err)
+ }
+ } else {
+ log.Info("No log file specified. Displaying summary of current conversation state.")
+ playbackChats = me.chats
+ }
- // Get the number of entries in the chat.
- entryCount := len(chat.GetEntries())
+ // Ensure all chats and entries have UUIDs before printing.
+ verifyUuids(playbackChats)
- // Get the timestamp of the first entry to represent the chat's start time.
+ fmt.Println("-------------------------------------------------")
+ log.Infof("Found %d chat topic(s).", len(playbackChats.GetChats()))
+ fmt.Println("-------------------------------------------------")
+
+ for _, chat := range playbackChats.GetChats() {
+ entryCount := len(chat.GetEntries())
var formattedTime string
- if entryCount > 0 && chat.GetEntries()[0].GetCtime() != nil {
- t := chat.GetEntries()[0].GetCtime().AsTime()
- formattedTime = t.Format("2006-01-02 15:04:05") // YYYY-MM-DD HH:MM:SS
+
+ // Use the chat's top-level ctime for the summary.
+ if ctime := chat.GetCtime(); ctime != nil {
+ t := ctime.AsTime()
+ formattedTime = t.Format("2006-01-02 15:04:05")
} else {
formattedTime = "No Timestamp"
}
- // Print the formatted one-line summary.
fmt.Printf("Topic: %-25s | Entries: %-4d | Started: %s | UUID: %s\n",
chat.GetChatName(),
entryCount,