Skip to content

Commit c70fcb0

Browse files
aiday-maralexr00
andauthored
Adding Mark as Done action (#6325)
* wip * adding polish * using different icon check-all * adding commands * polishing PR * fixing compiler errors * fetching url to check if organizations array has values * adding comment * making isInOrganization be string too * Missed a spot * Revert extraneous changes * Don't modify proposal files --------- Co-authored-by: Alex Ross <[email protected]>
1 parent 4d353de commit c70fcb0

File tree

6 files changed

+76
-11
lines changed

6 files changed

+76
-11
lines changed

package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,6 +1560,12 @@
15601560
"title": "%command.notifications.markAsRead.title%",
15611561
"category": "%command.notifications.category%",
15621562
"icon": "$(mail-read)"
1563+
},
1564+
{
1565+
"command": "notification.markAsDone",
1566+
"title": "%command.notifications.markAsDone.title%",
1567+
"category": "%command.notifications.category%",
1568+
"icon": "$(check-all)"
15631569
}
15641570
],
15651571
"viewsWelcome": [
@@ -2236,6 +2242,10 @@
22362242
"command": "notification.markAsRead",
22372243
"when": "false"
22382244
},
2245+
{
2246+
"command": "notification.markAsDone",
2247+
"when": "false"
2248+
},
22392249
{
22402250
"command": "notification.chatSummarizeNotification",
22412251
"when": "false"
@@ -2468,6 +2478,16 @@
24682478
"group": "issues_0@2",
24692479
"when": "view == notifications:github && (viewItem == 'Issue' || viewItem == 'PullRequest') && config.githubPullRequests.experimental.notificationsView"
24702480
},
2481+
{
2482+
"command": "notification.markAsDone",
2483+
"group": "inline@4",
2484+
"when": "view == notifications:github && (viewItem == 'Issue' || viewItem == 'PullRequest') && config.githubPullRequests.experimental.notificationsView"
2485+
},
2486+
{
2487+
"command": "notification.markAsDone",
2488+
"group": "issues_0@3",
2489+
"when": "view == notifications:github && (viewItem == 'Issue' || viewItem == 'PullRequest') && config.githubPullRequests.experimental.notificationsView"
2490+
},
24712491
{
24722492
"command": "pr.openDescriptionToTheSide",
24732493
"group": "inline@2",

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@
296296
"command.notifications.sortByPriority.title": "Sort by Priority using Copilot",
297297
"command.notifications.openOnGitHub.title": "Open on GitHub",
298298
"command.notifications.markAsRead.title": "Mark as Read",
299+
"command.notifications.markAsDone.title": "Mark as Done",
299300
"command.notification.chatSummarizeNotification.title": "Summarize With Copilot",
300301
"welcome.github.login.contents": {
301302
"message": "You have not yet signed in with GitHub\n[Sign in](command:pr.signin)",

src/lm/tools/summarizeNotificationsTool.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,15 @@ Body: ${comment.body}
7676
command: 'notification.markAsRead',
7777
arguments: [{ threadId, notificationKey }]
7878
};
79+
const markAsDoneCommand: vscode.Command = {
80+
title: 'Mark As Done',
81+
command: 'notification.markAsDone',
82+
arguments: [{ threadId, notificationKey }]
83+
};
7984
content.push(new vscode.LanguageModelTextPart(TOOL_COMMAND_RESULT));
8085
content.push(new vscode.LanguageModelTextPart(JSON.stringify(markAsReadCommand)));
86+
content.push(new vscode.LanguageModelTextPart(TOOL_COMMAND_RESULT));
87+
content.push(new vscode.LanguageModelTextPart(JSON.stringify(markAsDoneCommand)));
8188
}
8289
const owner = options.input.owner;
8390
const repo = options.input.repo;

