diff options
author | Anatoliy Sablin | 2017-11-06 16:27:11 +0300 |
---|---|---|
committer | Anatoliy Sablin | 2017-11-06 16:27:11 +0300 |
commit | d77ff16de5543b5820ee3b185660a052c5f57a15 (patch) | |
tree | ba701d56a441dc7e9caea89bad96929bc3a70d95 /juick-commands/src/main/java/com/juick/command/ToggleSubscriptions.java | |
parent | 41b885d84958d07ade536850829b3ba394a4f8f9 (diff) |
Added rest commands.
Diffstat (limited to 'juick-commands/src/main/java/com/juick/command/ToggleSubscriptions.java')
-rw-r--r-- | juick-commands/src/main/java/com/juick/command/ToggleSubscriptions.java | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/juick-commands/src/main/java/com/juick/command/ToggleSubscriptions.java b/juick-commands/src/main/java/com/juick/command/ToggleSubscriptions.java new file mode 100644 index 00000000..737565f9 --- /dev/null +++ b/juick-commands/src/main/java/com/juick/command/ToggleSubscriptions.java @@ -0,0 +1,56 @@ +package com.juick.command; + +import com.juick.User; +import com.juick.server.protocol.ProtocolListener; +import com.juick.service.UserService; +import lombok.Getter; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.regex.Pattern; + +/** + * @author ma1uta + */ +@Component +@Getter +public class ToggleSubscriptions extends MultiArgsCommand { + + private static final Pattern PATTERN = Pattern.compile("^(on|off)$", Pattern.CASE_INSENSITIVE); + + private final UserService userService; + + @Autowired + public ToggleSubscriptions(UserService userService) { + this.userService = userService; + } + + @Override + public Pattern pattern() { + return PATTERN; + } + + @Override + public String help() { + return "ON/OFF - Enable/disable subscriptions delivery"; + } + + @Override + protected String execute(User sender, ProtocolListener protocolListener, String... arguments) { + UserService.ActiveStatus newStatus; + String retValUpdated; + if (arguments[0].toLowerCase().equals("on")) { + newStatus = UserService.ActiveStatus.Active; + retValUpdated = "Notifications are activated for " + sender.getJid(); + } else { + newStatus = UserService.ActiveStatus.Inactive; + retValUpdated = "Notifications are disabled for " + sender.getJid(); + } + + if (getUserService().setActiveStatusForJID(sender.getJid(), newStatus)) { + return retValUpdated; + } else { + return String.format("Subscriptions status for %s was not changed", sender.getJid()); + } + } +} |