aboutsummaryrefslogtreecommitdiff
path: root/juick-www
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-04-03 17:55:46 +0300
committerGravatar Vitaly Takmazov2018-04-03 17:55:54 +0300
commita5f045a3780ef8530afa7493cf090771b8fdcfe1 (patch)
tree56e4cbc6949dc9bd39672ccf379324338f0eef76 /juick-www
parentc53675e5eb19a1a05ae5edcd0322075d51628b96 (diff)
refactoring: all messages are processed with XMPPConnection
Diffstat (limited to 'juick-www')
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/NewMessage.java25
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/Settings.java2
2 files changed, 11 insertions, 16 deletions
diff --git a/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java b/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java
index ee4a6025..b93d6f57 100644
--- a/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java
+++ b/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java
@@ -132,9 +132,9 @@ public class NewMessage {
throw new HttpForbiddenException();
}
- String attachmentFName = HttpUtils.receiveMultiPartFile(attach, tmpDir);
+ URI attachmentFName = HttpUtils.receiveMultiPartFile(attach, tmpDir);
- if (StringUtils.isBlank(attachmentFName) && img != null && img.length() > 10) {
+ if (StringUtils.isBlank(attachmentFName.toString()) && img != null && img.length() > 10) {
try {
URL imgUrl = new URL(img);
attachmentFName = HttpUtils.downloadImage(imgUrl, tmpDir);
@@ -144,7 +144,7 @@ public class NewMessage {
}
}
- String attachmentType = StringUtils.isNotEmpty(attachmentFName) ? attachmentFName.substring(attachmentFName.length() - 3) : null;
+ String attachmentType = StringUtils.isNotEmpty(attachmentFName.toString()) ? attachmentFName.toString().substring(attachmentFName.toString().length() - 3) : null;
int ridnew = messagesService.createReply(mid, rid, visitor.getUid(), body, attachmentType);
subscriptionService.subscribeMessage(mid, visitor.getUid());
@@ -163,11 +163,11 @@ public class NewMessage {
}
xmsg.addExtension(new Nickname("@" + jmsg.getUser().getName()));
- if (StringUtils.isNotEmpty(attachmentFName)) {
+ if (StringUtils.isNotEmpty(attachmentFName.toString())) {
String fname = mid + "-" + ridnew + "." + attachmentType;
String attachmentURL = "http://i.juick.com/photos-1024/" + fname;
- ImageUtils.saveImageWithPreviews(attachmentFName, fname, tmpDir, imgDir);
+ ImageUtils.saveImageWithPreviews(attachmentFName.getHost(), fname, tmpDir, imgDir);
body = attachmentURL + "\n" + body;
try {
@@ -246,9 +246,9 @@ public class NewMessage {
}
String body = StringUtils.isNotEmpty(bodyParam) ? bodyParam.replace("\r", StringUtils.EMPTY) : StringUtils.EMPTY;
- String attachmentFName = HttpUtils.receiveMultiPartFile(attach, tmpDir);
+ URI attachmentFName = HttpUtils.receiveMultiPartFile(attach, tmpDir);
- if (StringUtils.isBlank(attachmentFName) && StringUtils.isNotBlank(img)) {
+ if (StringUtils.isBlank(attachmentFName.toString()) && StringUtils.isNotBlank(img)) {
try {
URL imgUrl = new URL(img);
attachmentFName = HttpUtils.downloadImage(imgUrl, tmpDir);
@@ -262,15 +262,10 @@ public class NewMessage {
msg.setFrom(Jid.of(String.valueOf(visitor.getUid()), "uid.juick.com", "perl"));
msg.setTo(botJid);
msg.setBody(body);
- try {
- if (StringUtils.isNotEmpty(attachmentFName)) {
- String attachmentUrl = String.format("juick://%s", attachmentFName);
- msg.addExtension(new OobX(new URI(attachmentUrl), "!!!!Juick!!"));
- }
- xmpp.sendMessage(msg);
- } catch (URISyntaxException e1) {
- logger.warn("attachment error", e1);
+ if (StringUtils.isNotEmpty(attachmentFName.toString())) {
+ msg.addExtension(new OobX(attachmentFName, "!!!!Juick!!"));
}
+ xmpp.sendMessage(msg);
if (StringUtils.isBlank(referer) || referer.substring(0, 21).equals("http://juick.com/post")
|| referer.substring(0, 22).equals("https://juick.com/post")) {
return "redirect:/?show=my";
diff --git a/juick-www/src/main/java/com/juick/www/controllers/Settings.java b/juick-www/src/main/java/com/juick/www/controllers/Settings.java
index ffc66841..15f18052 100644
--- a/juick-www/src/main/java/com/juick/www/controllers/Settings.java
+++ b/juick-www/src/main/java/com/juick/www/controllers/Settings.java
@@ -158,7 +158,7 @@ public class Settings {
info.setCountry(request.getParameter("country"));
info.setUrl(request.getParameter("url"));
info.setDescription(request.getParameter("descr"));
- String avatarTmpPath = HttpUtils.receiveMultiPartFile(avatar, tmpDir);
+ String avatarTmpPath = HttpUtils.receiveMultiPartFile(avatar, tmpDir).getHost();
if (StringUtils.isNotEmpty(avatarTmpPath)) {
ImageUtils.saveAvatar(avatarTmpPath, visitor.getUid(), tmpDir, imgDir);
}