Skip to content
This repository was archived by the owner on Jul 31, 2025. It is now read-only.

Commit 205950f

Browse files
committed
Method to mark the thread as read
1 parent 8835b2c commit 205950f

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

src/main/java/org/kohsuke/github/GHNotificationStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ GHThread fetch() {
141141
long nt = n.getUpdatedAt().getTime();
142142
if (nt >= lastUpdated) {
143143
lastUpdated = nt;
144-
return n;
144+
return n.wrap(root);
145145
}
146146
}
147147

src/main/java/org/kohsuke/github/GHThread.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
package org.kohsuke.github;
22

3+
import java.io.IOException;
34
import java.util.Date;
45

56
/**
67
* A conversation in the notification API.
78
*
8-
*
99
* @see <a href="https://developer.github.com/v3/activity/notifications/">documentation</a>
10+
* @see GHNotificationStream
1011
* @author Kohsuke Kawaguchi
1112
*/
1213
public class GHThread extends GHObject {
14+
private GitHub root;
1315
private GHRepository repository;
1416
private Subject subject;
1517
private String reason;
1618
private boolean unread;
1719
private String last_read_at;
20+
private String url;
1821

1922
static class Subject {
2023
String title;
@@ -54,4 +57,18 @@ public String getTitle() {
5457
public String getType() {
5558
return subject.type;
5659
}
60+
61+
/*package*/ GHThread wrap(GitHub root) {
62+
this.root = root;
63+
if (this.repository!=null)
64+
this.repository.wrap(root);
65+
return this;
66+
}
67+
68+
/**
69+
* Marks this thread as read.
70+
*/
71+
public void markAsRead() throws IOException {
72+
new Requester(root).method("PATCH").to(url);
73+
}
5774
}

src/test/java/org/kohsuke/github/AppTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,10 @@ public void searchContent() throws Exception {
811811
public void notifications() throws Exception {
812812
boolean found=false;
813813
for (GHThread t : gitHub.listNotifications().nonBlocking(true).read(true)) {
814-
found = true;
814+
if (!found) {
815+
found = true;
816+
t.markAsRead(); // test this by calling it once on old nofication
817+
}
815818
assertNotNull(t.getTitle());
816819
assertNotNull(t.getReason());
817820

0 commit comments

Comments
 (0)