diff options
-rw-r--r-- | src/org/traccar/api/resource/CommandResource.java | 5 | ||||
-rw-r--r-- | src/org/traccar/database/CommandsManager.java | 10 |
2 files changed, 7 insertions, 8 deletions
diff --git a/src/org/traccar/api/resource/CommandResource.java b/src/org/traccar/api/resource/CommandResource.java index b7ea022de..6a258497f 100644 --- a/src/org/traccar/api/resource/CommandResource.java +++ b/src/org/traccar/api/resource/CommandResource.java @@ -45,12 +45,11 @@ public class CommandResource extends ExtendedObjectResource<Command> { @GET @Path("send") - public Collection<Command> get(@QueryParam("deviceId") long deviceId, - @QueryParam("textChannel") boolean textChannel) throws SQLException { + public Collection<Command> get(@QueryParam("deviceId") long deviceId) throws SQLException { Context.getPermissionsManager().checkDevice(getUserId(), deviceId); CommandsManager commandsManager = Context.getCommandsManager(); Set<Long> result = new HashSet<>(commandsManager.getUserItems(getUserId())); - result.retainAll(commandsManager.getSupportedCommands(deviceId, textChannel)); + result.retainAll(commandsManager.getSupportedCommands(deviceId)); return commandsManager.getItems(result); } diff --git a/src/org/traccar/database/CommandsManager.java b/src/org/traccar/database/CommandsManager.java index 6eb6d9035..deb802b29 100644 --- a/src/org/traccar/database/CommandsManager.java +++ b/src/org/traccar/database/CommandsManager.java @@ -81,17 +81,17 @@ public class CommandsManager extends ExtendedObjectManager<Command> { } } - public Collection<Long> getSupportedCommands(long deviceId, boolean textChannel) { + public Collection<Long> getSupportedCommands(long deviceId) { List<Long> result = new ArrayList<>(); Position lastPosition = Context.getIdentityManager().getLastPosition(deviceId); + boolean online = Context.getConnectionManager().getActiveDevice(deviceId) != null; for (long commandId : getAllDeviceItems(deviceId)) { Command command = getById(commandId); - if (command.getTextChannel() == textChannel) { + if (command.getTextChannel() || online) { if (lastPosition != null) { BaseProtocol protocol = Context.getServerManager().getProtocol(lastPosition.getProtocol()); - Collection<String> protocolCommands = - textChannel ? protocol.getSupportedTextCommands() : protocol.getSupportedDataCommands(); - if (protocolCommands.contains(command.getType())) { + if (protocol.getSupportedTextCommands().contains(command.getType()) + || online && protocol.getSupportedDataCommands().contains(command.getType())) { result.add(commandId); } } else if (command.getType().equals(Command.TYPE_CUSTOM)) { |