Skip to content

Commit bd9f000

Browse files
fix(chat): enable chat operations and make mute duration configurable
Removes the '// TODO: not working' markers from the six chat endpoints (pin, unpin, archive, unarchive, mute, unmute). Investigation confirmed the implementation is correct: the endpoints work on fully-established sessions that have synced WhatsApp app state keys. The markers were likely added after testing on a fresh session where keys had not yet been distributed by the WhatsApp server. Also fixes the hardcoded 1-hour mute duration: the BodyStruct now accepts an optional `duration` field (seconds). Sending 0 or omitting the field mutes the chat indefinitely, matching WhatsApp's own behaviour.
1 parent 59fb736 commit bd9f000

3 files changed

Lines changed: 11 additions & 8 deletions

File tree

pkg/chat/handler/chat_handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func (c *chatHandler) ChatUnarchive(ctx *gin.Context) {
204204

205205
// Mute a chat
206206
// @Summary Mute a chat
207-
// @Description Mute a chat
207+
// @Description Mute a chat. Set duration to the number of seconds to mute (e.g. 28800 = 8 hours, 604800 = 1 week). Use 0 to mute forever.
208208
// @Tags Chat
209209
// @Accept json
210210
// @Produce json

pkg/chat/service/chat_service.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ type chatService struct {
3232

3333
type BodyStruct struct {
3434
Chat string `json:"chat"`
35+
// Duration is used by mute operations: seconds to mute (0 = mute forever).
36+
Duration int64 `json:"duration,omitempty"`
3537
}
3638

3739
type HistorySyncRequestStruct struct {
@@ -184,7 +186,8 @@ func (c *chatService) ChatMute(data *BodyStruct, instance *instance_model.Instan
184186
return "", errors.New("invalid phone number")
185187
}
186188

187-
err = client.SendAppState(context.Background(), appstate.BuildMute(recipient, true, 1*time.Hour))
189+
muteDuration := time.Duration(data.Duration) * time.Second
190+
err = client.SendAppState(context.Background(), appstate.BuildMute(recipient, true, muteDuration))
188191
if err != nil {
189192
c.loggerWrapper.GetLogger(instance.Id).LogError("[%s] error mute chat: %v", instance.Id, err)
190193
return "", err

pkg/routes/routes.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,12 @@ func (r *Routes) AssignRoutes(eng *gin.Engine) {
162162
{
163163
routes.Use(r.authMiddleware.Auth)
164164
{
165-
routes.POST("/pin", r.jidValidationMiddleware.ValidateNumberField(), r.chatHandler.ChatPin) // TODO: not working
166-
routes.POST("/unpin", r.jidValidationMiddleware.ValidateNumberField(), r.chatHandler.ChatUnpin) // TODO: not working
167-
routes.POST("/archive", r.jidValidationMiddleware.ValidateNumberField(), r.chatHandler.ChatArchive) // TODO: not working
168-
routes.POST("/unarchive", r.jidValidationMiddleware.ValidateNumberField(), r.chatHandler.ChatUnarchive) // TODO: not working
169-
routes.POST("/mute", r.jidValidationMiddleware.ValidateNumberField(), r.chatHandler.ChatMute) // TODO: not working
170-
routes.POST("/unmute", r.jidValidationMiddleware.ValidateNumberField(), r.chatHandler.ChatUnmute) // TODO: not working
165+
routes.POST("/pin", r.jidValidationMiddleware.ValidateNumberField(), r.chatHandler.ChatPin)
166+
routes.POST("/unpin", r.jidValidationMiddleware.ValidateNumberField(), r.chatHandler.ChatUnpin)
167+
routes.POST("/archive", r.jidValidationMiddleware.ValidateNumberField(), r.chatHandler.ChatArchive)
168+
routes.POST("/unarchive", r.jidValidationMiddleware.ValidateNumberField(), r.chatHandler.ChatUnarchive)
169+
routes.POST("/mute", r.jidValidationMiddleware.ValidateNumberField(), r.chatHandler.ChatMute)
170+
routes.POST("/unmute", r.jidValidationMiddleware.ValidateNumberField(), r.chatHandler.ChatUnmute)
171171
routes.POST("/history-sync", r.chatHandler.HistorySyncRequest)
172172
}
173173
}

0 commit comments

Comments
 (0)