Skip to content

Commit 02fb3ab

Browse files
committed
[messages] add messages priority
1 parent e04c1b8 commit 02fb3ab

File tree

5 files changed

+48
-44
lines changed

5 files changed

+48
-44
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ toolchain go1.23.2
66

77
require (
88
firebase.google.com/go/v4 v4.12.1
9-
github.com/android-sms-gateway/client-go v1.5.6
9+
github.com/android-sms-gateway/client-go v1.5.7-0.20250329004203-446171f5cfa2
1010
github.com/ansrivas/fiberprometheus/v2 v2.6.1
1111
github.com/capcom6/go-helpers v0.2.0
1212
github.com/capcom6/go-infra-fx v0.2.1

go.sum

+2-10
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,8 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc
2626
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
2727
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw=
2828
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk=
29-
github.com/android-sms-gateway/client-go v1.5.4 h1:sFMqu+Lc+YtkasesmerckVV8KKL8Qcx/VPEUWvcfbyA=
30-
github.com/android-sms-gateway/client-go v1.5.4/go.mod h1:DQsReciU1xcaVW3T5Z2bqslNdsAwCFCtghawmA6g6L4=
31-
github.com/android-sms-gateway/client-go v1.5.6-0.20250326025946-2625b20dcccd h1:VuSsDc7HeRllPmVrFCmMi0ksFDWEDoUEHFuua4ccJ0s=
32-
github.com/android-sms-gateway/client-go v1.5.6-0.20250326025946-2625b20dcccd/go.mod h1:DQsReciU1xcaVW3T5Z2bqslNdsAwCFCtghawmA6g6L4=
33-
github.com/android-sms-gateway/client-go v1.5.6 h1:sCiBT1Fn7QBaTlX7Z3eBGDcG+u+3sADmp+rxb0HWuaA=
34-
github.com/android-sms-gateway/client-go v1.5.6/go.mod h1:DQsReciU1xcaVW3T5Z2bqslNdsAwCFCtghawmA6g6L4=
29+
github.com/android-sms-gateway/client-go v1.5.7-0.20250329004203-446171f5cfa2 h1:olxI6g/dAUFUMcgKV8Dq+wRE4rJuUmRk1v0NsAUV+oA=
30+
github.com/android-sms-gateway/client-go v1.5.7-0.20250329004203-446171f5cfa2/go.mod h1:DQsReciU1xcaVW3T5Z2bqslNdsAwCFCtghawmA6g6L4=
3531
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
3632
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
3733
github.com/ansrivas/fiberprometheus/v2 v2.6.1 h1:wac3pXaE6BYYTF04AC6K0ktk6vCD+MnDOJZ3SK66kXM=
@@ -41,10 +37,6 @@ github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT
4137
github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
4238
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
4339
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
44-
github.com/capcom6/go-helpers v0.1.1 h1:kcpK1+VUwo94MZlZX+0Gab4gf78egHTPzW9sOQXLfFE=
45-
github.com/capcom6/go-helpers v0.1.1/go.mod h1:WDqc7HZNqHxUTisArkYIBZtqUfJBVyPWeQI+FMwEzAw=
46-
github.com/capcom6/go-helpers v0.1.2-0.20250326030929-5d1f34b4936b h1:grbupORuCS6EJV/IMdEijRwmW7M91bpgqqex/TRKg38=
47-
github.com/capcom6/go-helpers v0.1.2-0.20250326030929-5d1f34b4936b/go.mod h1:WDqc7HZNqHxUTisArkYIBZtqUfJBVyPWeQI+FMwEzAw=
4840
github.com/capcom6/go-helpers v0.2.0 h1:OUcUnVbjBiwaTzvyaxkxqRKtrOXv1ifYalQ1NXzFBNM=
4941
github.com/capcom6/go-helpers v0.2.0/go.mod h1:WDqc7HZNqHxUTisArkYIBZtqUfJBVyPWeQI+FMwEzAw=
5042
github.com/capcom6/go-infra-fx v0.2.1 h1:8rqr2ZV+YC2R07amHMdlE1XKLUhMe5yO+ffCJ/xXlNY=

internal/sms-gateway/handlers/mobile.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/android-sms-gateway/server/internal/sms-gateway/modules/devices"
1717
"github.com/android-sms-gateway/server/internal/sms-gateway/modules/messages"
1818
"github.com/capcom6/go-helpers/anys"
19+
"github.com/capcom6/go-helpers/slices"
1920
"github.com/go-playground/validator/v10"
2021
"github.com/gofiber/fiber/v2"
2122
"github.com/gofiber/fiber/v2/middleware/keyauth"
@@ -163,7 +164,11 @@ func (h *mobileHandler) getMessage(device models.Device, c *fiber.Ctx) error {
163164
return fmt.Errorf("can't get messages: %w", err)
164165
}
165166

166-
return c.JSON(messages)
167+
return c.JSON(
168+
smsgateway.MobileGetMessagesReponse(
169+
slices.Map(messages, func(m smsgateway.Message) smsgateway.MobileMessage { return smsgateway.MobileMessage(m) }),
170+
),
171+
)
167172
}
168173

