aboutsummaryrefslogtreecommitdiff
path: root/juick-www/src/main/java/com/juick/www/NewMessage.java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-www/src/main/java/com/juick/www/NewMessage.java')
-rw-r--r--juick-www/src/main/java/com/juick/www/NewMessage.java50
1 files changed, 8 insertions, 42 deletions
diff --git a/juick-www/src/main/java/com/juick/www/NewMessage.java b/juick-www/src/main/java/com/juick/www/NewMessage.java
index ca783779..60ac08de 100644
--- a/juick-www/src/main/java/com/juick/www/NewMessage.java
+++ b/juick-www/src/main/java/com/juick/www/NewMessage.java
@@ -45,7 +45,6 @@ import java.net.URLEncoder;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
-import java.util.ArrayList;
import java.util.List;
/**
@@ -156,46 +155,17 @@ public class NewMessage {
}
body = body.replace("\r", "");
- String tagsStr = request.getParameter("tags");
- List<com.juick.Tag> tags = new ArrayList<Tag>();
- String tagsArr[] = new String[1];
- if (tagsStr != null && !tagsStr.isEmpty()) {
- tagsArr = tagsStr.split("[ \\,]");
- for (int i = 0; i < tagsArr.length; i++) {
- if (tagsArr[i].startsWith("*")) {
- tagsArr[i] = tagsArr[i].substring(1);
- }
- if (tagsArr[i].length() > 64) {
- tagsArr[i] = tagsArr[i].substring(0, 64);
- }
- }
- tags = TagQueries.getTags(sql, tagsArr, true);
- while (tags.size() > 5) {
- tags.remove(5);
- }
- }
+ List<Tag> tags = Utils.parseTags(sql, request.getParameter("tags"));
- String attachmentFName = null;
+ String attachmentFName;
try {
- attachmentFName = Utils.receiveMultiPartFile(request, "attach");
+ attachmentFName = Utils.receiveAttachment(request.getPart("attach"), request.getParameter("img"));
} catch (Exception e) {
logger.error("MULTIPART ERROR", e);
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
return;
}
- String paramImg = request.getParameter("img");
- if (attachmentFName == null && paramImg != null && paramImg.length() > 10) {
- try {
- URL imgUrl = new URL(paramImg);
- attachmentFName = Utils.downloadImage(imgUrl);
- } catch (Exception e) {
- logger.error("DOWNLOAD ERROR", e);
- response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- return;
- }
- }
-
String attachmentType = attachmentFName != null ? attachmentFName.substring(attachmentFName.length() - 3) : null;
int mid = MessagesQueries.createMessage(sql, visitor.getUid(), body, attachmentType, tags);
SubscriptionsQueries.subscribeMessage(sql, mid, visitor.getUid());
@@ -230,11 +200,7 @@ public class NewMessage {
}
if (xmpp != null) {
- String tagsStr2 = "";
- for (String tag : tagsArr) {
- tagsStr2 += " *" + tag;
- }
- xmsg.setBody("@" + jmsg.getUser().getName() + ":" + tagsStr2 + "\n" + body + "\n\n#" + mid + " http://juick.com/" + mid);
+ xmsg.setBody("@" + jmsg.getUser().getName() + ":" + jmsg.getTagsString() + "\n" + body + "\n\n#" + mid + " http://juick.com/" + mid);
xmsg.setTo(Jid.of("juick@s2s.juick.com"));
xmpp.send(xmsg);
@@ -265,13 +231,13 @@ public class NewMessage {
String hashtags = "";
String tagscomma = "";
- for (int i = 0; i < tagsArr.length; i++) {
+ for (int i = 0; i < jmsg.getTags().size(); i++) {
if (i > 0) {
hashtags += " ";
tagscomma += ",";
}
- hashtags += "#" + tagsArr[i];
- tagscomma += tagsArr[i];
+ hashtags += "#" + jmsg.getTags().get(i);
+ tagscomma += jmsg.getTags().get(i);
}
String url = URLEncoder.encode("http://juick.com/" + mid, "utf-8");
@@ -340,7 +306,7 @@ public class NewMessage {
String attachmentFName = null;
try {
- attachmentFName = Utils.receiveMultiPartFile(request, "attach");
+ attachmentFName = Utils.receiveMultiPartFile(request.getPart("attach"));
} catch (Exception e) {
logger.error("MULTIPART ERROR", e);
response.sendError(HttpServletResponse.SC_BAD_REQUEST);