// Package convhandler is the conversation list / inbox sync HTTP controller. package convhandler import ( "strconv" "github.com/gin-gonic/gin" syncentity "spark-server/internal/module/sync/entity" synclogic "spark-server/internal/module/sync/logic" "spark-server/internal/pkg/errs" "spark-server/internal/pkg/reqctx" "spark-server/internal/transport/http/respond" ) // Handler is the conversation list / inbox sync controller. type Handler struct { sync *synclogic.Service } func New(sync *synclogic.Service) *Handler { return &Handler{sync: sync} } func (h *Handler) Inbox(c *gin.Context) { rc := reqctx.From(c.Request.Context()) if rc == nil || rc.UserID <= 0 { respond.JSONError(c, errs.ErrUnauthorized) return } score, _ := strconv.ParseInt(c.Query("dialog_score"), 10, 64) seq, _ := strconv.ParseInt(c.Query("mailbox_seq"), 10, 64) limit, _ := strconv.Atoi(c.Query("limit")) out, err := h.sync.SyncInbox(c.Request.Context(), syncentity.InboxRequest{ UserID: rc.UserID, DeviceID: rc.DeviceID, DialogScore: score, MailboxSeq: seq, Limit: limit, }) if err != nil { respond.JSONError(c, err) return } respond.JSON(c, out) }