aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/server/api
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-03-28 21:19:07 +0300
committerGravatar Vitaly Takmazov2018-03-28 21:19:07 +0300
commit4b3ddcd138af69f504a9a08281edc1c2e7eb0c7a (patch)
treed1e6b3cc63184564a0ab3d7c59513e5e46b15b1c /juick-server/src/main/java/com/juick/server/api
parent31226138eb63b25a3b666ad782412a2024b50f74 (diff)
PM events
Diffstat (limited to 'juick-server/src/main/java/com/juick/server/api')
-rw-r--r--juick-server/src/main/java/com/juick/server/api/PM.java23
1 files changed, 5 insertions, 18 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 6797c7fd..357b68dc 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
@@ -19,11 +19,13 @@ package com.juick.server.api;
import com.juick.User;
import com.juick.server.ServerManager;
+import com.juick.server.component.MessageEvent;
import com.juick.server.helpers.AnonymousUser;
import com.juick.server.helpers.PrivateChats;
import com.juick.server.util.*;
import com.juick.service.PMQueriesService;
import com.juick.service.UserService;
+import org.springframework.context.ApplicationEventPublisher;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@@ -46,6 +48,8 @@ public class PM {
private PMQueriesService pmQueriesService;
@Inject
private ServerManager serverManager;
+ @Inject
+ private ApplicationEventPublisher applicationEventPublisher;
@RequestMapping(value = "/pm", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public List<com.juick.Message> doGetPM(
@@ -90,28 +94,11 @@ public class PM {
}
if (pmQueriesService.createPM(vuid, userTo.getUid(), body)) {
- Message msg = new Message();
- msg.setFrom(Jid.of("juick@juick.com"));
com.juick.Message jmsg = new com.juick.Message();
jmsg.setUser(visitor);
jmsg.setText(body);
jmsg.setTo(userTo);
- msg.addExtension(jmsg);
-
- List<String> jids = userService.getJIDsbyUID(userTo.getUid());
- for (String jid : jids) {
- Message mm = new Message();
- mm.setTo(Jid.of(jid));
- mm.setType(Message.Type.CHAT);
- if (pmQueriesService.havePMinRoster(vuid, jid)) {
- mm.setFrom(Jid.of(jmsg.getUser().getName(), "juick.com", "Juick"));
- mm.setBody(body);
- } else {
- mm.setFrom(Jid.of("juick", "juick.com", "Juick"));
- mm.setBody("Private message from @" + jmsg.getUser().getName() + ":\n" + body);
- }
- serverManager.sendMessage(mm);
- }
+ applicationEventPublisher.publishEvent(new MessageEvent(this, jmsg));
return jmsg;
}