Skip to content

Commit

Permalink
Method to mark the thread as read
Browse files Browse the repository at this point in the history
  • Loading branch information
kohsuke committed Mar 22, 2015
1 parent 8835b2c commit 205950f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/kohsuke/github/GHNotificationStream.java
Expand Up @@ -141,7 +141,7 @@ GHThread fetch() {
long nt = n.getUpdatedAt().getTime();
if (nt >= lastUpdated) {
lastUpdated = nt;
return n;
return n.wrap(root);
}
}

Expand Down
19 changes: 18 additions & 1 deletion src/main/java/org/kohsuke/github/GHThread.java
@@ -1,20 +1,23 @@
package org.kohsuke.github;

import java.io.IOException;
import java.util.Date;

/**
* A conversation in the notification API.
*
*
* @see <a href="https://developer.github.com/v3/activity/notifications/">documentation</a>
* @see GHNotificationStream
* @author Kohsuke Kawaguchi
*/
public class GHThread extends GHObject {
private GitHub root;
private GHRepository repository;
private Subject subject;
private String reason;
private boolean unread;
private String last_read_at;
private String url;

static class Subject {
String title;
Expand Down Expand Up @@ -54,4 +57,18 @@ public String getTitle() {
public String getType() {
return subject.type;
}

/*package*/ GHThread wrap(GitHub root) {
this.root = root;
if (this.repository!=null)
this.repository.wrap(root);
return this;
}

/**
* Marks this thread as read.
*/
public void markAsRead() throws IOException {
new Requester(root).method("PATCH").to(url);
}
}
5 changes: 4 additions & 1 deletion src/test/java/org/kohsuke/github/AppTest.java
Expand Up @@ -811,7 +811,10 @@ public void searchContent() throws Exception {
public void notifications() throws Exception {
boolean found=false;
for (GHThread t : gitHub.listNotifications().nonBlocking(true).read(true)) {
found = true;
if (!found) {
found = true;
t.markAsRead(); // test this by calling it once on old nofication
}
assertNotNull(t.getTitle());
assertNotNull(t.getReason());

Expand Down

0 comments on commit 205950f

Please sign in to comment.