{"action":"created","comment":{"url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/pulls/comments/50867390","id":50867390,"diff_hunk":"@@ -284,54 +546,12 @@ Room.prototype.addEventsToTimeline = function(events, toStartOfTimeline) {\n             }\n         }\n \n-        setEventMetadata(events[i], stateContext, toStartOfTimeline);\n-        // modify state\n-        if (events[i].isState()) {\n-            stateContext.setStateEvents([events[i]]);\n-            // it is possible that the act of setting the state event means we\n-            // can set more metadata (specifically sender/target props), so try\n-            // it again if the prop wasn't previously set. It may also mean that\n-            // the sender/target is updated (if the event set was a room member event)\n-            // so we want to use the *updated* member (new avatar/name) instead.\n-            if (!events[i].sender || events[i].getType() === \"m.room.member\") {\n-                setEventMetadata(events[i], stateContext, toStartOfTimeline);\n-            }\n-        }\n-        if (events[i].getType() === \"m.room.redaction\") {\n-            // try to remove the element\n-            var removed = utils.removeElement(\n-                this.timeline, checkForRedaction(events[i])\n-            );\n-            if (!removed && toStartOfTimeline) {\n-                // redactions will trickle in BEFORE the event redacted so make\n-                // a note of the redacted event; we'll check it later.\n-                this._redactions.push(events[i].event.redacts);\n-            }\n-            // NB: We continue to add the redaction event to the timeline so clients\n-            // can say \"so and so redacted an event\" if they wish to.\n-        }\n+        var spliceBeforeLocalEcho = !isLocalEcho && addLocalEchoToEnd;\n \n-        // TODO: pass through filter to see if this should be added to the timeline.\n-        if (toStartOfTimeline) {\n-            this.timeline.unshift(events[i]);\n-        }\n-        else {\n-            // everything gets added to the end by default. What we actually want to\n-            // do in this scenario is *NOT* add REAL events to the end if there are\n-            // existing local echo events at the end.\n-            if (addLocalEchoToEnd && !isLocalEcho) {\n-                var insertIndex = this.timeline.length;\n-                for (var j = this.timeline.length - 1; j >= 0; j--) {\n-                    if (!this.timeline[j].status) { // real events don't have a status\n-                        insertIndex = j + 1;\n-                        break;\n-                    }\n-                }\n-                this.timeline.splice(insertIndex, 0, events[i]); // insert element\n-            }\n-            else {\n-                this.timeline.push(events[i]);\n-            }\n+        if (!this._eventIdToTimeline[events[i].getId()]) {","path":"lib/models/room.js","position":450,"original_position":450,"commit_id":"48d1bc31583d04449e3912ce47510f204c52001c","original_commit_id":"48d1bc31583d04449e3912ce47510f204c52001c","user":{"login":"richvdh","id":1389908,"avatar_url":"https://avatars.githubusercontent.com/u/1389908?v=3","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":"well, this isn't a new problem. But I guess we could expire timelines which haven't been used for a while; we would remove entries from _eventIdToTimeline when we did so.\r\n\r\n","created_at":"2016-01-26T17:20:00Z","updated_at":"2016-01-26T17:20:00Z","html_url":"https://github.com/matrix-org/matrix-js-sdk/pull/63#discussion_r50867390","pull_request_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/pulls/63","_links":{"self":{"href":"https://api.github.com/repos/matrix-org/matrix-js-sdk/pulls/comments/50867390"},"html":{"href":"https://github.com/matrix-org/matrix-js-sdk/pull/63#discussion_r50867390"},"pull_request":{"href":"https://api.github.com/repos/matrix-org/matrix-js-sdk/pulls/63"}}},"pull_request":{"url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/pulls/63","id":56167895,"html_url":"https://github.com/matrix-org/matrix-js-sdk/pull/63","diff_url":"https://github.com/matrix-org/matrix-js-sdk/pull/63.diff","patch_url":"https://github.com/matrix-org/matrix-js-sdk/pull/63.patch","issue_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/issues/63","number":63,"state":"open","locked":false,"title":"Support for non-contiguous event timelines","user":{"login":"richvdh","id":1389908,"avatar_url":"https://avatars.githubusercontent.com/u/1389908?v=3","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":"This provides optional support for fetching old events via the /context API,\r\nand paginating backwards and forwards from them, eventually merging into the\r\nlive timeline.\r\n\r\nTo support it, events are now stored in an EventTimeline, rather than directly\r\nin an array in the Room; the old names are maintained as references for\r\ncompatibility.\r\n\r\nThe feature has to be enabled explicitly, otherwise it would be impossible for\r\nexisting clients to back-paginate to the old events after a gappy /sync.\r\n\r\nStill TODO here:\r\n\r\n* An object which provides a window into the timelines to make them possible to\r\n  use. (This is pr #64) .\r\n\r\n* Rewrite the 'EventContext' used by the searchRoomEvents API in terms of an\r\n  EventTimeline - it is essentially a subset. This isn't urgent, and can wait until this lump has landed.","created_at":"2016-01-15T13:19:25Z","updated_at":"2016-01-26T17:20:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c8da7ccefe80e2f26e8c9e7fc9108884314b4e41","assignee":{"login":"Kegsay","id":7190048,"avatar_url":"https://avatars.githubusercontent.com/u/7190048?v=3","gravatar_id":"","url":"https://api.github.com/users/Kegsay","html_url":"https://github.com/Kegsay","followers_url":"https://api.github.com/users/Kegsay/followers","following_url":"https://api.github.com/users/Kegsay/following{/other_user}","gists_url":"https://api.github.com/users/Kegsay/gists{/gist_id}","starred_url":"https://api.github.com/users/Kegsay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kegsay/subscriptions","organizations_url":"https://api.github.com/users/Kegsay/orgs","repos_url":"https://api.github.com/users/Kegsay/repos","events_url":"https://api.github.com/users/Kegsay/events{/privacy}","received_events_url":"https://api.github.com/users/Kegsay/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/pulls/63/commits","review_comments_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/pulls/63/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/63/comments","statuses_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/statuses/48d1bc31583d04449e3912ce47510f204c52001c","head":{"label":"matrix-org:rav/context","ref":"rav/context","sha":"48d1bc31583d04449e3912ce47510f204c52001c","user":{"login":"matrix-org","id":8418310,"avatar_url":"https://avatars.githubusercontent.com/u/8418310?v=3","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://avatars.githubusercontent.com/u/8418310?v=3","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":"2016-01-25T21:35:36Z","pushed_at":"2016-01-26T14:11:49Z","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":2184,"stargazers_count":21,"watchers_count":21,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":7,"mirror_url":null,"open_issues_count":6,"forks":7,"open_issues":6,"watchers":21,"default_branch":"master"}},"base":{"label":"matrix-org:develop","ref":"develop","sha":"7a4cc62280dafe71b0ec69c6fb3b0e9d5a4fe9e0","user":{"login":"matrix-org","id":8418310,"avatar_url":"https://avatars.githubusercontent.com/u/8418310?v=3","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://avatars.githubusercontent.com/u/8418310?v=3","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":"2016-01-25T21:35:36Z","pushed_at":"2016-01-26T14:11:49Z","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":2184,"stargazers_count":21,"watchers_count":21,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":7,"mirror_url":null,"open_issues_count":6,"forks":7,"open_issues":6,"watchers":21,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/matrix-org/matrix-js-sdk/pulls/63"},"html":{"href":"https://github.com/matrix-org/matrix-js-sdk/pull/63"},"issue":{"href":"https://api.github.com/repos/matrix-org/matrix-js-sdk/issues/63"},"comments":{"href":"https://api.github.com/repos/matrix-org/matrix-js-sdk/issues/63/comments"},"review_comments":{"href":"https://api.github.com/repos/matrix-org/matrix-js-sdk/pulls/63/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/63/commits"},"statuses":{"href":"https://api.github.com/repos/matrix-org/matrix-js-sdk/statuses/48d1bc31583d04449e3912ce47510f204c52001c"}}}}