feat(contacts): align active pagination payloads

This commit is contained in:
2026-06-06 01:18:24 +08:00
parent 7425e269d7
commit c76c25f2ea
3 changed files with 75 additions and 17 deletions
+12 -11
View File
@@ -25,6 +25,8 @@ type ContactHandler struct {
conversationSvc *service.ConversationService
}
const chatwootContactResultsPerPage = 15
// NewContactHandler creates a new ContactHandler.
func NewContactHandler(svc *service.ContactService, contactInboxSvc *service.ContactInboxService, mergeSvc *service.ContactMergeService, contactNoteSvc *service.ContactNoteService, conversationSvc ...*service.ConversationService) *ContactHandler {
h := &ContactHandler{svc: svc, contactInboxSvc: contactInboxSvc, mergeSvc: mergeSvc, contactNoteSvc: contactNoteSvc}
@@ -60,7 +62,7 @@ func (h *ContactHandler) List(c *gin.Context) {
}
page := getPage(c)
perPage := getPageSize(c)
perPage := chatwootContactResultsPerPage
offset := (page - 1) * perPage
sort := c.DefaultQuery("sort", "")
@@ -106,7 +108,7 @@ func (h *ContactHandler) Search(c *gin.Context) {
return
}
page := getPage(c)
perPage := getPageSize(c)
perPage := chatwootContactResultsPerPage
offset := (page - 1) * perPage
sort := c.DefaultQuery("sort", "")
searchMode := search.ParseSearchMode(c.DefaultQuery("search_mode", ""))
@@ -676,7 +678,7 @@ func (h *ContactHandler) DeleteContactInbox(c *gin.Context) {
}
// Active retrieves contacts with recent activity.
// GET /api/v1/accounts/:id/contacts/active?sort=name&page=1&page_size=25
// GET /api/v1/accounts/:id/contacts/active?sort=name&page=1
// Reference: Chatwoot contacts#active
func (h *ContactHandler) Active(c *gin.Context) {
accountID := parseAccountIDParam(c)
@@ -686,7 +688,7 @@ func (h *ContactHandler) Active(c *gin.Context) {
}
page := getPage(c)
perPage := getPageSize(c)
perPage := chatwootContactResultsPerPage
offset := (page - 1) * perPage
sort := c.DefaultQuery("sort", "")
if !h.svc.Ready() {
@@ -700,10 +702,7 @@ func (h *ContactHandler) Active(c *gin.Context) {
return
}
c.JSON(http.StatusOK, gin.H{
"contacts": contacts,
"meta": gin.H{"count": total, "page": page, "page_size": perPage},
})
c.JSON(http.StatusOK, contactListResponse(c.Request.Context(), h.svc.DB(), contacts, total, page, includeContactInboxes(c), nil))
}
// Export downloads contacts as CSV.
@@ -932,14 +931,16 @@ func (h *ContactHandler) Filter(c *gin.Context) {
return
}
p := pagination.Parse(c)
contacts, total, svcErr := h.svc.Filter(c.Request.Context(), accountID, params, p.Offset, p.PerPage)
page := getPage(c)
perPage := chatwootContactResultsPerPage
offset := (page - 1) * perPage
contacts, total, svcErr := h.svc.Filter(c.Request.Context(), accountID, params, offset, perPage)
if svcErr != nil {
c.JSON(http.StatusUnprocessableEntity, gin.H{"error": "failed to filter contacts"})
return
}
c.JSON(http.StatusOK, contactListResponse(c.Request.Context(), h.svc.DB(), contacts, total, p.Page, includeContactInboxes(c), nil))
c.JSON(http.StatusOK, contactListResponse(c.Request.Context(), h.svc.DB(), contacts, total, page, includeContactInboxes(c), nil))
}
// DestroyCustomAttributes removes all custom attributes from a contact.