diff --git a/api/v1/device/device.go b/api/v1/device/device.go index 7672c0c..d2bf594 100644 --- a/api/v1/device/device.go +++ b/api/v1/device/device.go @@ -235,8 +235,23 @@ func updateDevice(c *gin.Context) { } core.FlushCache(id) - if data.Push != "" { - push.SendPushNotification(device.Push, "Device Updated", "Device "+device.Name+" has been updated") + + if client.Push != "" { + // Add the push token to the list of push devices + if push.PushDevices[id] != client.Push { + push.PushDevices[id] = client.Push + } + err = push.SendPushNotification(data.Push, "Device Updated", "Device "+device.Name+" has been updated") + if err != nil { + log.WithFields(log.Fields{ + "err": err, + }).Error("failed to send push notification") + } + } else { + // Remove the push token from the list of push devices + if push.PushDevices[id] != "" { + delete(push.PushDevices, id) + } } c.JSON(http.StatusOK, client) } diff --git a/core/device.go b/core/device.go index ddf5fcb..7565529 100644 --- a/core/device.go +++ b/core/device.go @@ -159,6 +159,8 @@ func UpdateDevice(Id string, device *model.Device, fUpdated bool) (*model.Device current.UpdatedBy = "API" } } + + current.Push = device.Push current.Enable = device.Enable current.Logging = device.Logging current.Tags = device.Tags