aboutsummaryrefslogtreecommitdiff
path: root/juick-common/src/main/java/com/juick/server/CommandsManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-common/src/main/java/com/juick/server/CommandsManager.java')
-rw-r--r--juick-common/src/main/java/com/juick/server/CommandsManager.java27
1 files changed, 18 insertions, 9 deletions
diff --git a/juick-common/src/main/java/com/juick/server/CommandsManager.java b/juick-common/src/main/java/com/juick/server/CommandsManager.java
index b9f27940..7dd372b1 100644
--- a/juick-common/src/main/java/com/juick/server/CommandsManager.java
+++ b/juick-common/src/main/java/com/juick/server/CommandsManager.java
@@ -106,12 +106,17 @@ public class CommandsManager {
}
// new message
String body = TagUtils.toString(tags).equals(input) ? StringUtils.EMPTY : input.substring(TagUtils.toString(tags).length()).trim();
- String attachmentType = StringUtils.isNotEmpty(attachment.toString()) ? attachment.toString().substring(attachment.toString().length() - 3) : null;
+ boolean haveAttachment = StringUtils.isNotEmpty(attachment.toString());
+ String attachmentFName = null;
+ String attachmentType = null;
+ if (haveAttachment) {
+ attachmentFName = attachment.getScheme().equals("juick") ? attachment.getHost()
+ : HttpUtils.downloadImage(attachment.toURL(), tmpDir).getHost();
+ attachmentType = attachmentFName.substring(attachmentFName.length() - 3);
+ }
int mid = messagesService.createMessage(user.getUid(), body, attachmentType, tags);
subscriptionService.subscribeMessage(messagesService.getMessage(mid), user);
- if (StringUtils.isNotEmpty(attachmentType)) {
- String attachmentFName = attachment.getScheme().equals("juick") ? attachment.getHost()
- : HttpUtils.downloadImage(attachment.toURL(), tmpDir).getHost();
+ if (haveAttachment) {
String fname = String.format("%d.%s", mid, attachmentType);
imagesService.saveImageWithPreviews(attachmentFName, fname);
}
@@ -494,13 +499,17 @@ public class CommandsManager {
return CommandResult.fromString("Tags are NOT updated (5 tags maximum?)");
}
} else {
- String attachmentStr = attachment.toString();
- String attachmentType = StringUtils.isNotEmpty(attachmentStr) ? attachmentStr.substring(attachmentStr.length() - 3) : null;
+ boolean haveAttachment = StringUtils.isNotEmpty(attachment.toString());
+ String attachmentFName = null;
+ String attachmentType = null;
+ if (haveAttachment) {
+ attachmentFName = attachment.getScheme().equals("juick") ? attachment.getHost()
+ : HttpUtils.downloadImage(attachment.toURL(), tmpDir).getHost();
+ attachmentType = attachmentFName.substring(attachmentFName.length() - 3);
+ }
int newrid = messagesService.createReply(mid, rid, user, txt, attachmentType);
applicationEventPublisher.publishEvent(new MessageReadEvent(this, user, msg));
- if (StringUtils.isNotEmpty(attachmentType)) {
- String attachmentFName = attachment.getScheme().equals("juick") ? attachment.getHost()
- : HttpUtils.downloadImage(attachment.toURL(), tmpDir).getHost();
+ if (haveAttachment) {
String fname = String.format("%d-%d.%s", mid, newrid, attachmentType);
imagesService.saveImageWithPreviews(attachmentFName, fname);
}