{"action":"created","comment":{"url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/pulls/comments/139979769","pull_request_review_id":63982328,"id":139979769,"diff_hunk":"@@ -262,15 +270,162 @@ MegolmEncryption.prototype._prepareNewSession = async function() {\n  *\n  * @param {module:crypto/algorithms/megolm.OutboundSessionInfo} session\n  *\n+ * @param {object<userId, deviceId>} devicemap\n+ *   mapping from userId to deviceId to {@link module:crypto~OlmSessionResult}\n+ *\n  * @param {object<string, module:crypto/deviceinfo[]>} devicesByUser\n  *    map from userid to list of devices\n  *\n+ * @return {array<object<userid, deviceInfo>>}\n+ */\n+MegolmEncryption.prototype._splitUserDeviceMap = function(\n+    session, devicemap, devicesByUser,\n+) {\n+    const maxToDeviceMessagesPerRequest = 20;\n+\n+    // use an array where the slices of a content map gets stored\n+    const contentMaps = [];\n+    let maxContentMapId = 0; // start inserting in the first contentMap\n+    let currentToDeviceId = 0;\n+\n+    const key = this._olmDevice.getOutboundGroupSessionKey(session.sessionId);\n+\n+    for (const userId in devicesByUser) {\n+        if (!devicesByUser.hasOwnProperty(userId)) {\n+            continue;\n+        }\n+        const devicesToShareWith = devicesByUser[userId];\n+        const sessionResults = devicemap[userId];\n+\n+        for (let i = 0; i < devicesToShareWith.length; i++) {\n+            const deviceInfo = devicesToShareWith[i];\n+            const deviceId = deviceInfo.deviceId;\n+\n+            const sessionResult = sessionResults[deviceId];\n+            if (!sessionResult.sessionId) {\n+                // no session with this device, probably because there\n+                // were no one-time keys.\n+                //\n+                // we could send them a to_device message anyway, as a\n+                // signal that they have missed out on the key sharing\n+                // message because of the lack of keys, but there's not\n+                // much point in that really; it will mostly serve to clog\n+                // up to_device inboxes.\n+\n+                // mark this device as \"handled\" because we don't want to try\n+                // to claim a one-time-key for dead devices on every message.\n+                session.markSharedWithDevice(userId, deviceId, key.chain_index);\n+\n+                // ensureOlmSessionsForUsers has already done the logging,\n+                // so just skip it.\n+                continue;\n+            }\n+\n+            console.log(\n+                \"share keys with device \" + userId + \":\" + deviceId,\n+            );\n+\n+            if (currentToDeviceId > maxToDeviceMessagesPerRequest) {\n+                // the first slice is filled up. Start inserting into the next slice","path":"src/crypto/algorithms/megolm.js","position":75,"original_position":75,"commit_id":"8dffb6231334b8b11d84cc432c848f62fc7d2889","original_commit_id":"8dffb6231334b8b11d84cc432c848f62fc7d2889","user":{"login":"richvdh","id":1389908,"avatar_url":"https://avatars1.githubusercontent.com/u/1389908?v=4","gravatar_id":"","url":"https://api.github.com/users/richvdh","html_url":"https://github.com/richvdh","followers_url":"https://api.github.com/users/richvdh/followers","following_url":"https://api.github.com/users/richvdh/following{/other_user}","gists_url":"https://api.github.com/users/richvdh/gists{/gist_id}","starred_url":"https://api.github.com/users/richvdh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/richvdh/subscriptions","organizations_url":"https://api.github.com/users/richvdh/orgs","repos_url":"https://api.github.com/users/richvdh/repos","events_url":"https://api.github.com/users/richvdh/events{/privacy}","received_events_url":"https://api.github.com/users/richvdh/received_events","type":"User","site_admin":false},"body":"s/first/current/","created_at":"2017-09-20T14:08:14Z","updated_at":"2017-09-20T14:26:52Z","html_url":"https://github.com/matrix-org/matrix-js-sdk/pull/522#discussion_r139979769","pull_request_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/pulls/522","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/matrix-org/matrix-js-sdk/pulls/comments/139979769"},"html":{"href":"https://github.com/matrix-org/matrix-js-sdk/pull/522#discussion_r139979769"},"pull_request":{"href":"https://api.github.com/repos/matrix-org/matrix-js-sdk/pulls/522"}}},"pull_request":{"url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/pulls/522","id":134933636,"html_url":"https://github.com/matrix-org/matrix-js-sdk/pull/522","diff_url":"https://github.com/matrix-org/matrix-js-sdk/pull/522.diff","patch_url":"https://github.com/matrix-org/matrix-js-sdk/pull/522.patch","issue_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/issues/522","number":522,"state":"open","locked":false,"title":"reduce sendToDevice payload","user":{"login":"krombel","id":11167142,"avatar_url":"https://avatars0.githubusercontent.com/u/11167142?v=4","gravatar_id":"","url":"https://api.github.com/users/krombel","html_url":"https://github.com/krombel","followers_url":"https://api.github.com/users/krombel/followers","following_url":"https://api.github.com/users/krombel/following{/other_user}","gists_url":"https://api.github.com/users/krombel/gists{/gist_id}","starred_url":"https://api.github.com/users/krombel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krombel/subscriptions","organizations_url":"https://api.github.com/users/krombel/orgs","repos_url":"https://api.github.com/users/krombel/repos","events_url":"https://api.github.com/users/krombel/events{/privacy}","received_events_url":"https://api.github.com/users/krombel/received_events","type":"User","site_admin":false},"body":"instead of sending one huge request split them up and just do one\r\nrequest for uploading one-time-keys for 20 devices.\r\n\r\nSigned-Off by: Matthias Kesler <krombel@krombel.de>","created_at":"2017-08-09T16:17:55Z","updated_at":"2017-09-20T14:26:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9349bc57d5ce5e3df7474078ddc9a1bb55241cf6","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/pulls/522/commits","review_comments_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/pulls/522/comments","review_comment_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/pulls/comments{/number}","comments_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/issues/522/comments","statuses_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/statuses/8dffb6231334b8b11d84cc432c848f62fc7d2889","head":{"label":"krombel:reduce_sendToDevice_payload","ref":"reduce_sendToDevice_payload","sha":"8dffb6231334b8b11d84cc432c848f62fc7d2889","user":{"login":"krombel","id":11167142,"avatar_url":"https://avatars0.githubusercontent.com/u/11167142?v=4","gravatar_id":"","url":"https://api.github.com/users/krombel","html_url":"https://github.com/krombel","followers_url":"https://api.github.com/users/krombel/followers","following_url":"https://api.github.com/users/krombel/following{/other_user}","gists_url":"https://api.github.com/users/krombel/gists{/gist_id}","starred_url":"https://api.github.com/users/krombel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krombel/subscriptions","organizations_url":"https://api.github.com/users/krombel/orgs","repos_url":"https://api.github.com/users/krombel/repos","events_url":"https://api.github.com/users/krombel/events{/privacy}","received_events_url":"https://api.github.com/users/krombel/received_events","type":"User","site_admin":false},"repo":{"id":91661256,"name":"matrix-js-sdk","full_name":"krombel/matrix-js-sdk","owner":{"login":"krombel","id":11167142,"avatar_url":"https://avatars0.githubusercontent.com/u/11167142?v=4","gravatar_id":"","url":"https://api.github.com/users/krombel","html_url":"https://github.com/krombel","followers_url":"https://api.github.com/users/krombel/followers","following_url":"https://api.github.com/users/krombel/following{/other_user}","gists_url":"https://api.github.com/users/krombel/gists{/gist_id}","starred_url":"https://api.github.com/users/krombel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krombel/subscriptions","organizations_url":"https://api.github.com/users/krombel/orgs","repos_url":"https://api.github.com/users/krombel/repos","events_url":"https://api.github.com/users/krombel/events{/privacy}","received_events_url":"https://api.github.com/users/krombel/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/krombel/matrix-js-sdk","description":"Matrix Client-Server SDK for JavaScript","fork":true,"url":"https://api.github.com/repos/krombel/matrix-js-sdk","forks_url":"https://api.github.com/repos/krombel/matrix-js-sdk/forks","keys_url":"https://api.github.com/repos/krombel/matrix-js-sdk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/krombel/matrix-js-sdk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/krombel/matrix-js-sdk/teams","hooks_url":"https://api.github.com/repos/krombel/matrix-js-sdk/hooks","issue_events_url":"https://api.github.com/repos/krombel/matrix-js-sdk/issues/events{/number}","events_url":"https://api.github.com/repos/krombel/matrix-js-sdk/events","assignees_url":"https://api.github.com/repos/krombel/matrix-js-sdk/assignees{/user}","branches_url":"https://api.github.com/repos/krombel/matrix-js-sdk/branches{/branch}","tags_url":"https://api.github.com/repos/krombel/matrix-js-sdk/tags","blobs_url":"https://api.github.com/repos/krombel/matrix-js-sdk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/krombel/matrix-js-sdk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/krombel/matrix-js-sdk/git/refs{/sha}","trees_url":"https://api.github.com/repos/krombel/matrix-js-sdk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/krombel/matrix-js-sdk/statuses/{sha}","languages_url":"https://api.github.com/repos/krombel/matrix-js-sdk/languages","stargazers_url":"https://api.github.com/repos/krombel/matrix-js-sdk/stargazers","contributors_url":"https://api.github.com/repos/krombel/matrix-js-sdk/contributors","subscribers_url":"https://api.github.com/repos/krombel/matrix-js-sdk/subscribers","subscription_url":"https://api.github.com/repos/krombel/matrix-js-sdk/subscription","commits_url":"https://api.github.com/repos/krombel/matrix-js-sdk/commits{/sha}","git_commits_url":"https://api.github.com/repos/krombel/matrix-js-sdk/git/commits{/sha}","comments_url":"https://api.github.com/repos/krombel/matrix-js-sdk/comments{/number}","issue_comment_url":"https://api.github.com/repos/krombel/matrix-js-sdk/issues/comments{/number}","contents_url":"https://api.github.com/repos/krombel/matrix-js-sdk/contents/{+path}","compare_url":"https://api.github.com/repos/krombel/matrix-js-sdk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/krombel/matrix-js-sdk/merges","archive_url":"https://api.github.com/repos/krombel/matrix-js-sdk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/krombel/matrix-js-sdk/downloads","issues_url":"https://api.github.com/repos/krombel/matrix-js-sdk/issues{/number}","pulls_url":"https://api.github.com/repos/krombel/matrix-js-sdk/pulls{/number}","milestones_url":"https://api.github.com/repos/krombel/matrix-js-sdk/milestones{/number}","notifications_url":"https://api.github.com/repos/krombel/matrix-js-sdk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/krombel/matrix-js-sdk/labels{/name}","releases_url":"https://api.github.com/repos/krombel/matrix-js-sdk/releases{/id}","deployments_url":"https://api.github.com/repos/krombel/matrix-js-sdk/deployments","created_at":"2017-05-18T07:14:17Z","updated_at":"2017-06-24T10:05:48Z","pushed_at":"2017-09-19T00:19:49Z","git_url":"git://github.com/krombel/matrix-js-sdk.git","ssh_url":"git@github.com:krombel/matrix-js-sdk.git","clone_url":"https://github.com/krombel/matrix-js-sdk.git","svn_url":"https://github.com/krombel/matrix-js-sdk","homepage":"","size":12208,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"develop"}},"base":{"label":"matrix-org:develop","ref":"develop","sha":"068939f7904e3c44a741afa0010418fd110751e8","user":{"login":"matrix-org","id":8418310,"avatar_url":"https://avatars2.githubusercontent.com/u/8418310?v=4","gravatar_id":"","url":"https://api.github.com/users/matrix-org","html_url":"https://github.com/matrix-org","followers_url":"https://api.github.com/users/matrix-org/followers","following_url":"https://api.github.com/users/matrix-org/following{/other_user}","gists_url":"https://api.github.com/users/matrix-org/gists{/gist_id}","starred_url":"https://api.github.com/users/matrix-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matrix-org/subscriptions","organizations_url":"https://api.github.com/users/matrix-org/orgs","repos_url":"https://api.github.com/users/matrix-org/repos","events_url":"https://api.github.com/users/matrix-org/events{/privacy}","received_events_url":"https://api.github.com/users/matrix-org/received_events","type":"Organization","site_admin":false},"repo":{"id":31670053,"name":"matrix-js-sdk","full_name":"matrix-org/matrix-js-sdk","owner":{"login":"matrix-org","id":8418310,"avatar_url":"https://avatars2.githubusercontent.com/u/8418310?v=4","gravatar_id":"","url":"https://api.github.com/users/matrix-org","html_url":"https://github.com/matrix-org","followers_url":"https://api.github.com/users/matrix-org/followers","following_url":"https://api.github.com/users/matrix-org/following{/other_user}","gists_url":"https://api.github.com/users/matrix-org/gists{/gist_id}","starred_url":"https://api.github.com/users/matrix-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matrix-org/subscriptions","organizations_url":"https://api.github.com/users/matrix-org/orgs","repos_url":"https://api.github.com/users/matrix-org/repos","events_url":"https://api.github.com/users/matrix-org/events{/privacy}","received_events_url":"https://api.github.com/users/matrix-org/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/matrix-org/matrix-js-sdk","description":"Matrix Client-Server SDK for JavaScript","fork":false,"url":"https://api.github.com/repos/matrix-org/matrix-js-sdk","forks_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/forks","keys_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/teams","hooks_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/hooks","issue_events_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/issues/events{/number}","events_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/events","assignees_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/assignees{/user}","branches_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/branches{/branch}","tags_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/tags","blobs_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/git/refs{/sha}","trees_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/statuses/{sha}","languages_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/languages","stargazers_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/stargazers","contributors_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/contributors","subscribers_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/subscribers","subscription_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/subscription","commits_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/commits{/sha}","git_commits_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/git/commits{/sha}","comments_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/comments{/number}","issue_comment_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/issues/comments{/number}","contents_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/contents/{+path}","compare_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/merges","archive_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/downloads","issues_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/issues{/number}","pulls_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/pulls{/number}","milestones_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/milestones{/number}","notifications_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/labels{/name}","releases_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/releases{/id}","deployments_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/deployments","created_at":"2015-03-04T17:28:51Z","updated_at":"2017-09-15T22:05:20Z","pushed_at":"2017-09-20T14:06:52Z","git_url":"git://github.com/matrix-org/matrix-js-sdk.git","ssh_url":"git@github.com:matrix-org/matrix-js-sdk.git","clone_url":"https://github.com/matrix-org/matrix-js-sdk.git","svn_url":"https://github.com/matrix-org/matrix-js-sdk","homepage":"","size":14271,"stargazers_count":122,"watchers_count":122,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":52,"mirror_url":null,"open_issues_count":60,"forks":52,"open_issues":60,"watchers":122,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/matrix-org/matrix-js-sdk/pulls/522"},"html":{"href":"https://github.com/matrix-org/matrix-js-sdk/pull/522"},"issue":{"href":"https://api.github.com/repos/matrix-org/matrix-js-sdk/issues/522"},"comments":{"href":"https://api.github.com/repos/matrix-org/matrix-js-sdk/issues/522/comments"},"review_comments":{"href":"https://api.github.com/repos/matrix-org/matrix-js-sdk/pulls/522/comments"},"review_comment":{"href":"https://api.github.com/repos/matrix-org/matrix-js-sdk/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/matrix-org/matrix-js-sdk/pulls/522/commits"},"statuses":{"href":"https://api.github.com/repos/matrix-org/matrix-js-sdk/statuses/8dffb6231334b8b11d84cc432c848f62fc7d2889"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"richvdh"}}