From 22d120463b2617d890780ce426ecd67c7522fdba Mon Sep 17 00:00:00 2001 From: Rafael Soares Date: Thu, 22 Aug 2024 10:12:10 -0300 Subject: [PATCH] parse or set to now the msg timestamp from channel --- pkg/websocket/handler.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/websocket/handler.go b/pkg/websocket/handler.go index 758261f..ae520bd 100644 --- a/pkg/websocket/handler.go +++ b/pkg/websocket/handler.go @@ -5,6 +5,7 @@ import ( "errors" "net/http" "strconv" + "time" "github.com/go-playground/validator" "github.com/ilhasoft/wwcs/pkg/queue" @@ -89,10 +90,7 @@ func (a *App) SendHandler(w http.ResponseWriter, r *http.Request) { return } - msgTime, err := strconv.ParseInt(payload.Message.Timestamp, 10, 64) - if err != nil { - log.Error("error on parse msg timestamp from str to int64", err) - } + msgTime := tryParseStr2Timestamp(payload.Message.Timestamp) hmsg := NewHistoryMessagePayload(DirectionIn, payload.To, payload.ChannelUUID, payload.Message, msgTime) err = a.Histories.Save(hmsg) if err != nil { @@ -153,3 +151,11 @@ func handleError(w http.ResponseWriter, err error, msg string) { w.WriteHeader(http.StatusInternalServerError) w.Write([]byte(ErrorInternalError.Error())) } + +func tryParseStr2Timestamp(t string) int64 { + mt, err := strconv.ParseInt(t, 10, 64) + if err != nil { + return time.Now().Unix() + } + return mt +}