Created
March 6, 2018 23:03
-
-
Save rosem/360e42478240c88ebe533db9787fdaba to your computer and use it in GitHub Desktop.
notify room
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def notify_room(room, sender) | |
alert = "#{sender.pseudo} created #{room.title} nearby" | |
notifyees = User.within(prefered_distance, :origin => [room.lat, room.lng]).where(["prefered_distance is not null and lat is not null and lng is not null and id != ?", sender.id]) | |
#notifyees = User.geo_scope(:origin => [room.lat, room.lng]).where(["#{User.distance_sql(Geokit::LatLng.new(room.lat, room.lng))} < prefered_distance and prefered_distance is not null and lat is not null and lng is not null and id != ?", sender.id]) | |
# select users who haven't blocked the room owner | |
notifyees = notifyees.where('users.id not in (select user_id from blocked_users where blocked_users.blocked_id = ?)', room.user_id) | |
if !Room.with_deleted.find(room.id).deleted_at.nil? | |
#room got delete, no need to notify | |
return | |
end | |
enabled_notifyees = notifyees.select { |user| !user.device_token.blank? && user.notify_rooms } | |
enabled_notifyees = enabled_notifyees.select do |user| | |
user.add_event!(:eventable => room, :event_type => 'create') | |
end | |
deliver(alert, room, enabled_notifyees) | |
Pusher["webview"].trigger('room_created', { :room => room.id }) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment