diff --git a/app/models/user_device.rb b/app/models/user_device.rb index 23241682c..4a05276d9 100644 --- a/app/models/user_device.rb +++ b/app/models/user_device.rb @@ -145,6 +145,7 @@ log user device action user_device = UserDevice.find(user_device_id) # update location if needed + notify = false if user_device.ip != ip user_device.ip = ip location_details = Service::GeoIp.location(ip) @@ -154,14 +155,19 @@ log user device action # notify if country has changed if user_device.location != location - user_device.notification_send('user_device_new_location') + notify = true + user_device.location = location end - user_device.location = location end # update attributes user_device.updated_at = Time.zone.now # force update, also if no other attribute has changed user_device.save + + if notify + user_device.notification_send('user_device_new_location') + end + user_device end