fix notify self, fix superfluous WriteHeader warning

This commit is contained in:
Egor 2026-02-06 19:30:03 -08:00
parent 3f8fbe5b99
commit 519dd9e46f
4 changed files with 10 additions and 11 deletions

View file

@ -66,7 +66,7 @@ func (m *Monitor) monitor(ctx context.Context) error {
case <-m.newMessagesChan: case <-m.newMessagesChan:
idleCmd.Close() idleCmd.Close()
m.sendNotification() // Errors already logged in sendNotification() m.sendNotification()
idleCmd, err = m.client.Idle() idleCmd, err = m.client.Idle()
if err != nil { if err != nil {

View file

@ -107,7 +107,6 @@ func (c *Client) GetLinkedAccount() (*Account, error) {
return &Account{Number: accounts[0].Number}, nil return &Account{Number: accounts[0].Number}, nil
} }
// CreateGroup creates a Signal group using updateGroup JSON-RPC method
func (c *Client) CreateGroup(name string) (string, string, error) { func (c *Client) CreateGroup(name string) (string, string, error) {
if c == nil { if c == nil {
return "", "", fmt.Errorf("signal client not initialized") return "", "", fmt.Errorf("signal client not initialized")
@ -123,7 +122,7 @@ func (c *Client) CreateGroup(name string) (string, string, error) {
params := map[string]interface{}{ params := map[string]interface{}{
"name": name, "name": name,
"member": []string{}, // Empty group "member": []string{},
} }
result, err := c.CallWithAccount("updateGroup", params, account.Number) result, err := c.CallWithAccount("updateGroup", params, account.Number)
@ -145,7 +144,6 @@ func (c *Client) CreateGroup(name string) (string, string, error) {
return response.GroupID, account.Number, nil return response.GroupID, account.Number, nil
} }
// SendGroupMessage sends a message to a Signal group
func (c *Client) SendGroupMessage(groupID, message string) error { func (c *Client) SendGroupMessage(groupID, message string) error {
if c == nil { if c == nil {
return fmt.Errorf("signal client not initialized") return fmt.Errorf("signal client not initialized")
@ -160,9 +158,9 @@ func (c *Client) SendGroupMessage(groupID, message string) error {
} }
params := map[string]interface{}{ params := map[string]interface{}{
"groupId": groupID, "groupId": groupID,
"message": message, "message": message,
"notify-self": true, "notifySelf": true,
} }
_, err = c.CallWithAccount("send", params, account.Number) _, err = c.CallWithAccount("send", params, account.Number)

View file

@ -37,7 +37,6 @@ func (l *LinkDevice) GenerateQR() (string, error) {
return l.qrCode, nil return l.qrCode, nil
} }
// Call signal-cli's startLink JSON-RPC method directly
result, err := l.client.Call("startLink", nil) result, err := l.client.Call("startLink", nil)
if err != nil { if err != nil {
return "", fmt.Errorf("failed to start link: %w", err) return "", fmt.Errorf("failed to start link: %w", err)

View file

@ -51,14 +51,16 @@ func loggingMiddleware(logger *slog.Logger) func(http.Handler) http.Handler {
type responseWriter struct { type responseWriter struct {
http.ResponseWriter http.ResponseWriter
statusCode int statusCode int
headerWritten bool
} }
func (rw *responseWriter) WriteHeader(code int) { func (rw *responseWriter) WriteHeader(code int) {
if rw.statusCode == http.StatusOK { if !rw.headerWritten {
rw.statusCode = code rw.statusCode = code
rw.ResponseWriter.WriteHeader(code)
rw.headerWritten = true
} }
rw.ResponseWriter.WriteHeader(code)
} }
func securityHeadersMiddleware() func(http.Handler) http.Handler { func securityHeadersMiddleware() func(http.Handler) http.Handler {