private async registerListeners()

in src/view/reviewCommentController.ts [207:310]


	private async registerListeners(): Promise<void> {
		this._localToDispose.push(
			this._reposManager.activePullRequest!.onDidChangePendingReviewState(newDraftMode => {
				[
					this._workspaceFileChangeCommentThreads,
					this._obsoleteFileChangeCommentThreads,
					this._reviewSchemeFileChangeCommentThreads,
				].forEach(commentThreadMap => {
					for (const fileName in commentThreadMap) {
						commentThreadMap[fileName].forEach(thread => {
							updateCommentReviewState(thread, newDraftMode);
							updateCommentThreadLabel(thread);
						});
					}
				});
			}),
		);

		this._localToDispose.push(
			this._reposManager.activePullRequest!.onDidChangeReviewThreads(e => {
				e.added.forEach(async thread => {
					const { path } = thread;

					const index = this._pendingCommentThreadAdds.findIndex(async t => {
						const fileName = this.gitRelativeRootPath(t.uri.path);
						if (fileName !== thread.path) {
							return false;
						}

						const diff = await this.getContentDiff(t.uri, fileName);
						const line = mapNewPositionToOld(diff, t.range.start.line);
						const sameLine = line + 1 === thread.line;
						return sameLine;
					});

					let newThread: GHPRCommentThread;
					if (index > -1) {
						newThread = this._pendingCommentThreadAdds[index];
						newThread.gitHubThreadId = thread.id;
						newThread.comments = thread.comments.map(c => new GHPRComment(c, newThread));
						this._pendingCommentThreadAdds.splice(index, 1);
					} else {
						const fullPath = nodePath.join(this._repository.rootUri.path, path).replace(/\\/g, '/');
						const uri = this._repository.rootUri.with({ path: fullPath });
						if (thread.isOutdated) {
							newThread = this.createOutdatedCommentThread(path, thread);
						} else {
							if (thread.diffSide === DiffSide.RIGHT) {
								newThread = await this.createWorkspaceCommentThread(uri, path, thread);
							} else {
								newThread = this.createReviewCommentThread(uri, path, thread);
							}
						}
					}

					const threadMap = thread.isOutdated
						? this._obsoleteFileChangeCommentThreads
						: thread.diffSide === DiffSide.RIGHT
							? this._workspaceFileChangeCommentThreads
							: this._reviewSchemeFileChangeCommentThreads;

					if (threadMap[path]) {
						threadMap[path].push(newThread);
					} else {
						threadMap[path] = [newThread];
					}
				});

				e.changed.forEach(thread => {
					const threadMap = thread.isOutdated
						? this._obsoleteFileChangeCommentThreads
						: thread.diffSide === DiffSide.RIGHT
							? this._workspaceFileChangeCommentThreads
							: this._reviewSchemeFileChangeCommentThreads;

					const index = threadMap[thread.path].findIndex(t => t.gitHubThreadId === thread.id);
					if (index > -1) {
						const matchingThread = threadMap[thread.path][index];
						updateThread(matchingThread, thread);
					}
				});

				e.removed.forEach(thread => {
					const threadMap = thread.isOutdated
						? this._obsoleteFileChangeCommentThreads
						: thread.diffSide === DiffSide.RIGHT
							? this._workspaceFileChangeCommentThreads
							: this._reviewSchemeFileChangeCommentThreads;

					const index = threadMap[thread.path].findIndex(t => t.gitHubThreadId === thread.id);
					if (index > -1) {
						const matchingThread = threadMap[thread.path][index];
						threadMap[thread.path].splice(index, 1);
						matchingThread.dispose();
					}
				});
			}),
		);

		this._localToDispose.push(
			this._sessionState.onDidChangeCommentsExpandState(expand => {
				this.updateCommentExpandState(expand);
			}));
	}