aboutsummaryrefslogtreecommitdiff
path: root/juick-api/src/main/java/com/juick
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-01-30 16:48:08 +0300
committerGravatar Vitaly Takmazov2018-01-30 16:48:08 +0300
commit8eb857ec38b86e03a2509df1ad263cdb1e9bb7b7 (patch)
tree823a090ffeb77ca469afcfa9437b69c9a7166f34 /juick-api/src/main/java/com/juick
parentbbd3faa0ff2f65aa852e0995d8fa3a46d17b485f (diff)
serialize PM in api and www
Diffstat (limited to 'juick-api/src/main/java/com/juick')
-rw-r--r--juick-api/src/main/java/com/juick/api/controllers/PM.java20
1 files changed, 11 insertions, 9 deletions
diff --git a/juick-api/src/main/java/com/juick/api/controllers/PM.java b/juick-api/src/main/java/com/juick/api/controllers/PM.java
index b72e0a0f..87858e8c 100644
--- a/juick-api/src/main/java/com/juick/api/controllers/PM.java
+++ b/juick-api/src/main/java/com/juick/api/controllers/PM.java
@@ -19,6 +19,7 @@ package com.juick.api.controllers;
import com.juick.User;
import com.juick.api.ApiServer;
+import com.juick.server.helpers.AnonymousUser;
import com.juick.server.util.HttpBadRequestException;
import com.juick.server.util.HttpForbiddenException;
import com.juick.service.PMQueriesService;
@@ -77,33 +78,34 @@ public class PM {
if (vuid == 0) {
throw new HttpForbiddenException();
}
- int uid = 0;
+ User userTo = AnonymousUser.INSTANCE;
if (WebUtils.isUserName(uname)) {
- uid = userService.getUIDbyName(uname);
+ userTo = userService.getUserByName(uname);
}
- if (uid == 0 || body == null || body.length() < 1 || body.length() > 10240) {
+ if (userTo.getUid() == 0 || body == null || body.length() < 1 || body.length() > 10240) {
throw new HttpBadRequestException();
}
- if (userService.isInBLAny(uid, vuid)) {
+ if (userService.isInBLAny(userTo.getUid(), vuid)) {
throw new HttpForbiddenException();
}
- if (pmQueriesService.createPM(vuid, uid, body)) {
+ if (pmQueriesService.createPM(vuid, userTo.getUid(), body)) {
Message msg = new Message();
msg.setFrom(Jid.of("juick@juick.com"));
- msg.setTo(Jid.of(String.format("%d@push.juick.com", uid)));
+ msg.setTo(Jid.of(String.format("%d@push.juick.com", userTo.getUid())));
com.juick.Message jmsg = new com.juick.Message();
- jmsg.setUser(userService.getUserByUID(vuid).get());
+ jmsg.setUser(visitor);
jmsg.setText(body);
+ jmsg.setTo(userTo);
msg.addExtension(jmsg);
apiServer.sendMessage(msg);
- msg.setTo(Jid.of(String.format("%d@ws.juick.com", uid)));
+ msg.setTo(Jid.of(String.format("%d@ws.juick.com", userTo.getUid())));
apiServer.sendMessage(msg);
- List<String> jids = userService.getJIDsbyUID(uid);
+ List<String> jids = userService.getJIDsbyUID(userTo.getUid());
for (String jid : jids) {
Message mm = new Message();
mm.setTo(Jid.of(jid));