summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go40
1 files changed, 38 insertions, 2 deletions
diff --git a/main.go b/main.go
index ac443c6..e5a4ee7 100644
--- a/main.go
+++ b/main.go
@@ -9,6 +9,7 @@ import (
"embed"
"os"
+ "github.com/google/uuid"
"go.wit.com/dev/alexflint/arg"
"go.wit.com/gui"
"go.wit.com/lib/protobuf/chatpb"
@@ -55,8 +56,29 @@ func main() {
os.Exit(0)
}
- if argv.Add != nil {
- log.Info("add new conversation to protobuf")
+ me.chats = chatpb.NewChats()
+ if err := me.chats.ConfigLoad(); err != nil {
+ badExit(err)
+ }
+ if verifyUuids(me.chats) {
+ me.chats.ConfigSave()
+ }
+
+ if argv.Add != "" {
+ log.Info("add new conversation to protobuf", argv.Add)
+ pb := parseRichLog(argv.Add)
+ verifyUuids(pb)
+ all := pb.SortByUuid()
+ for all.Scan() {
+ chat := all.Next()
+ log.Info("NEW CHAT", chat.From, chat.Uuid)
+ if test := me.chats.FindByContentFile(chat.ContentFile); test != nil {
+ log.Info("NOT NEW CHAT", test.ContentFile)
+ continue
+ }
+ me.chats.AppendByUuid(chat)
+ }
+ pb.ConfigSave()
okExit("")
}
@@ -76,3 +98,17 @@ func main() {
// doGui()
okExit("")
}
+
+func verifyUuids(chats *chatpb.Chats) bool {
+ var changed bool
+
+ all := chats.SortByUuid()
+ for all.Scan() {
+ chat := all.Next()
+ if chat.Uuid == "" {
+ chat.Uuid = uuid.New().String()
+ changed = true
+ }
+ }
+ return changed
+}