{"action":"created","comment":{"url":"https://api.github.com/repos/takahirokawano87/chat-space/pulls/comments/236990572","pull_request_review_id":179181181,"id":236990572,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzNjk5MDU3Mg==","diff_hunk":"@@ -16,36 +18,86 @@ $(function(){\n                         ${image}\n                       </div>\n                     </div>\n-                  </div>`\n-      return html;\n-  }\n-  function scroll() {\n-    $('.chat_main_body').animate({scrollTop: $('.chat_main_body')[0].scrollHeight});\n-  }\n-  $('#new_message').on('submit', function(e){\n-    e.preventDefault();\n-    var formData = new FormData(this);\n-    var url = $(this).attr('action');\n-    $.ajax({\n-      url: url,\n-      type: \"POST\",\n-      data: formData,\n-      dataType: 'json',\n-      processData: false,\n-      contentType: false\n-    })\n-    .done(function(data){\n-      var html = buildHTML(data);\n-      $('.chat_main_body').append(html)\n-      $('.form__message').val('')\n-      $('#message_image').val('')\n-      scroll()\n-    })\n-    .fail(function(){\n-      alert('error');\n-    })\n-    .always(function(){\n-      $(\".form__submit\").removeAttr(\"disabled\");\n+                  </div>`;\n+      return html\n+    }\n+    // メッセージ自動更新時のHTML\n+    function buildMessage(message){\n+      var image = message.image ? `<img src=\"${message.image}\">` : \"\";\n+      var html = `<div class=\"chat_main_body_message\">\n+                    <div class=\"chat_main_body_message clearfix\" data-message-id=\"${message.id}\">\n+                      <div class=\"chat_main_body_message_name\">\n+                        ${message.name}\n+                      </div>\n+                      <div class=\"chat_main_body_message_time\">\n+                        ${message.date}\n+                      </div>\n+                      <div class=\"chat_main_body_message_body\">\n+                        <p class=\"lower-message__content\">\n+                          ${message.content}\n+                        </p>\n+                        ${image}\n+                      </div>\n+                    </div>\n+                  </div>`;\n+      return html\n+    }\n+    // メッセージ自動更新の挙動\n+    var interval = setInterval(function(){\n+      var message_id = $('.chat_main_body_message:last').data('messageId');\n+      if(window.location.href.match(/\\/groups\\/\\d+\\/messages/)){\n+        $.ajax({\n+          url: location.href,\n+          type: 'GET',\n+          data: {message: {id: message_id}},\n+          dataType: 'json'\n+        })\n+        .done(function(json){\n+          var insertHTML = '';\n+          json.new_message.forEach(function(message){\n+            insertHTML += buildMessage(message);\n+          });\n+          $('.chat_main_body').append(insertHTML);\n+          console.log(insertHTML)","path":"app/assets/javascripts/message.js","position":89,"original_position":89,"commit_id":"4bc7cec6771486457c82403651d44abfff5e11e9","original_commit_id":"4bc7cec6771486457c82403651d44abfff5e11e9","user":{"login":"miyagit","id":17040491,"node_id":"MDQ6VXNlcjE3MDQwNDkx","avatar_url":"https://avatars3.githubusercontent.com/u/17040491?v=4","gravatar_id":"","url":"https://api.github.com/users/miyagit","html_url":"https://github.com/miyagit","followers_url":"https://api.github.com/users/miyagit/followers","following_url":"https://api.github.com/users/miyagit/following{/other_user}","gists_url":"https://api.github.com/users/miyagit/gists{/gist_id}","starred_url":"https://api.github.com/users/miyagit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/miyagit/subscriptions","organizations_url":"https://api.github.com/users/miyagit/orgs","repos_url":"https://api.github.com/users/miyagit/repos","events_url":"https://api.github.com/users/miyagit/events{/privacy}","received_events_url":"https://api.github.com/users/miyagit/received_events","type":"User","site_admin":false},"body":"console.logは削除しましょう。","created_at":"2018-11-28T09:00:01Z","updated_at":"2018-11-28T09:00:26Z","html_url":"https://github.com/takahirokawano87/chat-space/pull/7#discussion_r236990572","pull_request_url":"https://api.github.com/repos/takahirokawano87/chat-space/pulls/7","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/takahirokawano87/chat-space/pulls/comments/236990572"},"html":{"href":"https://github.com/takahirokawano87/chat-space/pull/7#discussion_r236990572"},"pull_request":{"href":"https://api.github.com/repos/takahirokawano87/chat-space/pulls/7"}}},"pull_request":{"url":"https://api.github.com/repos/takahirokawano87/chat-space/pulls/7","id":234110141,"node_id":"MDExOlB1bGxSZXF1ZXN0MjM0MTEwMTQx","html_url":"https://github.com/takahirokawano87/chat-space/pull/7","diff_url":"https://github.com/takahirokawano87/chat-space/pull/7.diff","patch_url":"https://github.com/takahirokawano87/chat-space/pull/7.patch","issue_url":"https://api.github.com/repos/takahirokawano87/chat-space/issues/7","number":7,"state":"open","locked":false,"title":"[WIP]自動更新機能の実装","user":{"login":"takahirokawano87","id":44634939,"node_id":"MDQ6VXNlcjQ0NjM0OTM5","avatar_url":"https://avatars1.githubusercontent.com/u/44634939?v=4","gravatar_id":"","url":"https://api.github.com/users/takahirokawano87","html_url":"https://github.com/takahirokawano87","followers_url":"https://api.github.com/users/takahirokawano87/followers","following_url":"https://api.github.com/users/takahirokawano87/following{/other_user}","gists_url":"https://api.github.com/users/takahirokawano87/gists{/gist_id}","starred_url":"https://api.github.com/users/takahirokawano87/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/takahirokawano87/subscriptions","organizations_url":"https://api.github.com/users/takahirokawano87/orgs","repos_url":"https://api.github.com/users/takahirokawano87/repos","events_url":"https://api.github.com/users/takahirokawano87/events{/privacy}","received_events_url":"https://api.github.com/users/takahirokawano87/received_events","type":"User","site_admin":false},"body":"#WHAT\n■自動更新機能の実装\n・定期的に非同期通信を行い、該当グループのメッセージを取得\n・取得したメッセージでメッセージのHTML作成\n・ビューに追加\n\n#WHY\n・機能充実のため\n・自分以外の投稿をリアルタイムで表示するため","created_at":"2018-11-28T00:40:11Z","updated_at":"2018-11-28T09:00:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"677a6c2cdc7d5b91730eac2791dacd6e817e02aa","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/takahirokawano87/chat-space/pulls/7/commits","review_comments_url":"https://api.github.com/repos/takahirokawano87/chat-space/pulls/7/comments","review_comment_url":"https://api.github.com/repos/takahirokawano87/chat-space/pulls/comments{/number}","comments_url":"https://api.github.com/repos/takahirokawano87/chat-space/issues/7/comments","statuses_url":"https://api.github.com/repos/takahirokawano87/chat-space/statuses/4bc7cec6771486457c82403651d44abfff5e11e9","head":{"label":"takahirokawano87:automatic-update-function_implementation","ref":"automatic-update-function_implementation","sha":"4bc7cec6771486457c82403651d44abfff5e11e9","user":{"login":"takahirokawano87","id":44634939,"node_id":"MDQ6VXNlcjQ0NjM0OTM5","avatar_url":"https://avatars1.githubusercontent.com/u/44634939?v=4","gravatar_id":"","url":"https://api.github.com/users/takahirokawano87","html_url":"https://github.com/takahirokawano87","followers_url":"https://api.github.com/users/takahirokawano87/followers","following_url":"https://api.github.com/users/takahirokawano87/following{/other_user}","gists_url":"https://api.github.com/users/takahirokawano87/gists{/gist_id}","starred_url":"https://api.github.com/users/takahirokawano87/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/takahirokawano87/subscriptions","organizations_url":"https://api.github.com/users/takahirokawano87/orgs","repos_url":"https://api.github.com/users/takahirokawano87/repos","events_url":"https://api.github.com/users/takahirokawano87/events{/privacy}","received_events_url":"https://api.github.com/users/takahirokawano87/received_events","type":"User","site_admin":false},"repo":{"id":157188837,"node_id":"MDEwOlJlcG9zaXRvcnkxNTcxODg4Mzc=","name":"chat-space","full_name":"takahirokawano87/chat-space","private":false,"owner":{"login":"takahirokawano87","id":44634939,"node_id":"MDQ6VXNlcjQ0NjM0OTM5","avatar_url":"https://avatars1.githubusercontent.com/u/44634939?v=4","gravatar_id":"","url":"https://api.github.com/users/takahirokawano87","html_url":"https://github.com/takahirokawano87","followers_url":"https://api.github.com/users/takahirokawano87/followers","following_url":"https://api.github.com/users/takahirokawano87/following{/other_user}","gists_url":"https://api.github.com/users/takahirokawano87/gists{/gist_id}","starred_url":"https://api.github.com/users/takahirokawano87/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/takahirokawano87/subscriptions","organizations_url":"https://api.github.com/users/takahirokawano87/orgs","repos_url":"https://api.github.com/users/takahirokawano87/repos","events_url":"https://api.github.com/users/takahirokawano87/events{/privacy}","received_events_url":"https://api.github.com/users/takahirokawano87/received_events","type":"User","site_admin":false},"html_url":"https://github.com/takahirokawano87/chat-space","description":null,"fork":false,"url":"https://api.github.com/repos/takahirokawano87/chat-space","forks_url":"https://api.github.com/repos/takahirokawano87/chat-space/forks","keys_url":"https://api.github.com/repos/takahirokawano87/chat-space/keys{/key_id}","collaborators_url":"https://api.github.com/repos/takahirokawano87/chat-space/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/takahirokawano87/chat-space/teams","hooks_url":"https://api.github.com/repos/takahirokawano87/chat-space/hooks","issue_events_url":"https://api.github.com/repos/takahirokawano87/chat-space/issues/events{/number}","events_url":"https://api.github.com/repos/takahirokawano87/chat-space/events","assignees_url":"https://api.github.com/repos/takahirokawano87/chat-space/assignees{/user}","branches_url":"https://api.github.com/repos/takahirokawano87/chat-space/branches{/branch}","tags_url":"https://api.github.com/repos/takahirokawano87/chat-space/tags","blobs_url":"https://api.github.com/repos/takahirokawano87/chat-space/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/takahirokawano87/chat-space/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/takahirokawano87/chat-space/git/refs{/sha}","trees_url":"https://api.github.com/repos/takahirokawano87/chat-space/git/trees{/sha}","statuses_url":"https://api.github.com/repos/takahirokawano87/chat-space/statuses/{sha}","languages_url":"https://api.github.com/repos/takahirokawano87/chat-space/languages","stargazers_url":"https://api.github.com/repos/takahirokawano87/chat-space/stargazers","contributors_url":"https://api.github.com/repos/takahirokawano87/chat-space/contributors","subscribers_url":"https://api.github.com/repos/takahirokawano87/chat-space/subscribers","subscription_url":"https://api.github.com/repos/takahirokawano87/chat-space/subscription","commits_url":"https://api.github.com/repos/takahirokawano87/chat-space/commits{/sha}","git_commits_url":"https://api.github.com/repos/takahirokawano87/chat-space/git/commits{/sha}","comments_url":"https://api.github.com/repos/takahirokawano87/chat-space/comments{/number}","issue_comment_url":"https://api.github.com/repos/takahirokawano87/chat-space/issues/comments{/number}","contents_url":"https://api.github.com/repos/takahirokawano87/chat-space/contents/{+path}","compare_url":"https://api.github.com/repos/takahirokawano87/chat-space/compare/{base}...{head}","merges_url":"https://api.github.com/repos/takahirokawano87/chat-space/merges","archive_url":"https://api.github.com/repos/takahirokawano87/chat-space/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/takahirokawano87/chat-space/downloads","issues_url":"https://api.github.com/repos/takahirokawano87/chat-space/issues{/number}","pulls_url":"https://api.github.com/repos/takahirokawano87/chat-space/pulls{/number}","milestones_url":"https://api.github.com/repos/takahirokawano87/chat-space/milestones{/number}","notifications_url":"https://api.github.com/repos/takahirokawano87/chat-space/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/takahirokawano87/chat-space/labels{/name}","releases_url":"https://api.github.com/repos/takahirokawano87/chat-space/releases{/id}","deployments_url":"https://api.github.com/repos/takahirokawano87/chat-space/deployments","created_at":"2018-11-12T09:32:30Z","updated_at":"2018-11-27T03:08:49Z","pushed_at":"2018-11-28T08:55:39Z","git_url":"git://github.com/takahirokawano87/chat-space.git","ssh_url":"git@github.com:takahirokawano87/chat-space.git","clone_url":"https://github.com/takahirokawano87/chat-space.git","svn_url":"https://github.com/takahirokawano87/chat-space","homepage":null,"size":102,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"takahirokawano87:master","ref":"master","sha":"a56d63cac412509236215dcdda227460b9521f3a","user":{"login":"takahirokawano87","id":44634939,"node_id":"MDQ6VXNlcjQ0NjM0OTM5","avatar_url":"https://avatars1.githubusercontent.com/u/44634939?v=4","gravatar_id":"","url":"https://api.github.com/users/takahirokawano87","html_url":"https://github.com/takahirokawano87","followers_url":"https://api.github.com/users/takahirokawano87/followers","following_url":"https://api.github.com/users/takahirokawano87/following{/other_user}","gists_url":"https://api.github.com/users/takahirokawano87/gists{/gist_id}","starred_url":"https://api.github.com/users/takahirokawano87/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/takahirokawano87/subscriptions","organizations_url":"https://api.github.com/users/takahirokawano87/orgs","repos_url":"https://api.github.com/users/takahirokawano87/repos","events_url":"https://api.github.com/users/takahirokawano87/events{/privacy}","received_events_url":"https://api.github.com/users/takahirokawano87/received_events","type":"User","site_admin":false},"repo":{"id":157188837,"node_id":"MDEwOlJlcG9zaXRvcnkxNTcxODg4Mzc=","name":"chat-space","full_name":"takahirokawano87/chat-space","private":false,"owner":{"login":"takahirokawano87","id":44634939,"node_id":"MDQ6VXNlcjQ0NjM0OTM5","avatar_url":"https://avatars1.githubusercontent.com/u/44634939?v=4","gravatar_id":"","url":"https://api.github.com/users/takahirokawano87","html_url":"https://github.com/takahirokawano87","followers_url":"https://api.github.com/users/takahirokawano87/followers","following_url":"https://api.github.com/users/takahirokawano87/following{/other_user}","gists_url":"https://api.github.com/users/takahirokawano87/gists{/gist_id}","starred_url":"https://api.github.com/users/takahirokawano87/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/takahirokawano87/subscriptions","organizations_url":"https://api.github.com/users/takahirokawano87/orgs","repos_url":"https://api.github.com/users/takahirokawano87/repos","events_url":"https://api.github.com/users/takahirokawano87/events{/privacy}","received_events_url":"https://api.github.com/users/takahirokawano87/received_events","type":"User","site_admin":false},"html_url":"https://github.com/takahirokawano87/chat-space","description":null,"fork":false,"url":"https://api.github.com/repos/takahirokawano87/chat-space","forks_url":"https://api.github.com/repos/takahirokawano87/chat-space/forks","keys_url":"https://api.github.com/repos/takahirokawano87/chat-space/keys{/key_id}","collaborators_url":"https://api.github.com/repos/takahirokawano87/chat-space/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/takahirokawano87/chat-space/teams","hooks_url":"https://api.github.com/repos/takahirokawano87/chat-space/hooks","issue_events_url":"https://api.github.com/repos/takahirokawano87/chat-space/issues/events{/number}","events_url":"https://api.github.com/repos/takahirokawano87/chat-space/events","assignees_url":"https://api.github.com/repos/takahirokawano87/chat-space/assignees{/user}","branches_url":"https://api.github.com/repos/takahirokawano87/chat-space/branches{/branch}","tags_url":"https://api.github.com/repos/takahirokawano87/chat-space/tags","blobs_url":"https://api.github.com/repos/takahirokawano87/chat-space/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/takahirokawano87/chat-space/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/takahirokawano87/chat-space/git/refs{/sha}","trees_url":"https://api.github.com/repos/takahirokawano87/chat-space/git/trees{/sha}","statuses_url":"https://api.github.com/repos/takahirokawano87/chat-space/statuses/{sha}","languages_url":"https://api.github.com/repos/takahirokawano87/chat-space/languages","stargazers_url":"https://api.github.com/repos/takahirokawano87/chat-space/stargazers","contributors_url":"https://api.github.com/repos/takahirokawano87/chat-space/contributors","subscribers_url":"https://api.github.com/repos/takahirokawano87/chat-space/subscribers","subscription_url":"https://api.github.com/repos/takahirokawano87/chat-space/subscription","commits_url":"https://api.github.com/repos/takahirokawano87/chat-space/commits{/sha}","git_commits_url":"https://api.github.com/repos/takahirokawano87/chat-space/git/commits{/sha}","comments_url":"https://api.github.com/repos/takahirokawano87/chat-space/comments{/number}","issue_comment_url":"https://api.github.com/repos/takahirokawano87/chat-space/issues/comments{/number}","contents_url":"https://api.github.com/repos/takahirokawano87/chat-space/contents/{+path}","compare_url":"https://api.github.com/repos/takahirokawano87/chat-space/compare/{base}...{head}","merges_url":"https://api.github.com/repos/takahirokawano87/chat-space/merges","archive_url":"https://api.github.com/repos/takahirokawano87/chat-space/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/takahirokawano87/chat-space/downloads","issues_url":"https://api.github.com/repos/takahirokawano87/chat-space/issues{/number}","pulls_url":"https://api.github.com/repos/takahirokawano87/chat-space/pulls{/number}","milestones_url":"https://api.github.com/repos/takahirokawano87/chat-space/milestones{/number}","notifications_url":"https://api.github.com/repos/takahirokawano87/chat-space/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/takahirokawano87/chat-space/labels{/name}","releases_url":"https://api.github.com/repos/takahirokawano87/chat-space/releases{/id}","deployments_url":"https://api.github.com/repos/takahirokawano87/chat-space/deployments","created_at":"2018-11-12T09:32:30Z","updated_at":"2018-11-27T03:08:49Z","pushed_at":"2018-11-28T08:55:39Z","git_url":"git://github.com/takahirokawano87/chat-space.git","ssh_url":"git@github.com:takahirokawano87/chat-space.git","clone_url":"https://github.com/takahirokawano87/chat-space.git","svn_url":"https://github.com/takahirokawano87/chat-space","homepage":null,"size":102,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/takahirokawano87/chat-space/pulls/7"},"html":{"href":"https://github.com/takahirokawano87/chat-space/pull/7"},"issue":{"href":"https://api.github.com/repos/takahirokawano87/chat-space/issues/7"},"comments":{"href":"https://api.github.com/repos/takahirokawano87/chat-space/issues/7/comments"},"review_comments":{"href":"https://api.github.com/repos/takahirokawano87/chat-space/pulls/7/comments"},"review_comment":{"href":"https://api.github.com/repos/takahirokawano87/chat-space/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/takahirokawano87/chat-space/pulls/7/commits"},"statuses":{"href":"https://api.github.com/repos/takahirokawano87/chat-space/statuses/4bc7cec6771486457c82403651d44abfff5e11e9"}},"author_association":"OWNER"}}
{"actor":{"display_login":"miyagit"}}