From 965d46f8188378eea8acb99e8f6c448a26a1ee19 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 16 Jan 2017 14:25:58 +0300 Subject: juick-protocol: check message exists before subscription --- .../java/com/juick/server/protocol/JuickProtocol.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'juick-server/src/main/java/com/juick') 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"); } -- cgit v1.2.3