From 41eb9901d7962debb85ff2413c9404a7cc5c8ee8 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 30 Mar 2016 20:43:38 +0200 Subject: [PATCH] Send new location notification after device is saved. --- app/models/user_device.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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