{"action":"created","comment":{"url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/pulls/comments/54473961","id":54473961,"diff_hunk":"@@ -19,36 +19,71 @@ function factory(brMessagesService, $routeParams) {\n   function Link(scope) {\n     var model = scope.model = {};\n     model.message = null;\n+    model.loading = true;\n \n     brMessagesService.get($routeParams.id)\n       .then(function(result) {\n         model.message = result.data;\n-        scope.$apply();\n+        // TODO: In order to operate prev/next buttons, we have to pull\n+        // in all of the user's messages -- would be nice if\n+        // there was an endpoint that only pulled in a limited\n+        // number of the user's messages\n+        brMessagesService.getAll()\n+          .then(function(result) {\n+            var messages = result.data;\n+            // Only pull in messages that belong to the same archived class as the current message\n+            model.messages = messages.filter(function(message) {\n+              return message.meta.archived === model.message.meta.archived;\n+            });\n+            // Sort the messages by date\n+            model.messages.sort(function(message1, message2) {\n+              return new Date(message1.content.date).getTime() - new Date(message2.content.date).getTime();\n+            });\n+            // Take the message's index so we can operate previous/next\n+            model.index = model.messages.findIndex(function(message) {\n+              return message.id === $routeParams.id;\n+            });\n+            model.loading = false;\n+            scope.$apply();\n+          });\n       });\n \n     model.view = function(id) {\n       $location.url('/messages/' + id);\n     };\n \n-    model.sortClick = function(field) {\n-      switch(field) {\n-        case 'subject':\n-          model.sorting.subject = (model.sorting.subject === '+') ? '-' : '+';\n-          model.orderBy = [\n-            model.sorting.subject + '_id',\n-            model.sorting.date + 'content.date'\n-          ];\n-          break;\n-        case 'date':\n-          model.sorting.date = (model.sorting.date === '+') ? '-' : '+';\n-          model.orderBy = [\n-            model.sorting.date + 'content.date',\n-            model.sorting.subject + '_id'\n-          ];\n-          break;\n+    model.viewMessages = function() {\n+      if(brMessagesService.messageListUrl) {\n+        if(!model.message || !model.message.meta.archived) {\n+          brMessagesService.returningFrom = 'inbox';\n+        } else {\n+          brMessagesService.returningFrom = 'archive';\n+        }\n+        $location.url(brMessagesService.messageListUrl);\n       }\n     };\n \n+    model.delete = function() {\n+      brMessagesService.delete(model.message)\n+        .then(function(result) {\n+          model.viewMessages();\n+          scope.$apply();\n+        }, function(error) {\n+          model.showFailAlert = true;\n+          scope.$apply();\n+        });\n+    };\n+\n+    model.archive = function() {\n+      brMessagesService.archive(model.message)\n+        .then(function(result) {\n+          model.viewMessages();\n+          scope.$apply();\n+        }, function(error) {","path":"message-viewer-directive.js","position":90,"original_position":90,"commit_id":"4c83d746d318fe7960377d2d6fa8a2a0734a9e55","original_commit_id":"4c83d746d318fe7960377d2d6fa8a2a0734a9e55","user":{"login":"lamara","id":3131977,"avatar_url":"https://avatars.githubusercontent.com/u/3131977?v=3","gravatar_id":"","url":"https://api.github.com/users/lamara","html_url":"https://github.com/lamara","followers_url":"https://api.github.com/users/lamara/followers","following_url":"https://api.github.com/users/lamara/following{/other_user}","gists_url":"https://api.github.com/users/lamara/gists{/gist_id}","starred_url":"https://api.github.com/users/lamara/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lamara/subscriptions","organizations_url":"https://api.github.com/users/lamara/orgs","repos_url":"https://api.github.com/users/lamara/repos","events_url":"https://api.github.com/users/lamara/events{/privacy}","received_events_url":"https://api.github.com/users/lamara/received_events","type":"User","site_admin":false},"body":"I remember trying to use .catch syntax, but it didn't play well with the promise returned by the message service (we wrap the http calls in a Promise.resolve() -- I noticed that we could use .catch syntax when we didn't wrap it, but @mattcollier asked to wrap all of our calls so .catch stopped working). Any idea why that's happening? ","created_at":"2016-02-29T20:40:21Z","updated_at":"2016-02-29T20:40:21Z","html_url":"https://github.com/digitalbazaar/bedrock-angular-messages/pull/1#discussion_r54473961","pull_request_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/pulls/comments/54473961"},"html":{"href":"https://github.com/digitalbazaar/bedrock-angular-messages/pull/1#discussion_r54473961"},"pull_request":{"href":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/pulls/1","id":57575603,"html_url":"https://github.com/digitalbazaar/bedrock-angular-messages/pull/1","diff_url":"https://github.com/digitalbazaar/bedrock-angular-messages/pull/1.diff","patch_url":"https://github.com/digitalbazaar/bedrock-angular-messages/pull/1.patch","issue_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/issues/1","number":1,"state":"open","locked":false,"title":"Messaging interface","user":{"login":"mattcollier","id":902041,"avatar_url":"https://avatars.githubusercontent.com/u/902041?v=3","gravatar_id":"","url":"https://api.github.com/users/mattcollier","html_url":"https://github.com/mattcollier","followers_url":"https://api.github.com/users/mattcollier/followers","following_url":"https://api.github.com/users/mattcollier/following{/other_user}","gists_url":"https://api.github.com/users/mattcollier/gists{/gist_id}","starred_url":"https://api.github.com/users/mattcollier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattcollier/subscriptions","organizations_url":"https://api.github.com/users/mattcollier/orgs","repos_url":"https://api.github.com/users/mattcollier/repos","events_url":"https://api.github.com/users/mattcollier/events{/privacy}","received_events_url":"https://api.github.com/users/mattcollier/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-01-28T22:19:36Z","updated_at":"2016-02-29T20:40:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f8c4983b3628e634cc97f8ba907ab58742589148","assignee":{"login":"dlongley","id":168137,"avatar_url":"https://avatars.githubusercontent.com/u/168137?v=3","gravatar_id":"","url":"https://api.github.com/users/dlongley","html_url":"https://github.com/dlongley","followers_url":"https://api.github.com/users/dlongley/followers","following_url":"https://api.github.com/users/dlongley/following{/other_user}","gists_url":"https://api.github.com/users/dlongley/gists{/gist_id}","starred_url":"https://api.github.com/users/dlongley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dlongley/subscriptions","organizations_url":"https://api.github.com/users/dlongley/orgs","repos_url":"https://api.github.com/users/dlongley/repos","events_url":"https://api.github.com/users/dlongley/events{/privacy}","received_events_url":"https://api.github.com/users/dlongley/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/pulls/1/commits","review_comments_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/pulls/1/comments","review_comment_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/pulls/comments{/number}","comments_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/issues/1/comments","statuses_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/statuses/4c83d746d318fe7960377d2d6fa8a2a0734a9e55","head":{"label":"digitalbazaar:messagingInterface","ref":"messagingInterface","sha":"4c83d746d318fe7960377d2d6fa8a2a0734a9e55","user":{"login":"digitalbazaar","id":167436,"avatar_url":"https://avatars.githubusercontent.com/u/167436?v=3","gravatar_id":"","url":"https://api.github.com/users/digitalbazaar","html_url":"https://github.com/digitalbazaar","followers_url":"https://api.github.com/users/digitalbazaar/followers","following_url":"https://api.github.com/users/digitalbazaar/following{/other_user}","gists_url":"https://api.github.com/users/digitalbazaar/gists{/gist_id}","starred_url":"https://api.github.com/users/digitalbazaar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/digitalbazaar/subscriptions","organizations_url":"https://api.github.com/users/digitalbazaar/orgs","repos_url":"https://api.github.com/users/digitalbazaar/repos","events_url":"https://api.github.com/users/digitalbazaar/events{/privacy}","received_events_url":"https://api.github.com/users/digitalbazaar/received_events","type":"Organization","site_admin":false},"repo":{"id":49291824,"name":"bedrock-angular-messages","full_name":"digitalbazaar/bedrock-angular-messages","owner":{"login":"digitalbazaar","id":167436,"avatar_url":"https://avatars.githubusercontent.com/u/167436?v=3","gravatar_id":"","url":"https://api.github.com/users/digitalbazaar","html_url":"https://github.com/digitalbazaar","followers_url":"https://api.github.com/users/digitalbazaar/followers","following_url":"https://api.github.com/users/digitalbazaar/following{/other_user}","gists_url":"https://api.github.com/users/digitalbazaar/gists{/gist_id}","starred_url":"https://api.github.com/users/digitalbazaar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/digitalbazaar/subscriptions","organizations_url":"https://api.github.com/users/digitalbazaar/orgs","repos_url":"https://api.github.com/users/digitalbazaar/repos","events_url":"https://api.github.com/users/digitalbazaar/events{/privacy}","received_events_url":"https://api.github.com/users/digitalbazaar/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/digitalbazaar/bedrock-angular-messages","description":"","fork":false,"url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages","forks_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/forks","keys_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/keys{/key_id}","collaborators_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/teams","hooks_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/hooks","issue_events_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/issues/events{/number}","events_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/events","assignees_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/assignees{/user}","branches_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/branches{/branch}","tags_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/tags","blobs_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/git/refs{/sha}","trees_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/git/trees{/sha}","statuses_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/statuses/{sha}","languages_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/languages","stargazers_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/stargazers","contributors_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/contributors","subscribers_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/subscribers","subscription_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/subscription","commits_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/commits{/sha}","git_commits_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/git/commits{/sha}","comments_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/comments{/number}","issue_comment_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/issues/comments{/number}","contents_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/contents/{+path}","compare_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/compare/{base}...{head}","merges_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/merges","archive_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/downloads","issues_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/issues{/number}","pulls_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/pulls{/number}","milestones_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/milestones{/number}","notifications_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/labels{/name}","releases_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/releases{/id}","deployments_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/deployments","created_at":"2016-01-08T19:27:23Z","updated_at":"2016-01-11T04:08:32Z","pushed_at":"2016-02-24T17:38:19Z","git_url":"git://github.com/digitalbazaar/bedrock-angular-messages.git","ssh_url":"git@github.com:digitalbazaar/bedrock-angular-messages.git","clone_url":"https://github.com/digitalbazaar/bedrock-angular-messages.git","svn_url":"https://github.com/digitalbazaar/bedrock-angular-messages","homepage":null,"size":28,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"digitalbazaar:master","ref":"master","sha":"301edd233d86cec185894b3595ea17ded46dade5","user":{"login":"digitalbazaar","id":167436,"avatar_url":"https://avatars.githubusercontent.com/u/167436?v=3","gravatar_id":"","url":"https://api.github.com/users/digitalbazaar","html_url":"https://github.com/digitalbazaar","followers_url":"https://api.github.com/users/digitalbazaar/followers","following_url":"https://api.github.com/users/digitalbazaar/following{/other_user}","gists_url":"https://api.github.com/users/digitalbazaar/gists{/gist_id}","starred_url":"https://api.github.com/users/digitalbazaar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/digitalbazaar/subscriptions","organizations_url":"https://api.github.com/users/digitalbazaar/orgs","repos_url":"https://api.github.com/users/digitalbazaar/repos","events_url":"https://api.github.com/users/digitalbazaar/events{/privacy}","received_events_url":"https://api.github.com/users/digitalbazaar/received_events","type":"Organization","site_admin":false},"repo":{"id":49291824,"name":"bedrock-angular-messages","full_name":"digitalbazaar/bedrock-angular-messages","owner":{"login":"digitalbazaar","id":167436,"avatar_url":"https://avatars.githubusercontent.com/u/167436?v=3","gravatar_id":"","url":"https://api.github.com/users/digitalbazaar","html_url":"https://github.com/digitalbazaar","followers_url":"https://api.github.com/users/digitalbazaar/followers","following_url":"https://api.github.com/users/digitalbazaar/following{/other_user}","gists_url":"https://api.github.com/users/digitalbazaar/gists{/gist_id}","starred_url":"https://api.github.com/users/digitalbazaar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/digitalbazaar/subscriptions","organizations_url":"https://api.github.com/users/digitalbazaar/orgs","repos_url":"https://api.github.com/users/digitalbazaar/repos","events_url":"https://api.github.com/users/digitalbazaar/events{/privacy}","received_events_url":"https://api.github.com/users/digitalbazaar/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/digitalbazaar/bedrock-angular-messages","description":"","fork":false,"url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages","forks_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/forks","keys_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/keys{/key_id}","collaborators_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/teams","hooks_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/hooks","issue_events_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/issues/events{/number}","events_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/events","assignees_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/assignees{/user}","branches_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/branches{/branch}","tags_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/tags","blobs_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/git/refs{/sha}","trees_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/git/trees{/sha}","statuses_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/statuses/{sha}","languages_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/languages","stargazers_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/stargazers","contributors_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/contributors","subscribers_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/subscribers","subscription_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/subscription","commits_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/commits{/sha}","git_commits_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/git/commits{/sha}","comments_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/comments{/number}","issue_comment_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/issues/comments{/number}","contents_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/contents/{+path}","compare_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/compare/{base}...{head}","merges_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/merges","archive_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/downloads","issues_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/issues{/number}","pulls_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/pulls{/number}","milestones_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/milestones{/number}","notifications_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/labels{/name}","releases_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/releases{/id}","deployments_url":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/deployments","created_at":"2016-01-08T19:27:23Z","updated_at":"2016-01-11T04:08:32Z","pushed_at":"2016-02-24T17:38:19Z","git_url":"git://github.com/digitalbazaar/bedrock-angular-messages.git","ssh_url":"git@github.com:digitalbazaar/bedrock-angular-messages.git","clone_url":"https://github.com/digitalbazaar/bedrock-angular-messages.git","svn_url":"https://github.com/digitalbazaar/bedrock-angular-messages","homepage":null,"size":28,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/pulls/1"},"html":{"href":"https://github.com/digitalbazaar/bedrock-angular-messages/pull/1"},"issue":{"href":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/issues/1"},"comments":{"href":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/digitalbazaar/bedrock-angular-messages/statuses/4c83d746d318fe7960377d2d6fa8a2a0734a9e55"}}}}