diff options
author | 2018-05-10 15:04:57 +0300 | |
---|---|---|
committer | 2018-05-10 15:04:57 +0300 | |
commit | b642c55f053583533e23b1fc7fc5ac318fcbd7f0 (patch) | |
tree | 3255d68fe48ee38aeba6de4359c631f9b9ddf70f /juick-server/src/main/java/com/juick/server/api/PM.java | |
parent | 78bc4cd5b9383320e989183942ba9ca11252a917 (diff) |
using User::isAnonymous where possible
Diffstat (limited to 'juick-server/src/main/java/com/juick/server/api/PM.java')
-rw-r--r-- | juick-server/src/main/java/com/juick/server/api/PM.java | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/juick-server/src/main/java/com/juick/server/api/PM.java b/juick-server/src/main/java/com/juick/server/api/PM.java index 3649bb5e..045d465e 100644 --- a/juick-server/src/main/java/com/juick/server/api/PM.java +++ b/juick-server/src/main/java/com/juick/server/api/PM.java @@ -51,8 +51,7 @@ public class PM { public List<com.juick.Message> doGetPM( @RequestParam(required = false) String uname) { User visitor = UserUtils.getCurrentUser(); - int vuid = visitor.getUid(); - if (vuid == 0) { + if (visitor.isAnonymous()) { throw new HttpForbiddenException(); } int uid = 0; @@ -64,7 +63,7 @@ public class PM { throw new HttpBadRequestException(); } - return pmQueriesService.getPMMessages(vuid, uid); + return pmQueriesService.getPMMessages(visitor.getUid(), uid); } @RequestMapping(value = "/pm", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @@ -72,8 +71,7 @@ public class PM { @RequestParam String uname, @RequestParam String body) { User visitor = UserUtils.getCurrentUser(); - int vuid = visitor.getUid(); - if (vuid == 0) { + if (visitor.isAnonymous()) { throw new HttpForbiddenException(); } User userTo = AnonymousUser.INSTANCE; @@ -85,11 +83,11 @@ public class PM { throw new HttpBadRequestException(); } - if (userService.isInBLAny(userTo.getUid(), vuid)) { + if (userService.isInBLAny(userTo.getUid(), visitor.getUid())) { throw new HttpForbiddenException(); } - if (pmQueriesService.createPM(vuid, userTo.getUid(), body)) { + if (pmQueriesService.createPM(visitor.getUid(), userTo.getUid(), body)) { com.juick.Message jmsg = new com.juick.Message(); jmsg.setUser(visitor); jmsg.setText(body); @@ -104,8 +102,7 @@ public class PM { public PrivateChats doGetGroupsPMs( @RequestParam(defaultValue = "5") int cnt) { User visitor = UserUtils.getCurrentUser(); - int vuid = visitor.getUid(); - if (vuid == 0) { + if (visitor.isAnonymous()) { throw new HttpForbiddenException(); } if (cnt < 3) { @@ -115,7 +112,7 @@ public class PM { cnt = 10; } - List<User> lastconv = pmQueriesService.getPMLastConversationsUsers(vuid, cnt); + List<User> lastconv = pmQueriesService.getPMLastConversationsUsers(visitor.getUid(), cnt); if (lastconv != null && !lastconv.isEmpty()) { PrivateChats pms = new PrivateChats(); pms.setUsers(lastconv); |