diff options
author | Vitaly Takmazov | 2017-01-16 14:25:58 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2017-01-16 14:25:58 +0300 |
commit | 965d46f8188378eea8acb99e8f6c448a26a1ee19 (patch) | |
tree | 1ea8749a14ce33d229604f8a976a5944473153a8 /juick-server/src | |
parent | b1a81ad87c0803006965ca299103a5ec32be3056 (diff) |
juick-protocol: check message exists before subscription
Diffstat (limited to 'juick-server/src')
-rw-r--r-- | juick-server/src/main/java/com/juick/server/protocol/JuickProtocol.java | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/juick-server/src/main/java/com/juick/server/protocol/JuickProtocol.java b/juick-server/src/main/java/com/juick/server/protocol/JuickProtocol.java index 06fbf2fc..5b1b55e4 100644 --- a/juick-server/src/main/java/com/juick/server/protocol/JuickProtocol.java +++ b/juick-server/src/main/java/com/juick/server/protocol/JuickProtocol.java @@ -354,15 +354,17 @@ public class JuickProtocol { public ProtocolReply commandSubscribeMessage(User user, String... args) { boolean subscribe = args[0].equalsIgnoreCase("s"); int mid = NumberUtils.toInt(args[1], 0); - if (subscribe) { - if (subscriptionService.subscribeMessage(mid, user.getUid())) { - return new ProtocolReply("Subscribed"); - } - } else { - if (subscriptionService.unSubscribeMessage(mid, user.getUid())) { - return new ProtocolReply("Unsubscribed from #" + mid); + if (messagesService.getMessage(mid) != null) { + if (subscribe) { + if (subscriptionService.subscribeMessage(mid, user.getUid())) { + return new ProtocolReply("Subscribed"); + } + } else { + if (subscriptionService.unSubscribeMessage(mid, user.getUid())) { + return new ProtocolReply("Unsubscribed from #" + mid); + } + return new ProtocolReply("You was not subscribed to #" + mid); } - return new ProtocolReply("You was not subscribed to #" + mid); } return new ProtocolReply("Error"); } |