Skip to content

Commit f92dfa7

Browse files
committed
[settings] notify devices on settings change
1 parent 7e892e2 commit f92dfa7

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

internal/sms-gateway/modules/settings/service.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package settings
22

33
import (
4+
"github.com/android-sms-gateway/server/internal/sms-gateway/modules/push"
45
"go.uber.org/fx"
56
"go.uber.org/zap"
67
)
@@ -11,12 +12,16 @@ type ServiceParams struct {
1112
Repository *repository
1213

1314
Logger *zap.Logger
15+
16+
PushSvc *push.Service
1417
}
1518

1619
type Service struct {
1720
settings *repository
1821

1922
logger *zap.Logger
23+
24+
pushSvc *push.Service
2025
}
2126

2227
func (s *Service) GetSettings(userID string, public bool) (map[string]any, error) {
@@ -46,6 +51,8 @@ func (s *Service) UpdateSettings(userID string, settings map[string]any) (map[st
4651
return nil, err
4752
}
4853

54+
s.notifyDevices(userID)
55+
4956
return filterMap(updatedSettings.Settings, rulesPublic)
5057
}
5158

@@ -63,12 +70,24 @@ func (s *Service) ReplaceSettings(userID string, settings map[string]any) (map[s
6370
return nil, err
6471
}
6572

73+
s.notifyDevices(userID)
74+
6675
return filterMap(updated.Settings, rulesPublic)
6776
}
6877

78+
// notifyDevices asynchronously notifies all the user's devices.
79+
func (s *Service) notifyDevices(userID string) {
80+
go func(userID string) {
81+
if err := s.pushSvc.Notify(userID, nil, push.NewSettingsUpdatedEvent()); err != nil {
82+
s.logger.Error("can't notify devices", zap.Error(err))
83+
}
84+
}(userID)
85+
}
86+
6987
func NewService(params ServiceParams) *Service {
7088
return &Service{
7189
settings: params.Repository,
7290
logger: params.Logger.Named("service"),
91+
pushSvc: params.PushSvc,
7392
}
7493
}

pkg/swagger/docs/requests.http

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,6 @@ Authorization: Basic {{credentials}}
113113
Content-Type: application/json
114114

115115
{
116-
"localserver": {
117-
"PORT": 8080
118-
},
119116
"messages": {
120117
"send_interval_min": null,
121118
"send_interval_max": 1
@@ -131,10 +128,6 @@ Content-Type: application/json
131128
"encryption": {
132129
"passphrase": "{{$guid}}"
133130
},
134-
"gateway": {
135-
"cloud_url": "https://api.sms-gate.app/mobile/v1",
136-
"private_token": null
137-
},
138131
"messages": {
139132
"send_interval_min": null,
140133
"send_interval_max": null,
@@ -143,9 +136,6 @@ Content-Type: application/json
143136
"sim_selection_mode": "OSDefault",
144137
"log_lifetime_days": null
145138
},
146-
"localserver": {
147-
"PORT": 8080
148-
},
149139
"ping": {
150140
"interval_seconds": null
151141
},

0 commit comments

Comments
 (0)