aboutsummaryrefslogtreecommitdiff
path: root/juick-commands/src/main/java/com/juick/command/PostMessage.java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-commands/src/main/java/com/juick/command/PostMessage.java')
-rw-r--r--juick-commands/src/main/java/com/juick/command/PostMessage.java58
1 files changed, 58 insertions, 0 deletions
diff --git a/juick-commands/src/main/java/com/juick/command/PostMessage.java b/juick-commands/src/main/java/com/juick/command/PostMessage.java
new file mode 100644
index 00000000..2ef5ce22
--- /dev/null
+++ b/juick-commands/src/main/java/com/juick/command/PostMessage.java
@@ -0,0 +1,58 @@
+package com.juick.command;
+
+import com.juick.Tag;
+import com.juick.User;
+import com.juick.server.protocol.ProtocolListener;
+import com.juick.server.util.TagUtils;
+import com.juick.service.MessagesService;
+import com.juick.service.SubscriptionService;
+import com.juick.service.TagService;
+import lombok.Getter;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.regex.Pattern;
+
+/**
+ * @author ma1uta
+ */
+@Component
+@Getter
+public class PostMessage implements Command {
+
+ private final TagService tagService;
+ private final MessagesService messagesService;
+ private final SubscriptionService subscriptionService;
+
+ @Value("${baseuri}")
+ private String baseUri = "http://juick.com";
+
+ @Autowired
+ public PostMessage(TagService tagService, MessagesService messagesService, SubscriptionService subscriptionService) {
+ this.tagService = tagService;
+ this.messagesService = messagesService;
+ this.subscriptionService = subscriptionService;
+ }
+
+ @Override
+ public Pattern pattern() {
+ return null;
+ }
+
+ @Override
+ public String help() {
+ return "";
+ }
+
+ @Override
+ public String execute(User sender, ProtocolListener protocolListener, String command) {
+ List<Tag> tags = getTagService().fromString(command, false);
+ String body = command.substring(TagUtils.toString(tags).length());
+ int mid = getMessagesService().createMessage(sender.getUid(), body, null, tags);
+ getSubscriptionService().subscribeMessage(mid, sender.getUid());
+ protocolListener.messagePosted(getMessagesService().getMessage(mid));
+ return String.format("New message posted.\n#%d %s%d", mid, getBaseUri(), mid);
+ }
+}