summaryrefslogtreecommitdiff
path: root/doPlayback.go
blob: 34ed0fd2d412bd1a2356af42b8f7d30786437e56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main

import (
	"fmt"
	"strings"

	"go.wit.com/lib/protobuf/chatpb"
	"go.wit.com/log"
)

func doPlayback() {
	if argv.Playback.Uuid != "" {
		showChat(argv.Playback.Uuid)
		return
	}

	listChats(me.chats)
}

func showChat(uuid string) {
	chat := me.chats.FindByUuid(uuid)
	if chat == nil {
		log.Info("unknown uuid", uuid)
		return
	}
	prettyFormatChat(chat)
}

func listChats(chats *chatpb.Chats) {
	if argv.Playback.Long != nil {
		for _, chat := range chats.GetChats() {
			listEntries(chat)
		}
		return
	}

	log.Infof("Found %d chat topic(s) in the log.", len(chats.GetChats()))
	fmt.Println("-------------------------------------------------")

	for _, chat := range chats.GetChats() {
		entryCount := len(chat.GetEntries())
		var formattedTime string
		if ctime := chat.GetCtime(); ctime != nil {
			t := ctime.AsTime()
			formattedTime = t.Format("2006-01-02 15:04:05")
		} else {
			formattedTime = "No Timestamp"
		}

		fmt.Printf("Topic: %-25s | Entries: %-4d | Started: %s | UUID: %s\n",
			chat.GetChatName(),
			entryCount,
			formattedTime,
			chat.GetUuid(),
		)
	}
	fmt.Println("-------------------------------------------------")
}

// print out one line for each chat entry
func listEntries(chat *chatpb.Chat) {
	fmt.Printf("\n--- Entries for Topic: %s ---\n", chat.GetChatName())
	for i, entry := range chat.GetEntries() {
		author := entry.GetFrom().String()
		var formattedTime string
		if ctime := entry.GetCtime(); ctime != nil {
			t := ctime.AsTime()
			formattedTime = t.Format("15:04:05") // Just the time for entry summary
		} else {
			formattedTime = "No Time"
		}

		// Create a short preview of the content
		contentPreview := strings.TrimSpace(entry.GetContent())
		if len(contentPreview) > 60 {
			contentPreview = contentPreview[:57] + "..."
		}
		// Replace newlines with spaces for a clean one-line view
		contentPreview = strings.ReplaceAll(contentPreview, "\n", " ")

		fmt.Printf("  %2d. [%s] (%s): %s\n",
			i+1,
			author,
			formattedTime,
			contentPreview,
		)
	}
	fmt.Println("-------------------------------------------------")
}