{"action":"created","comment":{"url":"https://api.github.com/repos/Coursemology/coursemology2/pulls/comments/30938941","id":30938941,"diff_hunk":"@@ -0,0 +1,55 @@\n+class Notification < ActiveRecord::Base\n+  belongs_to :activity, inverse_of: :notifications, dependent: :destroy\n+\n+  acts_as_readable on: :updated_at\n+\n+  def self.notify(user, course, object, options = {})\n+    include_public_activity(object)\n+    unless options.key?(:activity)\n+      notify_only(user, course, object, options)\n+      return\n+    end\n+    activity_and_notify(user, course, object, options)\n+  end\n+\n+  class << self\n+    private\n+\n+    def include_public_activity(object)","path":"app/models/notification.rb","position":18,"original_position":18,"commit_id":"be28ca9f0beaae327d6584833dcc52dee8afc4eb","original_commit_id":"093b90b2f845313001c5c596b517b24ef8266e6d","user":{"login":"lowjoel","id":2505070,"avatar_url":"https://avatars.githubusercontent.com/u/2505070?v=3","gravatar_id":"","url":"https://api.github.com/users/lowjoel","html_url":"https://github.com/lowjoel","followers_url":"https://api.github.com/users/lowjoel/followers","following_url":"https://api.github.com/users/lowjoel/following{/other_user}","gists_url":"https://api.github.com/users/lowjoel/gists{/gist_id}","starred_url":"https://api.github.com/users/lowjoel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lowjoel/subscriptions","organizations_url":"https://api.github.com/users/lowjoel/orgs","repos_url":"https://api.github.com/users/lowjoel/repos","events_url":"https://api.github.com/users/lowjoel/events{/privacy}","received_events_url":"https://api.github.com/users/lowjoel/received_events","type":"User","site_admin":false},"body":"And I don't think this works with inherited models.","created_at":"2015-05-23T00:00:59Z","updated_at":"2015-05-23T00:00:59Z","html_url":"https://github.com/Coursemology/coursemology2/pull/189#discussion_r30938941","pull_request_url":"https://api.github.com/repos/Coursemology/coursemology2/pulls/189","_links":{"self":{"href":"https://api.github.com/repos/Coursemology/coursemology2/pulls/comments/30938941"},"html":{"href":"https://github.com/Coursemology/coursemology2/pull/189#discussion_r30938941"},"pull_request":{"href":"https://api.github.com/repos/Coursemology/coursemology2/pulls/189"}}},"pull_request":{"url":"https://api.github.com/repos/Coursemology/coursemology2/pulls/189","id":35233688,"html_url":"https://github.com/Coursemology/coursemology2/pull/189","diff_url":"https://github.com/Coursemology/coursemology2/pull/189.diff","patch_url":"https://github.com/Coursemology/coursemology2/pull/189.patch","issue_url":"https://api.github.com/repos/Coursemology/coursemology2/issues/189","number":189,"state":"open","locked":false,"title":"Redesign Notification Framework","user":{"login":"xzhflying","id":8858295,"avatar_url":"https://avatars.githubusercontent.com/u/8858295?v=3","gravatar_id":"","url":"https://api.github.com/users/xzhflying","html_url":"https://github.com/xzhflying","followers_url":"https://api.github.com/users/xzhflying/followers","following_url":"https://api.github.com/users/xzhflying/following{/other_user}","gists_url":"https://api.github.com/users/xzhflying/gists{/gist_id}","starred_url":"https://api.github.com/users/xzhflying/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xzhflying/subscriptions","organizations_url":"https://api.github.com/users/xzhflying/orgs","repos_url":"https://api.github.com/users/xzhflying/repos","events_url":"https://api.github.com/users/xzhflying/events{/privacy}","received_events_url":"https://api.github.com/users/xzhflying/received_events","type":"User","site_admin":false},"body":"To create a notification:\r\n===================\r\nUse API: `Notification.notify(user, course, object, types = {})`\r\nFor example, if you want to create three types of notification(activity):\r\n<code>Notification.notify(user, course, object, popup: [:PopupStyle], email: { style :EmailStyle, subject: :YourSubject }, activity: :ActivityType)</code>\r\n\r\n`popup: , email: , activity:` are all optional. You can create any combinations of notifications among them. But it certainly doesn't make sense if you do not input any type.\r\n\r\npopup: \r\n---------------\r\nCould take in an **array**, and the types(symbols) in array will be the templates' **styles** which are used to show those popups. You should provide those styles in **view/notifications/popups/** directory. (eg. you may want to create a popup style: `level_up`)\r\n\r\nemail: \r\n--------\r\nCould take in a hash. There will be the style of email which will be used in the email and the subject of email which will be used as your email's subject. You should provide email style in **view/notifications/email_notifications/** directory. Meanwhile your email will also use **view/layouts/notifications/email.html.slim** as its layout.\r\n\r\nactivity:\r\n----------\r\nCould only take in a type name of activity. If one object is created in some controller, you may need to create an activity as `:create`. Activities are shown in course's show view. But you need to provide templates for each kind of activity type you have generated in **view/notifications/activities/object_name/** directory. \r\n\r\nFor example, if someone reached some level. You may want to create an update_activity for level object. To show this activity, you should provide a file named **_update.html.slim** in **view/notifications/activities/level/** directory. In that template, you may want to write:\r\n        `I18n.t('reached') a.trackable.level_number`  (you can use a.trackable to get your object record in your template)\r\n\r\nHow to store data\r\n==============\r\nactivities table\r\n-------------------\r\nThis table is provided by public_activity gem which will mainly store:\r\n* owner:   Course object is stored in this field.\r\n* trackable:   The object that is involved in this activity. (e.g. Achievement, Level ...)\r\n* recipient:   User object is stored in this field.\r\n* key:   Stands for which kind of activity\r\n\r\nnotifications table\r\n------------------------\r\n* activity\r\n* notification_type\r\n* style\r\n\r\nMost of time, the information we need to store for a notification( popup) is just like what is required for an activity. And most of time, we send a notification( popup or email) just after an activity record is created. So we just need to store the type( popup or something else) of this notification, the style of this notification and where is the information of this notification (reference to an activity record in activities table)\r\nWhat if we just want to send a popup or any other notification types without an existing activity record? We can create a fake activity as the type of :notification. So that we can also store our data. And this kind of activity( :notification) will not be loaded when we want to load recent activities.","created_at":"2015-05-12T14:45:20Z","updated_at":"2015-05-23T00:00:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"51980f6961cfcf142e3901d04e4a2c0b7f762d45","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Coursemology/coursemology2/pulls/189/commits","review_comments_url":"https://api.github.com/repos/Coursemology/coursemology2/pulls/189/comments","review_comment_url":"https://api.github.com/repos/Coursemology/coursemology2/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Coursemology/coursemology2/issues/189/comments","statuses_url":"https://api.github.com/repos/Coursemology/coursemology2/statuses/be28ca9f0beaae327d6584833dcc52dee8afc4eb","head":{"label":"xzhflying:notification","ref":"notification","sha":"be28ca9f0beaae327d6584833dcc52dee8afc4eb","user":{"login":"xzhflying","id":8858295,"avatar_url":"https://avatars.githubusercontent.com/u/8858295?v=3","gravatar_id":"","url":"https://api.github.com/users/xzhflying","html_url":"https://github.com/xzhflying","followers_url":"https://api.github.com/users/xzhflying/followers","following_url":"https://api.github.com/users/xzhflying/following{/other_user}","gists_url":"https://api.github.com/users/xzhflying/gists{/gist_id}","starred_url":"https://api.github.com/users/xzhflying/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xzhflying/subscriptions","organizations_url":"https://api.github.com/users/xzhflying/orgs","repos_url":"https://api.github.com/users/xzhflying/repos","events_url":"https://api.github.com/users/xzhflying/events{/privacy}","received_events_url":"https://api.github.com/users/xzhflying/received_events","type":"User","site_admin":false},"repo":{"id":31704878,"name":"coursemology2","full_name":"xzhflying/coursemology2","owner":{"login":"xzhflying","id":8858295,"avatar_url":"https://avatars.githubusercontent.com/u/8858295?v=3","gravatar_id":"","url":"https://api.github.com/users/xzhflying","html_url":"https://github.com/xzhflying","followers_url":"https://api.github.com/users/xzhflying/followers","following_url":"https://api.github.com/users/xzhflying/following{/other_user}","gists_url":"https://api.github.com/users/xzhflying/gists{/gist_id}","starred_url":"https://api.github.com/users/xzhflying/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xzhflying/subscriptions","organizations_url":"https://api.github.com/users/xzhflying/orgs","repos_url":"https://api.github.com/users/xzhflying/repos","events_url":"https://api.github.com/users/xzhflying/events{/privacy}","received_events_url":"https://api.github.com/users/xzhflying/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/xzhflying/coursemology2","description":"Rails 4 re-write of Coursemology","fork":true,"url":"https://api.github.com/repos/xzhflying/coursemology2","forks_url":"https://api.github.com/repos/xzhflying/coursemology2/forks","keys_url":"https://api.github.com/repos/xzhflying/coursemology2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/xzhflying/coursemology2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/xzhflying/coursemology2/teams","hooks_url":"https://api.github.com/repos/xzhflying/coursemology2/hooks","issue_events_url":"https://api.github.com/repos/xzhflying/coursemology2/issues/events{/number}","events_url":"https://api.github.com/repos/xzhflying/coursemology2/events","assignees_url":"https://api.github.com/repos/xzhflying/coursemology2/assignees{/user}","branches_url":"https://api.github.com/repos/xzhflying/coursemology2/branches{/branch}","tags_url":"https://api.github.com/repos/xzhflying/coursemology2/tags","blobs_url":"https://api.github.com/repos/xzhflying/coursemology2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/xzhflying/coursemology2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/xzhflying/coursemology2/git/refs{/sha}","trees_url":"https://api.github.com/repos/xzhflying/coursemology2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/xzhflying/coursemology2/statuses/{sha}","languages_url":"https://api.github.com/repos/xzhflying/coursemology2/languages","stargazers_url":"https://api.github.com/repos/xzhflying/coursemology2/stargazers","contributors_url":"https://api.github.com/repos/xzhflying/coursemology2/contributors","subscribers_url":"https://api.github.com/repos/xzhflying/coursemology2/subscribers","subscription_url":"https://api.github.com/repos/xzhflying/coursemology2/subscription","commits_url":"https://api.github.com/repos/xzhflying/coursemology2/commits{/sha}","git_commits_url":"https://api.github.com/repos/xzhflying/coursemology2/git/commits{/sha}","comments_url":"https://api.github.com/repos/xzhflying/coursemology2/comments{/number}","issue_comment_url":"https://api.github.com/repos/xzhflying/coursemology2/issues/comments{/number}","contents_url":"https://api.github.com/repos/xzhflying/coursemology2/contents/{+path}","compare_url":"https://api.github.com/repos/xzhflying/coursemology2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/xzhflying/coursemology2/merges","archive_url":"https://api.github.com/repos/xzhflying/coursemology2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/xzhflying/coursemology2/downloads","issues_url":"https://api.github.com/repos/xzhflying/coursemology2/issues{/number}","pulls_url":"https://api.github.com/repos/xzhflying/coursemology2/pulls{/number}","milestones_url":"https://api.github.com/repos/xzhflying/coursemology2/milestones{/number}","notifications_url":"https://api.github.com/repos/xzhflying/coursemology2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/xzhflying/coursemology2/labels{/name}","releases_url":"https://api.github.com/repos/xzhflying/coursemology2/releases{/id}","created_at":"2015-03-05T09:01:00Z","updated_at":"2015-03-30T12:53:21Z","pushed_at":"2015-05-22T13:39:38Z","git_url":"git://github.com/xzhflying/coursemology2.git","ssh_url":"git@github.com:xzhflying/coursemology2.git","clone_url":"https://github.com/xzhflying/coursemology2.git","svn_url":"https://github.com/xzhflying/coursemology2","homepage":null,"size":861,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Coursemology:master","ref":"master","sha":"60b1e299dad3161934a1a07ff7b7e2c6933e15f0","user":{"login":"Coursemology","id":4427741,"avatar_url":"https://avatars.githubusercontent.com/u/4427741?v=3","gravatar_id":"","url":"https://api.github.com/users/Coursemology","html_url":"https://github.com/Coursemology","followers_url":"https://api.github.com/users/Coursemology/followers","following_url":"https://api.github.com/users/Coursemology/following{/other_user}","gists_url":"https://api.github.com/users/Coursemology/gists{/gist_id}","starred_url":"https://api.github.com/users/Coursemology/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Coursemology/subscriptions","organizations_url":"https://api.github.com/users/Coursemology/orgs","repos_url":"https://api.github.com/users/Coursemology/repos","events_url":"https://api.github.com/users/Coursemology/events{/privacy}","received_events_url":"https://api.github.com/users/Coursemology/received_events","type":"Organization","site_admin":false},"repo":{"id":22155032,"name":"coursemology2","full_name":"Coursemology/coursemology2","owner":{"login":"Coursemology","id":4427741,"avatar_url":"https://avatars.githubusercontent.com/u/4427741?v=3","gravatar_id":"","url":"https://api.github.com/users/Coursemology","html_url":"https://github.com/Coursemology","followers_url":"https://api.github.com/users/Coursemology/followers","following_url":"https://api.github.com/users/Coursemology/following{/other_user}","gists_url":"https://api.github.com/users/Coursemology/gists{/gist_id}","starred_url":"https://api.github.com/users/Coursemology/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Coursemology/subscriptions","organizations_url":"https://api.github.com/users/Coursemology/orgs","repos_url":"https://api.github.com/users/Coursemology/repos","events_url":"https://api.github.com/users/Coursemology/events{/privacy}","received_events_url":"https://api.github.com/users/Coursemology/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Coursemology/coursemology2","description":"Rails 4 re-write of Coursemology","fork":false,"url":"https://api.github.com/repos/Coursemology/coursemology2","forks_url":"https://api.github.com/repos/Coursemology/coursemology2/forks","keys_url":"https://api.github.com/repos/Coursemology/coursemology2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Coursemology/coursemology2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Coursemology/coursemology2/teams","hooks_url":"https://api.github.com/repos/Coursemology/coursemology2/hooks","issue_events_url":"https://api.github.com/repos/Coursemology/coursemology2/issues/events{/number}","events_url":"https://api.github.com/repos/Coursemology/coursemology2/events","assignees_url":"https://api.github.com/repos/Coursemology/coursemology2/assignees{/user}","branches_url":"https://api.github.com/repos/Coursemology/coursemology2/branches{/branch}","tags_url":"https://api.github.com/repos/Coursemology/coursemology2/tags","blobs_url":"https://api.github.com/repos/Coursemology/coursemology2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Coursemology/coursemology2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Coursemology/coursemology2/git/refs{/sha}","trees_url":"https://api.github.com/repos/Coursemology/coursemology2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Coursemology/coursemology2/statuses/{sha}","languages_url":"https://api.github.com/repos/Coursemology/coursemology2/languages","stargazers_url":"https://api.github.com/repos/Coursemology/coursemology2/stargazers","contributors_url":"https://api.github.com/repos/Coursemology/coursemology2/contributors","subscribers_url":"https://api.github.com/repos/Coursemology/coursemology2/subscribers","subscription_url":"https://api.github.com/repos/Coursemology/coursemology2/subscription","commits_url":"https://api.github.com/repos/Coursemology/coursemology2/commits{/sha}","git_commits_url":"https://api.github.com/repos/Coursemology/coursemology2/git/commits{/sha}","comments_url":"https://api.github.com/repos/Coursemology/coursemology2/comments{/number}","issue_comment_url":"https://api.github.com/repos/Coursemology/coursemology2/issues/comments{/number}","contents_url":"https://api.github.com/repos/Coursemology/coursemology2/contents/{+path}","compare_url":"https://api.github.com/repos/Coursemology/coursemology2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Coursemology/coursemology2/merges","archive_url":"https://api.github.com/repos/Coursemology/coursemology2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Coursemology/coursemology2/downloads","issues_url":"https://api.github.com/repos/Coursemology/coursemology2/issues{/number}","pulls_url":"https://api.github.com/repos/Coursemology/coursemology2/pulls{/number}","milestones_url":"https://api.github.com/repos/Coursemology/coursemology2/milestones{/number}","notifications_url":"https://api.github.com/repos/Coursemology/coursemology2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Coursemology/coursemology2/labels{/name}","releases_url":"https://api.github.com/repos/Coursemology/coursemology2/releases{/id}","created_at":"2014-07-23T14:57:06Z","updated_at":"2015-05-13T05:02:47Z","pushed_at":"2015-05-22T13:39:38Z","git_url":"git://github.com/Coursemology/coursemology2.git","ssh_url":"git@github.com:Coursemology/coursemology2.git","clone_url":"https://github.com/Coursemology/coursemology2.git","svn_url":"https://github.com/Coursemology/coursemology2","homepage":null,"size":4922,"stargazers_count":12,"watchers_count":12,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":46,"forks":9,"open_issues":46,"watchers":12,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Coursemology/coursemology2/pulls/189"},"html":{"href":"https://github.com/Coursemology/coursemology2/pull/189"},"issue":{"href":"https://api.github.com/repos/Coursemology/coursemology2/issues/189"},"comments":{"href":"https://api.github.com/repos/Coursemology/coursemology2/issues/189/comments"},"review_comments":{"href":"https://api.github.com/repos/Coursemology/coursemology2/pulls/189/comments"},"review_comment":{"href":"https://api.github.com/repos/Coursemology/coursemology2/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Coursemology/coursemology2/pulls/189/commits"},"statuses":{"href":"https://api.github.com/repos/Coursemology/coursemology2/statuses/be28ca9f0beaae327d6584833dcc52dee8afc4eb"}}}}