Skip to content

Commit 0ff2d46

Browse files
committed
push notifications
1 parent 7d2d968 commit 0ff2d46

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

api/v1/device/device.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,23 @@ func updateDevice(c *gin.Context) {
235235
}
236236

237237
core.FlushCache(id)
238-
if data.Push != "" {
239-
push.SendPushNotification(device.Push, "Device Updated", "Device "+device.Name+" has been updated")
238+
239+
if client.Push != "" {
240+
// Add the push token to the list of push devices
241+
if push.PushDevices[id] != client.Push {
242+
push.PushDevices[id] = client.Push
243+
}
244+
err = push.SendPushNotification(data.Push, "Device Updated", "Device "+device.Name+" has been updated")
245+
if err != nil {
246+
log.WithFields(log.Fields{
247+
"err": err,
248+
}).Error("failed to send push notification")
249+
}
250+
} else {
251+
// Remove the push token from the list of push devices
252+
if push.PushDevices[id] != "" {
253+
delete(push.PushDevices, id)
254+
}
240255
}
241256
c.JSON(http.StatusOK, client)
242257
}

core/device.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ func UpdateDevice(Id string, device *model.Device, fUpdated bool) (*model.Device
159159
current.UpdatedBy = "API"
160160
}
161161
}
162+
163+
current.Push = device.Push
162164
current.Enable = device.Enable
163165
current.Logging = device.Logging
164166
current.Tags = device.Tags

0 commit comments

Comments
 (0)