Skip to content

Commit 4cfbe0a

Browse files
committed
change push notification when starting a vpn
1 parent 338bab8 commit 4cfbe0a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

api/v1/vpn/vpn.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,15 @@ func updateVPN(c *gin.Context) {
311311
// flush the cache for this vpn
312312
core.FlushCache(v.DeviceID)
313313

314-
// send push notification if appropriate
315-
if core.Push.PushDevices[v.DeviceID] != "" && v.Enable {
314+
if core.Push.PushDevices[v.DeviceID] == "" && v.Enable && v.DeviceID == result.DeviceID {
315+
err := core.Push.SendPushNotification(core.Push.PushDevices[v.DeviceID], v.NetName+" enabled", "Connection to "+v.NetName+" has been established")
316+
if err != nil {
317+
log.WithFields(log.Fields{
318+
"err": err,
319+
}).Error("failed to send push notification")
320+
}
321+
} else if core.Push.PushDevices[v.DeviceID] != "" && v.Enable {
322+
// send push notification if appropriate
316323
err := core.Push.SendPushNotification(core.Push.PushDevices[v.DeviceID], v.NetName+" updated", "The VPN configuration for "+v.NetName+" has been updated")
317324
if err != nil {
318325
log.WithFields(log.Fields{
@@ -330,7 +337,6 @@ func updateVPN(c *gin.Context) {
330337
}).Error("failed to send push notification")
331338
}
332339
}
333-
334340
}
335341

336342
c.JSON(http.StatusOK, result)

0 commit comments

Comments
 (0)