blob: 2ef5ce2203d4d2d39d0f6d540cf8407b9477a9db (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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);
}
}
|