Skip to content

Commit

Permalink
push notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-nettica committed Oct 14, 2024
1 parent 7d2d968 commit 0ff2d46
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 17 additions & 2 deletions api/v1/device/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 2 additions & 0 deletions core/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0ff2d46

Please sign in to comment.