aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-04-16 15:20:58 +0300
committerGravatar Vitaly Takmazov2018-04-16 15:24:41 +0300
commita1703a67b166fd2e1616acb4e9ba0cdb218b521c (patch)
tree8d19695792d73faa481c24b1a6c0237c9ddaad47 /juick-server/src/main/java/com/juick
parent350f6942078e67b15e160ecffc913ba0cef624be (diff)
server: mark messages read from email notifications
Diffstat (limited to 'juick-server/src/main/java/com/juick')
-rw-r--r--juick-server/src/main/java/com/juick/server/EmailManager.java5
-rw-r--r--juick-server/src/main/java/com/juick/server/api/Messages.java15
2 files changed, 17 insertions, 3 deletions
diff --git a/juick-server/src/main/java/com/juick/server/EmailManager.java b/juick-server/src/main/java/com/juick/server/EmailManager.java
index 2bea7060..aaebaac8 100644
--- a/juick-server/src/main/java/com/juick/server/EmailManager.java
+++ b/juick-server/src/main/java/com/juick/server/EmailManager.java
@@ -93,12 +93,13 @@ public class EmailManager implements ApplicationListener<MessageEvent> {
", discussion or tag. Reply to this email directly or view it on Juick: %s.",
formatPost(msg), formatUrl(msg));
MimeBodyPart textBodyPart = new MimeBodyPart();
+ String hash = userService.getHashByUID(userService.getUserByEmail(email).getUid());
textBodyPart.setContent(plainText, "text/plain; charset=UTF-8");
String htmlText = String.format("%s<br /><br />--<br />You are receiving this because you are subscribed to this user" +
- ", discussion or tag. Reply to this email directly or <a href=\"%s\">view it</a> on Juick." +
+ ", discussion or tag. Reply to this email directly or <a href=\"%s\"><img src=\"https://api.juick.com/thread/mark_read/%d-%d.gif?hash=%s\" />view it</a> on Juick." +
"<br /><a href=\"https://juick.com/settings?hash=%s\">Configure or disable notifications</a>",
MessageUtils.formatHtml(msg), formatUrl(msg),
- userService.getHashByUID(userService.getUserByEmail(email).getUid()));
+ msg.getMid(), msg.getRid(), hash, hash);
MimeBodyPart htmlBodyPart = new MimeBodyPart();
htmlBodyPart.setContent(htmlText, "text/html; charset=UTF-8");
Multipart multipart = new MimeMultipart("alternative");
diff --git a/juick-server/src/main/java/com/juick/server/api/Messages.java b/juick-server/src/main/java/com/juick/server/api/Messages.java
index 45b8f69c..05ce504f 100644
--- a/juick-server/src/main/java/com/juick/server/api/Messages.java
+++ b/juick-server/src/main/java/com/juick/server/api/Messages.java
@@ -21,11 +21,13 @@ import com.juick.Message;
import com.juick.Status;
import com.juick.Tag;
import com.juick.User;
+import com.juick.server.util.HttpBadRequestException;
import com.juick.server.util.HttpForbiddenException;
import com.juick.server.util.UserUtils;
import com.juick.service.MessagesService;
import com.juick.service.TagService;
import com.juick.service.UserService;
+import org.apache.commons.io.IOUtils;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
@@ -34,8 +36,10 @@ import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.inject.Inject;
+import java.io.IOException;
import java.util.Collections;
import java.util.List;
+import java.util.Objects;
/**
* @author ugnich
@@ -152,7 +156,16 @@ public class Messages {
}
return NOT_FOUND;
}
-
+ @GetMapping("/thread/mark_read/{mid}-{rid}.gif")
+ public byte[] markThreadRead(@PathVariable int mid, @PathVariable int rid) throws IOException {
+ User visitor = UserUtils.getCurrentUser();
+ if (visitor.getUid() > 0) {
+ messagesService.setLastReadComment(visitor, mid, rid);
+ return IOUtils.toByteArray(
+ Objects.requireNonNull(getClass().getClassLoader().getResource("Transparent.gif")));
+ }
+ throw new HttpBadRequestException();
+ }
@ApiIgnore
@RequestMapping("/messages/set_privacy")
@ResponseBody