169174
// @Summary Update message state
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package messages
2+
3+
import (
4+
"time"
5+
6+
"github.com/android-sms-gateway/client-go/smsgateway"
7+
"github.com/android-sms-gateway/server/internal/sms-gateway/models"
8+
"github.com/capcom6/go-helpers/anys"
9+
"github.com/capcom6/go-helpers/slices"
10+
)
11+
12+
func messageToDTO(input *models.Message) smsgateway.Message {
13+
var ttl *uint64 = nil
14+
if input.ValidUntil != nil {
15+
delta := time.Until(*input.ValidUntil).Seconds()
16+
if delta > 0 {
17+
deltaInt := uint64(delta)
18+
ttl = &deltaInt
19+
} else {
20+
deltaInt := uint64(0)
21+
ttl = &deltaInt
22+
}
23+
}
24+
25+
return smsgateway.Message{
26+
ID: input.ExtID,
27+
Message: input.Message,
28+
PhoneNumbers: slices.Map(input.Recipients, func(r models.MessageRecipient) string { return r.PhoneNumber }),
29+
30+
SimNumber: input.SimNumber,
31+
WithDeliveryReport: anys.AsPointer(input.WithDeliveryReport),
32+
IsEncrypted: input.IsEncrypted,
33+
TTL: ttl,
34+
ValidUntil: input.ValidUntil,
35+
36+
CreatedAt: input.CreatedAt,
37+
}
38+
}

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

+1-32
Original file line numberDiff line numberDiff line change
@@ -103,28 +103,7 @@ func (s *Service) SelectPending(deviceID string) ([]smsgateway.Message, error) {
103103

104104
result := make([]smsgateway.Message, len(messages))
105105
for i, v := range messages {
106-
var ttl *uint64 = nil
107-
if v.ValidUntil != nil {
108-
delta := time.Until(*v.ValidUntil).Seconds()
109-
if delta > 0 {
110-
deltaInt := uint64(delta)
111-
ttl = &deltaInt
112-
} else {
113-
deltaInt := uint64(0)
114-
ttl = &deltaInt
115-
}
116-
}
117-
118-
result[i] = smsgateway.Message{
119-
ID: v.ExtID,
120-
Message: v.Message,
121-
SimNumber: v.SimNumber,
122-
WithDeliveryReport: anys.AsPointer[bool](v.WithDeliveryReport),
123-
IsEncrypted: v.IsEncrypted,
124-
PhoneNumbers: s.recipientsToDomain(v.Recipients),
125-
TTL: ttl,
126-
ValidUntil: v.ValidUntil,
127-
}
106+
result[i] = messageToDTO(&v)
128107
}
129108

130109
return result, nil
@@ -265,16 +244,6 @@ func (s *Service) Clean(ctx context.Context) error {
265244

266245
///////////////////////////////////////////////////////////////////////////////
267246

268-
func (s *Service) recipientsToDomain(input []models.MessageRecipient) []string {
269-
output := make([]string, len(input))
270-
271-
for i, v := range input {
272-
output[i] = v.PhoneNumber
273-
}
274-
275-
return output
276-
}
277-
278247
func (s *Service) recipientsToModel(input []string) []models.MessageRecipient {
279248
output := make([]models.MessageRecipient, len(input))
280249

0 commit comments

Comments
 (0)