Skip to content

Commit

Permalink
parse or set to now the msg timestamp from channel
Browse files Browse the repository at this point in the history
  • Loading branch information
rasoro committed Aug 22, 2024
1 parent 8a37c46 commit 22d1204
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions pkg/websocket/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"net/http"
"strconv"
"time"

"github.com/go-playground/validator"
"github.com/ilhasoft/wwcs/pkg/queue"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

0 comments on commit 22d1204

Please sign in to comment.