src/notifications/notificationsFeatureRegistar.ts

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,28 +102,43 @@ export class NotificationsFeatureRegister extends Disposable {
102102
);
103103
this._register(
104104
vscode.commands.registerCommand('notification.markAsRead', (options: any) => {
105-
let threadId: string;
106-
let notificationKey: string;
107-
if (isNotificationTreeItem(options)) {
108-
threadId = options.notification.id;
109-
notificationKey = options.notification.key;
110-
} else if ('threadId' in options && 'notificationKey' in options && typeof options.threadId === 'number' && typeof options.notificationKey === 'string') {
111-
threadId = options.threadId;
112-
notificationKey = options.notificationKey;
113-
} else {
114-
throw new Error(`Invalid arguments for command notification.markAsRead : ${JSON.stringify(options)}`);
115-
}
105+
const { threadId, notificationKey } = this._extractMarkAsCommandOptions(options);
116106
/* __GDPR__
117107
"notification.markAsRead" : {}
118108
*/
119109
this._telemetry.sendTelemetryEvent('notification.markAsRead');
120110
notificationsManager.markAsRead({ threadId, notificationKey });
121111
})
122112
);
113+
this._register(
114+
vscode.commands.registerCommand('notification.markAsDone', (options: any) => {
115+
const { threadId, notificationKey } = this._extractMarkAsCommandOptions(options);
116+
/* __GDPR__
117+
"notification.markAsDone" : {}
118+
*/
119+
this._telemetry.sendTelemetryEvent('notification.markAsDone');
120+
notificationsManager.markAsDone({ threadId, notificationKey });
121+
})
122+
);
123123

124124
// Events
125125
this._register(onceEvent(this._repositoriesManager.onDidLoadAnyRepositories)(() => {
126126
notificationsManager.refresh();
127127
}));
128128
}
129+
130+
private _extractMarkAsCommandOptions(options: any): { threadId: string, notificationKey: string } {
131+
let threadId: string;
132+
let notificationKey: string;
133+
if (isNotificationTreeItem(options)) {
134+
threadId = options.notification.id;
135+
notificationKey = options.notification.key;
136+
} else if ('threadId' in options && 'notificationKey' in options && typeof options.threadId === 'number' && typeof options.notificationKey === 'string') {
137+
threadId = options.threadId;
138+
notificationKey = options.notificationKey;
139+
} else {
140+
throw new Error(`Invalid arguments for command notification.markAsRead : ${JSON.stringify(options)}`);
141+
}
142+
return { threadId, notificationKey };
143+
}
129144
}

src/notifications/notificationsManager.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,18 @@ export class NotificationsManager extends Disposable implements vscode.TreeDataP
211211
}
212212
}
213213

214+
public async markAsDone(notificationIdentifier: { threadId: string, notificationKey: string }): Promise<void> {
215+
const notification = this._notifications.get(notificationIdentifier.notificationKey);
216+
if (notification) {
217+
await this._notificationProvider.markAsDone(notificationIdentifier);
218+
219+
this._onDidChangeNotifications.fire([notification]);
220+
this._notifications.delete(notificationIdentifier.notificationKey);
221+
222+
this._refresh(false);
223+
}
224+
}
225+
214226
public sortNotifications(method: NotificationsSortMethod): void {
215227
if (this._sortingMethod === method) {
216228
return;

src/notifications/notificationsProvider.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ export class NotificationsProvider extends Disposable {
7070
});
7171
}
7272

73+
public async markAsDone(notificationIdentifier: { threadId: string, notificationKey: string }): Promise<void> {
74+
const gitHub = this._getGitHub();
75+
if (gitHub === undefined) {
76+
return undefined;
77+
}
78+
await gitHub.octokit.call(gitHub.octokit.api.activity.markThreadAsDone, {
79+
thread_id: Number(notificationIdentifier.threadId)
80+
});
81+
}
82+
7383
public async getNotifications(before: string, page: number): Promise<INotifications | undefined> {
7484
const gitHub = this._getGitHub();
7585
if (gitHub === undefined) {

0 commit comments

Comments
 (0)