ref: master
plugins/push_notification/lib/push_notification_plugin/observers/add_friend_observer.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
module PushNotificationPlugin::Observers module AddFriendObserver def add_friend_after_create_callback(add_friend) requestor = add_friend.requestor target = add_friend.target send_to_users("add_friend", [target.user], {:event => "Add Friend", :requestor_id => requestor.id, :requestor_name => requestor.name, :task_id => add_friend.id} ) end #check when task is finished def add_friend_after_save_callback(add_friend) requestor = add_friend.requestor target = add_friend.target return false unless [Task::Status::FINISHED, Task::Status::CANCELLED].include?(add_friend.status) added = add_friend.status==Task::Status::FINISHED event= added ? "Friendship accepted" : "Friendship refused" send_to_users("add_friend_result", [requestor.user], {:event => event, :target_id => target.id, :target_name => target.name, :task_id => add_friend.id} ) end end end |