{"action":"created","comment":{"url":"https://api.github.com/repos/WhisperSystems/TextSecure/pulls/comments/24303844","id":24303844,"diff_hunk":"@@ -0,0 +1,180 @@\n+package org.thoughtcrime.securesms.service;\n+\n+import android.app.Service;\n+import android.content.Context;\n+import android.content.Intent;\n+import android.os.IBinder;\n+import android.util.Log;\n+\n+import org.thoughtcrime.securesms.ApplicationContext;\n+import org.thoughtcrime.securesms.dependencies.InjectableType;\n+import org.thoughtcrime.securesms.jobs.PushReceiveJob;\n+import org.thoughtcrime.securesms.util.TextSecurePreferences;\n+import org.whispersystems.jobqueue.requirements.NetworkRequirement;\n+import org.whispersystems.jobqueue.requirements.NetworkRequirementProvider;\n+import org.whispersystems.jobqueue.requirements.RequirementListener;\n+import org.whispersystems.libaxolotl.InvalidVersionException;\n+import org.whispersystems.textsecure.api.TextSecureMessagePipe;\n+import org.whispersystems.textsecure.api.TextSecureMessageReceiver;\n+import org.whispersystems.textsecure.api.messages.TextSecureEnvelope;\n+\n+import java.util.concurrent.TimeUnit;\n+import java.util.concurrent.TimeoutException;\n+\n+import javax.inject.Inject;\n+\n+public class MessageRetrievalService extends Service implements Runnable, InjectableType, RequirementListener {\n+\n+  private static final String TAG = MessageRetrievalService.class.getSimpleName();\n+\n+  public static final  String ACTION_ACTIVITY_STARTED  = \"ACTIVITY_STARTED\";\n+  public static final  String ACTION_ACTIVITY_FINISHED = \"ACTIVITY_FINISHED\";\n+  public static final  String ACTION_PUSH_RECEIVED     = \"PUSH_RECEIVED\";\n+  private static final long   REQUEST_TIMEOUT_MINUTES  = 1;\n+\n+  private NetworkRequirement         networkRequirement;\n+  private NetworkRequirementProvider networkRequirementProvider;\n+\n+  @Inject\n+  public TextSecureMessageReceiver receiver;\n+\n+  private int     activeActivities = 0;\n+  private boolean pushPending      = false;\n+\n+  @Override\n+  public void onCreate() {\n+    super.onCreate();\n+    ApplicationContext.getInstance(this).injectDependencies(this);\n+\n+    networkRequirement         = new NetworkRequirement(this);\n+    networkRequirementProvider = new NetworkRequirementProvider(this);\n+\n+    networkRequirementProvider.setListener(this);\n+    new Thread(this, \"MessageRetrievalService\").start();\n+  }\n+\n+  public int onStartCommand(Intent intent, int flags, int startId) {\n+    if (intent == null) return START_STICKY;\n+\n+    if      (ACTION_ACTIVITY_STARTED.equals(intent.getAction()))  incrementActive();\n+    else if (ACTION_ACTIVITY_FINISHED.equals(intent.getAction())) decrementActive();\n+    else if (ACTION_PUSH_RECEIVED.equals(intent.getAction()))     incrementPushReceived();\n+\n+    return START_STICKY;\n+  }\n+\n+  @Override\n+  public void run() {\n+    while (true) {\n+      Log.w(TAG, \"Waiting for websocket state change....\");\n+      waitForConnectionNecessary();","path":"src/org/thoughtcrime/securesms/service/MessageRetrievalService.java","position":70,"original_position":70,"commit_id":"736473287943d7725480463c04b935dd0dd2f9f4","original_commit_id":"736473287943d7725480463c04b935dd0dd2f9f4","user":{"login":"mcginty","id":373823,"avatar_url":"https://avatars.githubusercontent.com/u/373823?v=3","gravatar_id":"","url":"https://api.github.com/users/mcginty","html_url":"https://github.com/mcginty","followers_url":"https://api.github.com/users/mcginty/followers","following_url":"https://api.github.com/users/mcginty/following{/other_user}","gists_url":"https://api.github.com/users/mcginty/gists{/gist_id}","starred_url":"https://api.github.com/users/mcginty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcginty/subscriptions","organizations_url":"https://api.github.com/users/mcginty/orgs","repos_url":"https://api.github.com/users/mcginty/repos","events_url":"https://api.github.com/users/mcginty/events{/privacy}","received_events_url":"https://api.github.com/users/mcginty/received_events","type":"User","site_admin":false},"body":"this will just be an infinitely looping if isWebsocketRegistered is false?","created_at":"2015-02-08T23:20:15Z","updated_at":"2015-02-08T23:20:15Z","html_url":"https://github.com/WhisperSystems/TextSecure/pull/2423#discussion_r24303844","pull_request_url":"https://api.github.com/repos/WhisperSystems/TextSecure/pulls/2423","_links":{"self":{"href":"https://api.github.com/repos/WhisperSystems/TextSecure/pulls/comments/24303844"},"html":{"href":"https://github.com/WhisperSystems/TextSecure/pull/2423#discussion_r24303844"},"pull_request":{"href":"https://api.github.com/repos/WhisperSystems/TextSecure/pulls/2423"}}},"pull_request":{"url":"https://api.github.com/repos/WhisperSystems/TextSecure/pulls/2423","id":28871923,"html_url":"https://github.com/WhisperSystems/TextSecure/pull/2423","diff_url":"https://github.com/WhisperSystems/TextSecure/pull/2423.diff","patch_url":"https://github.com/WhisperSystems/TextSecure/pull/2423.patch","issue_url":"https://api.github.com/repos/WhisperSystems/TextSecure/issues/2423","number":2423,"state":"open","locked":false,"title":"Store and forward","user":{"login":"moxie0","id":512439,"avatar_url":"https://avatars.githubusercontent.com/u/512439?v=3","gravatar_id":"","url":"https://api.github.com/users/moxie0","html_url":"https://github.com/moxie0","followers_url":"https://api.github.com/users/moxie0/followers","following_url":"https://api.github.com/users/moxie0/following{/other_user}","gists_url":"https://api.github.com/users/moxie0/gists{/gist_id}","starred_url":"https://api.github.com/users/moxie0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/moxie0/subscriptions","organizations_url":"https://api.github.com/users/moxie0/orgs","repos_url":"https://api.github.com/users/moxie0/repos","events_url":"https://api.github.com/users/moxie0/events{/privacy}","received_events_url":"https://api.github.com/users/moxie0/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-02-07T23:10:57Z","updated_at":"2015-02-08T23:20:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"913db0837a014bd4585ba4f427ae43b7ecb40326","assignee":{"login":"mcginty","id":373823,"avatar_url":"https://avatars.githubusercontent.com/u/373823?v=3","gravatar_id":"","url":"https://api.github.com/users/mcginty","html_url":"https://github.com/mcginty","followers_url":"https://api.github.com/users/mcginty/followers","following_url":"https://api.github.com/users/mcginty/following{/other_user}","gists_url":"https://api.github.com/users/mcginty/gists{/gist_id}","starred_url":"https://api.github.com/users/mcginty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcginty/subscriptions","organizations_url":"https://api.github.com/users/mcginty/orgs","repos_url":"https://api.github.com/users/mcginty/repos","events_url":"https://api.github.com/users/mcginty/events{/privacy}","received_events_url":"https://api.github.com/users/mcginty/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/WhisperSystems/TextSecure/pulls/2423/commits","review_comments_url":"https://api.github.com/repos/WhisperSystems/TextSecure/pulls/2423/comments","review_comment_url":"https://api.github.com/repos/WhisperSystems/TextSecure/pulls/comments/{number}","comments_url":"https://api.github.com/repos/WhisperSystems/TextSecure/issues/2423/comments","statuses_url":"https://api.github.com/repos/WhisperSystems/TextSecure/statuses/736473287943d7725480463c04b935dd0dd2f9f4","head":{"label":"WhisperSystems:store_and_forward","ref":"store_and_forward","sha":"736473287943d7725480463c04b935dd0dd2f9f4","user":{"login":"WhisperSystems","id":702459,"avatar_url":"https://avatars.githubusercontent.com/u/702459?v=3","gravatar_id":"","url":"https://api.github.com/users/WhisperSystems","html_url":"https://github.com/WhisperSystems","followers_url":"https://api.github.com/users/WhisperSystems/followers","following_url":"https://api.github.com/users/WhisperSystems/following{/other_user}","gists_url":"https://api.github.com/users/WhisperSystems/gists{/gist_id}","starred_url":"https://api.github.com/users/WhisperSystems/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WhisperSystems/subscriptions","organizations_url":"https://api.github.com/users/WhisperSystems/orgs","repos_url":"https://api.github.com/users/WhisperSystems/repos","events_url":"https://api.github.com/users/WhisperSystems/events{/privacy}","received_events_url":"https://api.github.com/users/WhisperSystems/received_events","type":"Organization","site_admin":false},"repo":{"id":2990192,"name":"TextSecure","full_name":"WhisperSystems/TextSecure","owner":{"login":"WhisperSystems","id":702459,"avatar_url":"https://avatars.githubusercontent.com/u/702459?v=3","gravatar_id":"","url":"https://api.github.com/users/WhisperSystems","html_url":"https://github.com/WhisperSystems","followers_url":"https://api.github.com/users/WhisperSystems/followers","following_url":"https://api.github.com/users/WhisperSystems/following{/other_user}","gists_url":"https://api.github.com/users/WhisperSystems/gists{/gist_id}","starred_url":"https://api.github.com/users/WhisperSystems/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WhisperSystems/subscriptions","organizations_url":"https://api.github.com/users/WhisperSystems/orgs","repos_url":"https://api.github.com/users/WhisperSystems/repos","events_url":"https://api.github.com/users/WhisperSystems/events{/privacy}","received_events_url":"https://api.github.com/users/WhisperSystems/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/WhisperSystems/TextSecure","description":"A secure text messaging application for Android.","fork":false,"url":"https://api.github.com/repos/WhisperSystems/TextSecure","forks_url":"https://api.github.com/repos/WhisperSystems/TextSecure/forks","keys_url":"https://api.github.com/repos/WhisperSystems/TextSecure/keys{/key_id}","collaborators_url":"https://api.github.com/repos/WhisperSystems/TextSecure/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/WhisperSystems/TextSecure/teams","hooks_url":"https://api.github.com/repos/WhisperSystems/TextSecure/hooks","issue_events_url":"https://api.github.com/repos/WhisperSystems/TextSecure/issues/events{/number}","events_url":"https://api.github.com/repos/WhisperSystems/TextSecure/events","assignees_url":"https://api.github.com/repos/WhisperSystems/TextSecure/assignees{/user}","branches_url":"https://api.github.com/repos/WhisperSystems/TextSecure/branches{/branch}","tags_url":"https://api.github.com/repos/WhisperSystems/TextSecure/tags","blobs_url":"https://api.github.com/repos/WhisperSystems/TextSecure/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/WhisperSystems/TextSecure/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/WhisperSystems/TextSecure/git/refs{/sha}","trees_url":"https://api.github.com/repos/WhisperSystems/TextSecure/git/trees{/sha}","statuses_url":"https://api.github.com/repos/WhisperSystems/TextSecure/statuses/{sha}","languages_url":"https://api.github.com/repos/WhisperSystems/TextSecure/languages","stargazers_url":"https://api.github.com/repos/WhisperSystems/TextSecure/stargazers","contributors_url":"https://api.github.com/repos/WhisperSystems/TextSecure/contributors","subscribers_url":"https://api.github.com/repos/WhisperSystems/TextSecure/subscribers","subscription_url":"https://api.github.com/repos/WhisperSystems/TextSecure/subscription","commits_url":"https://api.github.com/repos/WhisperSystems/TextSecure/commits{/sha}","git_commits_url":"https://api.github.com/repos/WhisperSystems/TextSecure/git/commits{/sha}","comments_url":"https://api.github.com/repos/WhisperSystems/TextSecure/comments{/number}","issue_comment_url":"https://api.github.com/repos/WhisperSystems/TextSecure/issues/comments/{number}","contents_url":"https://api.github.com/repos/WhisperSystems/TextSecure/contents/{+path}","compare_url":"https://api.github.com/repos/WhisperSystems/TextSecure/compare/{base}...{head}","merges_url":"https://api.github.com/repos/WhisperSystems/TextSecure/merges","archive_url":"https://api.github.com/repos/WhisperSystems/TextSecure/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/WhisperSystems/TextSecure/downloads","issues_url":"https://api.github.com/repos/WhisperSystems/TextSecure/issues{/number}","pulls_url":"https://api.github.com/repos/WhisperSystems/TextSecure/pulls{/number}","milestones_url":"https://api.github.com/repos/WhisperSystems/TextSecure/milestones{/number}","notifications_url":"https://api.github.com/repos/WhisperSystems/TextSecure/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/WhisperSystems/TextSecure/labels{/name}","releases_url":"https://api.github.com/repos/WhisperSystems/TextSecure/releases{/id}","created_at":"2011-12-15T20:01:12Z","updated_at":"2015-02-08T19:37:39Z","pushed_at":"2015-02-07T23:04:40Z","git_url":"git://github.com/WhisperSystems/TextSecure.git","ssh_url":"git@github.com:WhisperSystems/TextSecure.git","clone_url":"https://github.com/WhisperSystems/TextSecure.git","svn_url":"https://github.com/WhisperSystems/TextSecure","homepage":"","size":59494,"stargazers_count":3438,"watchers_count":3438,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":995,"mirror_url":null,"open_issues_count":522,"forks":995,"open_issues":522,"watchers":3438,"default_branch":"master"}},"base":{"label":"WhisperSystems:master","ref":"master","sha":"8aa0f15740c7efb001f83be0cfe010f3cb211db8","user":{"login":"WhisperSystems","id":702459,"avatar_url":"https://avatars.githubusercontent.com/u/702459?v=3","gravatar_id":"","url":"https://api.github.com/users/WhisperSystems","html_url":"https://github.com/WhisperSystems","followers_url":"https://api.github.com/users/WhisperSystems/followers","following_url":"https://api.github.com/users/WhisperSystems/following{/other_user}","gists_url":"https://api.github.com/users/WhisperSystems/gists{/gist_id}","starred_url":"https://api.github.com/users/WhisperSystems/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WhisperSystems/subscriptions","organizations_url":"https://api.github.com/users/WhisperSystems/orgs","repos_url":"https://api.github.com/users/WhisperSystems/repos","events_url":"https://api.github.com/users/WhisperSystems/events{/privacy}","received_events_url":"https://api.github.com/users/WhisperSystems/received_events","type":"Organization","site_admin":false},"repo":{"id":2990192,"name":"TextSecure","full_name":"WhisperSystems/TextSecure","owner":{"login":"WhisperSystems","id":702459,"avatar_url":"https://avatars.githubusercontent.com/u/702459?v=3","gravatar_id":"","url":"https://api.github.com/users/WhisperSystems","html_url":"https://github.com/WhisperSystems","followers_url":"https://api.github.com/users/WhisperSystems/followers","following_url":"https://api.github.com/users/WhisperSystems/following{/other_user}","gists_url":"https://api.github.com/users/WhisperSystems/gists{/gist_id}","starred_url":"https://api.github.com/users/WhisperSystems/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WhisperSystems/subscriptions","organizations_url":"https://api.github.com/users/WhisperSystems/orgs","repos_url":"https://api.github.com/users/WhisperSystems/repos","events_url":"https://api.github.com/users/WhisperSystems/events{/privacy}","received_events_url":"https://api.github.com/users/WhisperSystems/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/WhisperSystems/TextSecure","description":"A secure text messaging application for Android.","fork":false,"url":"https://api.github.com/repos/WhisperSystems/TextSecure","forks_url":"https://api.github.com/repos/WhisperSystems/TextSecure/forks","keys_url":"https://api.github.com/repos/WhisperSystems/TextSecure/keys{/key_id}","collaborators_url":"https://api.github.com/repos/WhisperSystems/TextSecure/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/WhisperSystems/TextSecure/teams","hooks_url":"https://api.github.com/repos/WhisperSystems/TextSecure/hooks","issue_events_url":"https://api.github.com/repos/WhisperSystems/TextSecure/issues/events{/number}","events_url":"https://api.github.com/repos/WhisperSystems/TextSecure/events","assignees_url":"https://api.github.com/repos/WhisperSystems/TextSecure/assignees{/user}","branches_url":"https://api.github.com/repos/WhisperSystems/TextSecure/branches{/branch}","tags_url":"https://api.github.com/repos/WhisperSystems/TextSecure/tags","blobs_url":"https://api.github.com/repos/WhisperSystems/TextSecure/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/WhisperSystems/TextSecure/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/WhisperSystems/TextSecure/git/refs{/sha}","trees_url":"https://api.github.com/repos/WhisperSystems/TextSecure/git/trees{/sha}","statuses_url":"https://api.github.com/repos/WhisperSystems/TextSecure/statuses/{sha}","languages_url":"https://api.github.com/repos/WhisperSystems/TextSecure/languages","stargazers_url":"https://api.github.com/repos/WhisperSystems/TextSecure/stargazers","contributors_url":"https://api.github.com/repos/WhisperSystems/TextSecure/contributors","subscribers_url":"https://api.github.com/repos/WhisperSystems/TextSecure/subscribers","subscription_url":"https://api.github.com/repos/WhisperSystems/TextSecure/subscription","commits_url":"https://api.github.com/repos/WhisperSystems/TextSecure/commits{/sha}","git_commits_url":"https://api.github.com/repos/WhisperSystems/TextSecure/git/commits{/sha}","comments_url":"https://api.github.com/repos/WhisperSystems/TextSecure/comments{/number}","issue_comment_url":"https://api.github.com/repos/WhisperSystems/TextSecure/issues/comments/{number}","contents_url":"https://api.github.com/repos/WhisperSystems/TextSecure/contents/{+path}","compare_url":"https://api.github.com/repos/WhisperSystems/TextSecure/compare/{base}...{head}","merges_url":"https://api.github.com/repos/WhisperSystems/TextSecure/merges","archive_url":"https://api.github.com/repos/WhisperSystems/TextSecure/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/WhisperSystems/TextSecure/downloads","issues_url":"https://api.github.com/repos/WhisperSystems/TextSecure/issues{/number}","pulls_url":"https://api.github.com/repos/WhisperSystems/TextSecure/pulls{/number}","milestones_url":"https://api.github.com/repos/WhisperSystems/TextSecure/milestones{/number}","notifications_url":"https://api.github.com/repos/WhisperSystems/TextSecure/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/WhisperSystems/TextSecure/labels{/name}","releases_url":"https://api.github.com/repos/WhisperSystems/TextSecure/releases{/id}","created_at":"2011-12-15T20:01:12Z","updated_at":"2015-02-08T19:37:39Z","pushed_at":"2015-02-07T23:04:40Z","git_url":"git://github.com/WhisperSystems/TextSecure.git","ssh_url":"git@github.com:WhisperSystems/TextSecure.git","clone_url":"https://github.com/WhisperSystems/TextSecure.git","svn_url":"https://github.com/WhisperSystems/TextSecure","homepage":"","size":59494,"stargazers_count":3438,"watchers_count":3438,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":995,"mirror_url":null,"open_issues_count":522,"forks":995,"open_issues":522,"watchers":3438,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/WhisperSystems/TextSecure/pulls/2423"},"html":{"href":"https://github.com/WhisperSystems/TextSecure/pull/2423"},"issue":{"href":"https://api.github.com/repos/WhisperSystems/TextSecure/issues/2423"},"comments":{"href":"https://api.github.com/repos/WhisperSystems/TextSecure/issues/2423/comments"},"review_comments":{"href":"https://api.github.com/repos/WhisperSystems/TextSecure/pulls/2423/comments"},"review_comment":{"href":"https://api.github.com/repos/WhisperSystems/TextSecure/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/WhisperSystems/TextSecure/pulls/2423/commits"},"statuses":{"href":"https://api.github.com/repos/WhisperSystems/TextSecure/statuses/736473287943d7725480463c04b935dd0dd2f9f4"}}}}