From a1703a67b166fd2e1616acb4e9ba0cdb218b521c Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 16 Apr 2018 15:20:58 +0300 Subject: server: mark messages read from email notifications --- .../src/main/java/com/juick/server/EmailManager.java | 5 +++-- .../src/main/java/com/juick/server/api/Messages.java | 15 ++++++++++++++- juick-server/src/main/resources/Transparent.gif | Bin 0 -> 42 bytes .../test/java/com/juick/server/tests/ServerTests.java | 10 +++++++++- 4 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 juick-server/src/main/resources/Transparent.gif (limited to 'juick-server/src') 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 { ", 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

--
You are receiving this because you are subscribed to this user" + - ", discussion or tag. Reply to this email directly or view it on Juick." + + ", discussion or tag. Reply to this email directly or view it on Juick." + "
Configure or disable notifications", 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 diff --git a/juick-server/src/main/resources/Transparent.gif b/juick-server/src/main/resources/Transparent.gif new file mode 100644 index 00000000..f191b280 Binary files /dev/null and b/juick-server/src/main/resources/Transparent.gif differ diff --git a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java index 046e0e7d..71c42b6c 100644 --- a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java +++ b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java @@ -31,6 +31,7 @@ import com.juick.server.util.HttpUtils; import com.juick.service.*; import com.juick.util.DateFormattersHolder; import com.juick.util.MessageUtils; +import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.junit.After; import org.junit.Assert; @@ -754,7 +755,7 @@ public class ServerTests { telegramBotManager.processUpdate("{\"message\":{\"chat\":{\"id\":1},\"text\":\"yo\",\"from\":{\"id\":1,\"username\":\"teleugnich\"}}}"); } @Test - public void lastReadTests() { + public void lastReadTests() throws Exception { int mid = messagesService.createMessage(ugnich.getUid(), "to be watched", null, null); subscriptionService.subscribeMessage(messagesService.getMessage(mid), ugnich); messagesService.createReply(mid, 0, freefd, "new reply", null); @@ -769,5 +770,12 @@ public class ServerTests { assertThat(messagesService.getUnread(ugnich).size(), is(0)); messagesService.setLastReadComment(ugnich, mid, 0); assertThat(lastRead.apply(ugnich, mid), is(1)); + String ugnichHash = userService.getHashByUID(ugnich.getUid()); + int freefdrid = messagesService.createReply(mid, 0, freefd, "again", null); + mockMvc.perform(get(String.format("/thread/mark_read/%d-%d.gif?hash=%s", mid, freefdrid, ugnichHash))) + .andExpect(status().isOk()) + .andExpect(content().bytes(IOUtils.toByteArray( + Objects.requireNonNull(getClass().getClassLoader().getResource("Transparent.gif"))))); + assertThat(lastRead.apply(ugnich, mid), is(freefdrid)); } } -- cgit v1.2.3