{"action":"created","comment":{"url":"https://api.github.com/repos/realm/realm-object-store/pulls/comments/81837229","pull_request_review_id":2787850,"id":81837229,"diff_hunk":"@@ -0,0 +1,118 @@\n+////////////////////////////////////////////////////////////////////////////\n+//\n+// Copyright 2016 Realm Inc.\n+//\n+// Licensed under the Apache License, Version 2.0 (the \"License\");\n+// you may not use this file except in compliance with the License.\n+// You may obtain a copy of the License at\n+//\n+// http://www.apache.org/licenses/LICENSE-2.0\n+//\n+// Unless required by applicable law or agreed to in writing, software\n+// distributed under the License is distributed on an \"AS IS\" BASIS,\n+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+// See the License for the specific language governing permissions and\n+// limitations under the License.\n+//\n+////////////////////////////////////////////////////////////////////////////\n+\n+#ifndef REALM_OS_SYNC_USER_HPP\n+#define REALM_OS_SYNC_USER_HPP\n+\n+#include <string>\n+#include <memory>\n+#include <unordered_map>\n+\n+namespace realm {\n+\n+struct SyncSession;\n+\n+// A `SyncUser` represents a single user account. Each user manages the sessions that\n+// are associated with it.\n+class SyncUser {\n+public:\t\n+\tenum class State {\n+\t\tLoggedOut, Active, Error;\n+\t}\n+\n+\t// Don't use this directly; use the `SyncManager` APIs. Public for use with `make_shared`.\n+\tSyncUser(std::string user_token, bool is_admin=false);\n+\n+\t// Return a list of all users.\n+\tstatic std::vector<SyncUser> all_users();","path":"src/sync_user.hpp","position":42,"original_position":42,"commit_id":"5fd233c6714c5196e44da765cd3a3599b584be7d","original_commit_id":"5fd233c6714c5196e44da765cd3a3599b584be7d","user":{"login":"bdash","id":54825,"avatar_url":"https://avatars.githubusercontent.com/u/54825?v=3","gravatar_id":"","url":"https://api.github.com/users/bdash","html_url":"https://github.com/bdash","followers_url":"https://api.github.com/users/bdash/followers","following_url":"https://api.github.com/users/bdash/following{/other_user}","gists_url":"https://api.github.com/users/bdash/gists{/gist_id}","starred_url":"https://api.github.com/users/bdash/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bdash/subscriptions","organizations_url":"https://api.github.com/users/bdash/orgs","repos_url":"https://api.github.com/users/bdash/repos","events_url":"https://api.github.com/users/bdash/events{/privacy}","received_events_url":"https://api.github.com/users/bdash/received_events","type":"User","site_admin":false},"body":"This return type conflicts with your statement that there's only a single `SyncUser` for a given user.","created_at":"2016-10-04T19:42:43Z","updated_at":"2016-10-04T19:42:43Z","html_url":"https://github.com/realm/realm-object-store/pull/185#discussion_r81837229","pull_request_url":"https://api.github.com/repos/realm/realm-object-store/pulls/185","_links":{"self":{"href":"https://api.github.com/repos/realm/realm-object-store/pulls/comments/81837229"},"html":{"href":"https://github.com/realm/realm-object-store/pull/185#discussion_r81837229"},"pull_request":{"href":"https://api.github.com/repos/realm/realm-object-store/pulls/185"}}},"pull_request":{"url":"https://api.github.com/repos/realm/realm-object-store/pulls/185","id":87953064,"html_url":"https://github.com/realm/realm-object-store/pull/185","diff_url":"https://github.com/realm/realm-object-store/pull/185.diff","patch_url":"https://github.com/realm/realm-object-store/pull/185.patch","issue_url":"https://api.github.com/repos/realm/realm-object-store/issues/185","number":185,"state":"open","locked":false,"title":"Proposal for API to move sync functionality into object store","user":{"login":"austinzheng","id":3687054,"avatar_url":"https://avatars.githubusercontent.com/u/3687054?v=3","gravatar_id":"","url":"https://api.github.com/users/austinzheng","html_url":"https://github.com/austinzheng","followers_url":"https://api.github.com/users/austinzheng/followers","following_url":"https://api.github.com/users/austinzheng/following{/other_user}","gists_url":"https://api.github.com/users/austinzheng/gists{/gist_id}","starred_url":"https://api.github.com/users/austinzheng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/austinzheng/subscriptions","organizations_url":"https://api.github.com/users/austinzheng/orgs","repos_url":"https://api.github.com/users/austinzheng/repos","events_url":"https://api.github.com/users/austinzheng/events{/privacy}","received_events_url":"https://api.github.com/users/austinzheng/received_events","type":"User","site_admin":false},"body":"I want to start a conversation, per @alazier's request, about eventually moving most of the sync functionality into the object store. This commit isn't meant to be merged, but rather to propose API changes through header file changes.\r\n\r\n@jpsim @bdash @tgoyne @cmelchior \r\n\r\nThis is what I envision.\r\n\r\n## `SyncUser`\r\n\r\n`SyncUser` is a new object store type. It owns zero or more `SyncSession`s and takes over managing sessions from the `SyncManager`. (The functionality itself remains almost identical, but instead of a session informing the sync manager when it's about to die it informs its parent user, and so forth.)\r\n\r\n## `SyncConfig` changes:\r\n\r\nRather than carrying a string \"tag\" to a user, the config now carries a shared pointer to the user object itself.\r\n\r\n## `SyncManager` changes:\r\n\r\nThe `SyncManager` no longer directly manages sessions. Instead, it now keeps track of `SyncUser`s and creates or vends them out to the binding as desired. (I would like to maintain the invariant of one `SyncUser` object per user, much like how the Cocoa binding treats `RLMUser` today.)\r\n\r\nThe `SyncManager`'s login callback has been changed into a \"bind session\" callback. This callback now passes the following arguments back to the binding:\r\n\r\n* The current user (refresh) token for the user the session belongs to\r\n* The unresolved (containing `/~/`) URL of the session\r\n* A boolean indicating whether the session wants to be `bind()`ed or refreshed\r\n* A `shared_ptr<SyncSession>`\r\n\r\nThe first three arguments are sufficient for the binding to construct a network request to the auth server. The fourth argument gives the binding an object to call the appropriate `bind()` or `refresh()` API on once the network response returns and the JSON has been parsed.\r\n\r\n**NOTE**: Once the new token system is implemented the callback can be removed altogether.\r\n\r\n## Minimum binding requirement\r\n\r\nA hypothetical binding which wanted to support the minimal sync feature set given this new object store design would do the following:\r\n\r\n1. Create a `SyncConfiguration` type which wraps `realm::SyncConfig`, and allow the user to set it as a property on a `RealmConfiguration`, updating the underlying `realm::Realm::Config`.\r\n2. Create a `User` type which wraps a `realm::SyncUser`. This user object needs to be able to make the login call to the auth server using a credential, and might have other APIs like `logOut()`. \r\n3. Set the global \"bind session\" callback.\r\n\r\nThe object store would transparently take care of everything else, from closing sessions upon completion to persisting and loading user info in the metadata database.\r\n","created_at":"2016-10-04T18:57:40Z","updated_at":"2016-10-04T19:46:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3c4a40c066ac0757c92f861ec6db49886cfcb3a3","assignee":{"login":"austinzheng","id":3687054,"avatar_url":"https://avatars.githubusercontent.com/u/3687054?v=3","gravatar_id":"","url":"https://api.github.com/users/austinzheng","html_url":"https://github.com/austinzheng","followers_url":"https://api.github.com/users/austinzheng/followers","following_url":"https://api.github.com/users/austinzheng/following{/other_user}","gists_url":"https://api.github.com/users/austinzheng/gists{/gist_id}","starred_url":"https://api.github.com/users/austinzheng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/austinzheng/subscriptions","organizations_url":"https://api.github.com/users/austinzheng/orgs","repos_url":"https://api.github.com/users/austinzheng/repos","events_url":"https://api.github.com/users/austinzheng/events{/privacy}","received_events_url":"https://api.github.com/users/austinzheng/received_events","type":"User","site_admin":false},"assignees":[{"login":"austinzheng","id":3687054,"avatar_url":"https://avatars.githubusercontent.com/u/3687054?v=3","gravatar_id":"","url":"https://api.github.com/users/austinzheng","html_url":"https://github.com/austinzheng","followers_url":"https://api.github.com/users/austinzheng/followers","following_url":"https://api.github.com/users/austinzheng/following{/other_user}","gists_url":"https://api.github.com/users/austinzheng/gists{/gist_id}","starred_url":"https://api.github.com/users/austinzheng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/austinzheng/subscriptions","organizations_url":"https://api.github.com/users/austinzheng/orgs","repos_url":"https://api.github.com/users/austinzheng/repos","events_url":"https://api.github.com/users/austinzheng/events{/privacy}","received_events_url":"https://api.github.com/users/austinzheng/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/realm/realm-object-store/pulls/185/commits","review_comments_url":"https://api.github.com/repos/realm/realm-object-store/pulls/185/comments","review_comment_url":"https://api.github.com/repos/realm/realm-object-store/pulls/comments{/number}","comments_url":"https://api.github.com/repos/realm/realm-object-store/issues/185/comments","statuses_url":"https://api.github.com/repos/realm/realm-object-store/statuses/5fd233c6714c5196e44da765cd3a3599b584be7d","head":{"label":"realm:az/proposed-sync-api","ref":"az/proposed-sync-api","sha":"5fd233c6714c5196e44da765cd3a3599b584be7d","user":{"login":"realm","id":7575099,"avatar_url":"https://avatars.githubusercontent.com/u/7575099?v=3","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"repo":{"id":36953657,"name":"realm-object-store","full_name":"realm/realm-object-store","owner":{"login":"realm","id":7575099,"avatar_url":"https://avatars.githubusercontent.com/u/7575099?v=3","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/realm/realm-object-store","description":"Cross-platform abstractions used within Realm products","fork":false,"url":"https://api.github.com/repos/realm/realm-object-store","forks_url":"https://api.github.com/repos/realm/realm-object-store/forks","keys_url":"https://api.github.com/repos/realm/realm-object-store/keys{/key_id}","collaborators_url":"https://api.github.com/repos/realm/realm-object-store/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/realm/realm-object-store/teams","hooks_url":"https://api.github.com/repos/realm/realm-object-store/hooks","issue_events_url":"https://api.github.com/repos/realm/realm-object-store/issues/events{/number}","events_url":"https://api.github.com/repos/realm/realm-object-store/events","assignees_url":"https://api.github.com/repos/realm/realm-object-store/assignees{/user}","branches_url":"https://api.github.com/repos/realm/realm-object-store/branches{/branch}","tags_url":"https://api.github.com/repos/realm/realm-object-store/tags","blobs_url":"https://api.github.com/repos/realm/realm-object-store/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/realm/realm-object-store/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/realm/realm-object-store/git/refs{/sha}","trees_url":"https://api.github.com/repos/realm/realm-object-store/git/trees{/sha}","statuses_url":"https://api.github.com/repos/realm/realm-object-store/statuses/{sha}","languages_url":"https://api.github.com/repos/realm/realm-object-store/languages","stargazers_url":"https://api.github.com/repos/realm/realm-object-store/stargazers","contributors_url":"https://api.github.com/repos/realm/realm-object-store/contributors","subscribers_url":"https://api.github.com/repos/realm/realm-object-store/subscribers","subscription_url":"https://api.github.com/repos/realm/realm-object-store/subscription","commits_url":"https://api.github.com/repos/realm/realm-object-store/commits{/sha}","git_commits_url":"https://api.github.com/repos/realm/realm-object-store/git/commits{/sha}","comments_url":"https://api.github.com/repos/realm/realm-object-store/comments{/number}","issue_comment_url":"https://api.github.com/repos/realm/realm-object-store/issues/comments{/number}","contents_url":"https://api.github.com/repos/realm/realm-object-store/contents/{+path}","compare_url":"https://api.github.com/repos/realm/realm-object-store/compare/{base}...{head}","merges_url":"https://api.github.com/repos/realm/realm-object-store/merges","archive_url":"https://api.github.com/repos/realm/realm-object-store/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/realm/realm-object-store/downloads","issues_url":"https://api.github.com/repos/realm/realm-object-store/issues{/number}","pulls_url":"https://api.github.com/repos/realm/realm-object-store/pulls{/number}","milestones_url":"https://api.github.com/repos/realm/realm-object-store/milestones{/number}","notifications_url":"https://api.github.com/repos/realm/realm-object-store/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/realm/realm-object-store/labels{/name}","releases_url":"https://api.github.com/repos/realm/realm-object-store/releases{/id}","deployments_url":"https://api.github.com/repos/realm/realm-object-store/deployments","created_at":"2015-06-05T20:21:52Z","updated_at":"2016-10-02T03:41:23Z","pushed_at":"2016-10-04T19:23:29Z","git_url":"git://github.com/realm/realm-object-store.git","ssh_url":"git@github.com:realm/realm-object-store.git","clone_url":"https://github.com/realm/realm-object-store.git","svn_url":"https://github.com/realm/realm-object-store","homepage":"https://realm.io","size":3245,"stargazers_count":40,"watchers_count":40,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":18,"forks":5,"open_issues":18,"watchers":40,"default_branch":"master"}},"base":{"label":"realm:cocoa","ref":"cocoa","sha":"f2508684ce24d00321886ea3aa0a4d14b84a6ab8","user":{"login":"realm","id":7575099,"avatar_url":"https://avatars.githubusercontent.com/u/7575099?v=3","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"repo":{"id":36953657,"name":"realm-object-store","full_name":"realm/realm-object-store","owner":{"login":"realm","id":7575099,"avatar_url":"https://avatars.githubusercontent.com/u/7575099?v=3","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/realm/realm-object-store","description":"Cross-platform abstractions used within Realm products","fork":false,"url":"https://api.github.com/repos/realm/realm-object-store","forks_url":"https://api.github.com/repos/realm/realm-object-store/forks","keys_url":"https://api.github.com/repos/realm/realm-object-store/keys{/key_id}","collaborators_url":"https://api.github.com/repos/realm/realm-object-store/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/realm/realm-object-store/teams","hooks_url":"https://api.github.com/repos/realm/realm-object-store/hooks","issue_events_url":"https://api.github.com/repos/realm/realm-object-store/issues/events{/number}","events_url":"https://api.github.com/repos/realm/realm-object-store/events","assignees_url":"https://api.github.com/repos/realm/realm-object-store/assignees{/user}","branches_url":"https://api.github.com/repos/realm/realm-object-store/branches{/branch}","tags_url":"https://api.github.com/repos/realm/realm-object-store/tags","blobs_url":"https://api.github.com/repos/realm/realm-object-store/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/realm/realm-object-store/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/realm/realm-object-store/git/refs{/sha}","trees_url":"https://api.github.com/repos/realm/realm-object-store/git/trees{/sha}","statuses_url":"https://api.github.com/repos/realm/realm-object-store/statuses/{sha}","languages_url":"https://api.github.com/repos/realm/realm-object-store/languages","stargazers_url":"https://api.github.com/repos/realm/realm-object-store/stargazers","contributors_url":"https://api.github.com/repos/realm/realm-object-store/contributors","subscribers_url":"https://api.github.com/repos/realm/realm-object-store/subscribers","subscription_url":"https://api.github.com/repos/realm/realm-object-store/subscription","commits_url":"https://api.github.com/repos/realm/realm-object-store/commits{/sha}","git_commits_url":"https://api.github.com/repos/realm/realm-object-store/git/commits{/sha}","comments_url":"https://api.github.com/repos/realm/realm-object-store/comments{/number}","issue_comment_url":"https://api.github.com/repos/realm/realm-object-store/issues/comments{/number}","contents_url":"https://api.github.com/repos/realm/realm-object-store/contents/{+path}","compare_url":"https://api.github.com/repos/realm/realm-object-store/compare/{base}...{head}","merges_url":"https://api.github.com/repos/realm/realm-object-store/merges","archive_url":"https://api.github.com/repos/realm/realm-object-store/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/realm/realm-object-store/downloads","issues_url":"https://api.github.com/repos/realm/realm-object-store/issues{/number}","pulls_url":"https://api.github.com/repos/realm/realm-object-store/pulls{/number}","milestones_url":"https://api.github.com/repos/realm/realm-object-store/milestones{/number}","notifications_url":"https://api.github.com/repos/realm/realm-object-store/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/realm/realm-object-store/labels{/name}","releases_url":"https://api.github.com/repos/realm/realm-object-store/releases{/id}","deployments_url":"https://api.github.com/repos/realm/realm-object-store/deployments","created_at":"2015-06-05T20:21:52Z","updated_at":"2016-10-02T03:41:23Z","pushed_at":"2016-10-04T19:23:29Z","git_url":"git://github.com/realm/realm-object-store.git","ssh_url":"git@github.com:realm/realm-object-store.git","clone_url":"https://github.com/realm/realm-object-store.git","svn_url":"https://github.com/realm/realm-object-store","homepage":"https://realm.io","size":3245,"stargazers_count":40,"watchers_count":40,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":18,"forks":5,"open_issues":18,"watchers":40,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/realm/realm-object-store/pulls/185"},"html":{"href":"https://github.com/realm/realm-object-store/pull/185"},"issue":{"href":"https://api.github.com/repos/realm/realm-object-store/issues/185"},"comments":{"href":"https://api.github.com/repos/realm/realm-object-store/issues/185/comments"},"review_comments":{"href":"https://api.github.com/repos/realm/realm-object-store/pulls/185/comments"},"review_comment":{"href":"https://api.github.com/repos/realm/realm-object-store/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/realm/realm-object-store/pulls/185/commits"},"statuses":{"href":"https://api.github.com/repos/realm/realm-object-store/statuses/5fd233c6714c5196e44da765cd3a3599b584be7d"}}}}
{"actor":{"display_login":"bdash"}}