{"action":"created","comment":{"url":"https://api.github.com/repos/nylas/N1/pulls/comments/60491470","id":60491470,"diff_hunk":"@@ -0,0 +1,140 @@\n+{Utils, DraftStore, React} = require 'nylas-exports'\n+PGPKeyStore = require './pgp-key-store'\n+{RetinaImg} = require 'nylas-component-kit'\n+pgp = require 'kbpgp'\n+_ = require 'underscore'\n+\n+class EncryptMessageButton extends React.Component\n+\n+  @displayName: 'EncryptMessageButton'\n+\n+  # require that we have a draft object available\n+  @propTypes:\n+    draftClientId: React.PropTypes.string.isRequired\n+\n+  constructor: (props) ->\n+    super(props)\n+    @state = @_getStateFromStores()\n+\n+    # maintain the state of the button's toggle\n+    @state.currentlyEncrypted = false\n+\n+    # store the message's plaintext in case the user wants to edit further after\n+    # hitting the \"encrypt\" button (i.e. so we can \"undo\" the encryption)\n+    @state.plaintext = \"\"\n+\n+    # store the message's body here, for comparison purposes (so that if the\n+    # user edits an encrypted message, we can revert it)\n+    @state.cryptotext = \"\"\n+\n+  componentDidMount: ->\n+    @unlistenKeystore = PGPKeyStore.listen(@_onKeystoreChange, @)\n+    # periodically check to see if we should get any keys\n+    @interval = setInterval(@_onTrigger, 100)\n+\n+  componentWillUnmount: ->\n+    @unlistenKeystore()\n+    clearInterval(@interval)\n+\n+  _getStateFromStores: ->\n+    keys = []\n+    DraftStore.sessionForClientId(@props.draftClientId).then (session) =>\n+      for recipient in session.draft().to\n+        publicKeys = PGPKeyStore.pubKeys(recipient.email)\n+        if publicKeys.length < 1\n+          # no key for this user:\n+          # push a null so that @_encrypt can line this array up with the\n+          # array of recipients\n+          keys.push({address: recipient.email, key: null})\n+        else\n+          # note: this, by default, encrypts using every public key associated\n+          # with the address\n+          for publicKey in publicKeys\n+            if not publicKey.key?\n+              PGPKeyStore.getKeyContents(key: publicKey)\n+            else\n+              keys.push(publicKey)\n+\n+    return {\n+      keys: keys\n+    }\n+\n+  _onKeystoreChange: =>\n+    if @state.currentlyEncrypted\n+      # message is no longer encrypted with all keys - decrypt it!\n+      @_toggleCrypt()\n+    # now actually get the new keys\n+    @setState(@_getStateFromStores())\n+\n+  _onTrigger: =>\n+    # Some sort of outside event has occured that we must respond to\n+    DraftStore.sessionForClientId(@props.draftClientId).then (session) =>","path":"internal_packages/keybase/lib/encrypt-button.cjsx","position":71,"original_position":71,"commit_id":"4081ad7ef2b4375f5665904eb2d61992bab9cf4d","original_commit_id":"4081ad7ef2b4375f5665904eb2d61992bab9cf4d","user":{"login":"bengotow","id":1037212,"avatar_url":"https://avatars.githubusercontent.com/u/1037212?v=3","gravatar_id":"","url":"https://api.github.com/users/bengotow","html_url":"https://github.com/bengotow","followers_url":"https://api.github.com/users/bengotow/followers","following_url":"https://api.github.com/users/bengotow/following{/other_user}","gists_url":"https://api.github.com/users/bengotow/gists{/gist_id}","starred_url":"https://api.github.com/users/bengotow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bengotow/subscriptions","organizations_url":"https://api.github.com/users/bengotow/orgs","repos_url":"https://api.github.com/users/bengotow/repos","events_url":"https://api.github.com/users/bengotow/events{/privacy}","received_events_url":"https://api.github.com/users/bengotow/received_events","type":"User","site_admin":false},"body":"I think we can safely move this to `componentWillReceiveProps`","created_at":"2016-04-20T21:30:49Z","updated_at":"2016-04-20T21:30:49Z","html_url":"https://github.com/nylas/N1/pull/2011#discussion_r60491470","pull_request_url":"https://api.github.com/repos/nylas/N1/pulls/2011","_links":{"self":{"href":"https://api.github.com/repos/nylas/N1/pulls/comments/60491470"},"html":{"href":"https://github.com/nylas/N1/pull/2011#discussion_r60491470"},"pull_request":{"href":"https://api.github.com/repos/nylas/N1/pulls/2011"}}},"pull_request":{"url":"https://api.github.com/repos/nylas/N1/pulls/2011","id":67244864,"html_url":"https://github.com/nylas/N1/pull/2011","diff_url":"https://github.com/nylas/N1/pull/2011.diff","patch_url":"https://github.com/nylas/N1/pull/2011.patch","issue_url":"https://api.github.com/repos/nylas/N1/issues/2011","number":2011,"state":"open","locked":false,"title":"feat(keybase): Initial commit from n1-keybase repo","user":{"login":"DakotaNelson","id":6242741,"avatar_url":"https://avatars.githubusercontent.com/u/6242741?v=3","gravatar_id":"","url":"https://api.github.com/users/DakotaNelson","html_url":"https://github.com/DakotaNelson","followers_url":"https://api.github.com/users/DakotaNelson/followers","following_url":"https://api.github.com/users/DakotaNelson/following{/other_user}","gists_url":"https://api.github.com/users/DakotaNelson/gists{/gist_id}","starred_url":"https://api.github.com/users/DakotaNelson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DakotaNelson/subscriptions","organizations_url":"https://api.github.com/users/DakotaNelson/orgs","repos_url":"https://api.github.com/users/DakotaNelson/repos","events_url":"https://api.github.com/users/DakotaNelson/events{/privacy}","received_events_url":"https://api.github.com/users/DakotaNelson/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-04-20T19:32:27Z","updated_at":"2016-04-20T21:30:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1cfa6047e77d9269ee9811f13dc79dc31436882a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/nylas/N1/pulls/2011/commits","review_comments_url":"https://api.github.com/repos/nylas/N1/pulls/2011/comments","review_comment_url":"https://api.github.com/repos/nylas/N1/pulls/comments{/number}","comments_url":"https://api.github.com/repos/nylas/N1/issues/2011/comments","statuses_url":"https://api.github.com/repos/nylas/N1/statuses/4081ad7ef2b4375f5665904eb2d61992bab9cf4d","head":{"label":"nylas:wip/keybase","ref":"wip/keybase","sha":"4081ad7ef2b4375f5665904eb2d61992bab9cf4d","user":{"login":"nylas","id":4219865,"avatar_url":"https://avatars.githubusercontent.com/u/4219865?v=3","gravatar_id":"","url":"https://api.github.com/users/nylas","html_url":"https://github.com/nylas","followers_url":"https://api.github.com/users/nylas/followers","following_url":"https://api.github.com/users/nylas/following{/other_user}","gists_url":"https://api.github.com/users/nylas/gists{/gist_id}","starred_url":"https://api.github.com/users/nylas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nylas/subscriptions","organizations_url":"https://api.github.com/users/nylas/orgs","repos_url":"https://api.github.com/users/nylas/repos","events_url":"https://api.github.com/users/nylas/events{/privacy}","received_events_url":"https://api.github.com/users/nylas/received_events","type":"Organization","site_admin":false},"repo":{"id":25315643,"name":"N1","full_name":"nylas/N1","owner":{"login":"nylas","id":4219865,"avatar_url":"https://avatars.githubusercontent.com/u/4219865?v=3","gravatar_id":"","url":"https://api.github.com/users/nylas","html_url":"https://github.com/nylas","followers_url":"https://api.github.com/users/nylas/followers","following_url":"https://api.github.com/users/nylas/following{/other_user}","gists_url":"https://api.github.com/users/nylas/gists{/gist_id}","starred_url":"https://api.github.com/users/nylas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nylas/subscriptions","organizations_url":"https://api.github.com/users/nylas/orgs","repos_url":"https://api.github.com/users/nylas/repos","events_url":"https://api.github.com/users/nylas/events{/privacy}","received_events_url":"https://api.github.com/users/nylas/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nylas/N1","description":":love_letter: An extensible desktop mail app built on the modern web.","fork":false,"url":"https://api.github.com/repos/nylas/N1","forks_url":"https://api.github.com/repos/nylas/N1/forks","keys_url":"https://api.github.com/repos/nylas/N1/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nylas/N1/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nylas/N1/teams","hooks_url":"https://api.github.com/repos/nylas/N1/hooks","issue_events_url":"https://api.github.com/repos/nylas/N1/issues/events{/number}","events_url":"https://api.github.com/repos/nylas/N1/events","assignees_url":"https://api.github.com/repos/nylas/N1/assignees{/user}","branches_url":"https://api.github.com/repos/nylas/N1/branches{/branch}","tags_url":"https://api.github.com/repos/nylas/N1/tags","blobs_url":"https://api.github.com/repos/nylas/N1/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nylas/N1/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nylas/N1/git/refs{/sha}","trees_url":"https://api.github.com/repos/nylas/N1/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nylas/N1/statuses/{sha}","languages_url":"https://api.github.com/repos/nylas/N1/languages","stargazers_url":"https://api.github.com/repos/nylas/N1/stargazers","contributors_url":"https://api.github.com/repos/nylas/N1/contributors","subscribers_url":"https://api.github.com/repos/nylas/N1/subscribers","subscription_url":"https://api.github.com/repos/nylas/N1/subscription","commits_url":"https://api.github.com/repos/nylas/N1/commits{/sha}","git_commits_url":"https://api.github.com/repos/nylas/N1/git/commits{/sha}","comments_url":"https://api.github.com/repos/nylas/N1/comments{/number}","issue_comment_url":"https://api.github.com/repos/nylas/N1/issues/comments{/number}","contents_url":"https://api.github.com/repos/nylas/N1/contents/{+path}","compare_url":"https://api.github.com/repos/nylas/N1/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nylas/N1/merges","archive_url":"https://api.github.com/repos/nylas/N1/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nylas/N1/downloads","issues_url":"https://api.github.com/repos/nylas/N1/issues{/number}","pulls_url":"https://api.github.com/repos/nylas/N1/pulls{/number}","milestones_url":"https://api.github.com/repos/nylas/N1/milestones{/number}","notifications_url":"https://api.github.com/repos/nylas/N1/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nylas/N1/labels{/name}","releases_url":"https://api.github.com/repos/nylas/N1/releases{/id}","deployments_url":"https://api.github.com/repos/nylas/N1/deployments","created_at":"2014-10-16T18:29:12Z","updated_at":"2016-04-20T21:18:06Z","pushed_at":"2016-04-20T19:32:27Z","git_url":"git://github.com/nylas/N1.git","ssh_url":"git@github.com:nylas/N1.git","clone_url":"https://github.com/nylas/N1.git","svn_url":"https://github.com/nylas/N1","homepage":"https://nylas.com/N1","size":76997,"stargazers_count":16905,"watchers_count":16905,"language":"CoffeeScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":599,"mirror_url":null,"open_issues_count":575,"forks":599,"open_issues":575,"watchers":16905,"default_branch":"master"}},"base":{"label":"nylas:master","ref":"master","sha":"aecb6f7953a35d8aaf2211130f313344cd7caf61","user":{"login":"nylas","id":4219865,"avatar_url":"https://avatars.githubusercontent.com/u/4219865?v=3","gravatar_id":"","url":"https://api.github.com/users/nylas","html_url":"https://github.com/nylas","followers_url":"https://api.github.com/users/nylas/followers","following_url":"https://api.github.com/users/nylas/following{/other_user}","gists_url":"https://api.github.com/users/nylas/gists{/gist_id}","starred_url":"https://api.github.com/users/nylas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nylas/subscriptions","organizations_url":"https://api.github.com/users/nylas/orgs","repos_url":"https://api.github.com/users/nylas/repos","events_url":"https://api.github.com/users/nylas/events{/privacy}","received_events_url":"https://api.github.com/users/nylas/received_events","type":"Organization","site_admin":false},"repo":{"id":25315643,"name":"N1","full_name":"nylas/N1","owner":{"login":"nylas","id":4219865,"avatar_url":"https://avatars.githubusercontent.com/u/4219865?v=3","gravatar_id":"","url":"https://api.github.com/users/nylas","html_url":"https://github.com/nylas","followers_url":"https://api.github.com/users/nylas/followers","following_url":"https://api.github.com/users/nylas/following{/other_user}","gists_url":"https://api.github.com/users/nylas/gists{/gist_id}","starred_url":"https://api.github.com/users/nylas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nylas/subscriptions","organizations_url":"https://api.github.com/users/nylas/orgs","repos_url":"https://api.github.com/users/nylas/repos","events_url":"https://api.github.com/users/nylas/events{/privacy}","received_events_url":"https://api.github.com/users/nylas/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nylas/N1","description":":love_letter: An extensible desktop mail app built on the modern web.","fork":false,"url":"https://api.github.com/repos/nylas/N1","forks_url":"https://api.github.com/repos/nylas/N1/forks","keys_url":"https://api.github.com/repos/nylas/N1/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nylas/N1/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nylas/N1/teams","hooks_url":"https://api.github.com/repos/nylas/N1/hooks","issue_events_url":"https://api.github.com/repos/nylas/N1/issues/events{/number}","events_url":"https://api.github.com/repos/nylas/N1/events","assignees_url":"https://api.github.com/repos/nylas/N1/assignees{/user}","branches_url":"https://api.github.com/repos/nylas/N1/branches{/branch}","tags_url":"https://api.github.com/repos/nylas/N1/tags","blobs_url":"https://api.github.com/repos/nylas/N1/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nylas/N1/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nylas/N1/git/refs{/sha}","trees_url":"https://api.github.com/repos/nylas/N1/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nylas/N1/statuses/{sha}","languages_url":"https://api.github.com/repos/nylas/N1/languages","stargazers_url":"https://api.github.com/repos/nylas/N1/stargazers","contributors_url":"https://api.github.com/repos/nylas/N1/contributors","subscribers_url":"https://api.github.com/repos/nylas/N1/subscribers","subscription_url":"https://api.github.com/repos/nylas/N1/subscription","commits_url":"https://api.github.com/repos/nylas/N1/commits{/sha}","git_commits_url":"https://api.github.com/repos/nylas/N1/git/commits{/sha}","comments_url":"https://api.github.com/repos/nylas/N1/comments{/number}","issue_comment_url":"https://api.github.com/repos/nylas/N1/issues/comments{/number}","contents_url":"https://api.github.com/repos/nylas/N1/contents/{+path}","compare_url":"https://api.github.com/repos/nylas/N1/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nylas/N1/merges","archive_url":"https://api.github.com/repos/nylas/N1/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nylas/N1/downloads","issues_url":"https://api.github.com/repos/nylas/N1/issues{/number}","pulls_url":"https://api.github.com/repos/nylas/N1/pulls{/number}","milestones_url":"https://api.github.com/repos/nylas/N1/milestones{/number}","notifications_url":"https://api.github.com/repos/nylas/N1/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nylas/N1/labels{/name}","releases_url":"https://api.github.com/repos/nylas/N1/releases{/id}","deployments_url":"https://api.github.com/repos/nylas/N1/deployments","created_at":"2014-10-16T18:29:12Z","updated_at":"2016-04-20T21:18:06Z","pushed_at":"2016-04-20T19:32:27Z","git_url":"git://github.com/nylas/N1.git","ssh_url":"git@github.com:nylas/N1.git","clone_url":"https://github.com/nylas/N1.git","svn_url":"https://github.com/nylas/N1","homepage":"https://nylas.com/N1","size":76997,"stargazers_count":16905,"watchers_count":16905,"language":"CoffeeScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":599,"mirror_url":null,"open_issues_count":575,"forks":599,"open_issues":575,"watchers":16905,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nylas/N1/pulls/2011"},"html":{"href":"https://github.com/nylas/N1/pull/2011"},"issue":{"href":"https://api.github.com/repos/nylas/N1/issues/2011"},"comments":{"href":"https://api.github.com/repos/nylas/N1/issues/2011/comments"},"review_comments":{"href":"https://api.github.com/repos/nylas/N1/pulls/2011/comments"},"review_comment":{"href":"https://api.github.com/repos/nylas/N1/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/nylas/N1/pulls/2011/commits"},"statuses":{"href":"https://api.github.com/repos/nylas/N1/statuses/4081ad7ef2b4375f5665904eb2d61992bab9cf4d"}}}}